11use crate :: commands:: daemon:: read_most_recent_log_file;
22use crate :: service:: enumerate_pipes;
33use crate :: { CliDiagnostic , CliSession , VERSION , service} ;
4+ use biome_analyze:: RuleFilter ;
5+ use biome_configuration:: analyzer:: { DomainSelector , RuleDomainValue } ;
46use biome_configuration:: { ConfigurationPathHint , Rules } ;
57use biome_console:: fmt:: { Display , Formatter } ;
68use biome_console:: {
@@ -17,6 +19,7 @@ use biome_service::configuration::{LoadedConfiguration, load_configuration};
1719use biome_service:: settings:: Settings ;
1820use biome_service:: workspace:: { RageEntry , RageParams , client} ;
1921use camino:: Utf8PathBuf ;
22+ use std:: collections:: BTreeSet ;
2023use std:: { env, io, ops:: Deref } ;
2124use terminal_size:: terminal_size;
2225use tokio:: runtime:: Runtime ;
@@ -348,6 +351,10 @@ impl Display for RageConfiguration<'_> {
348351 // Print linter configuration if --linter option is true
349352 if self . linter {
350353 let linter_configuration = configuration. get_linter_rules ( ) ;
354+ let enabled_rules = linter_enabled_rules (
355+ & linter_configuration,
356+ configuration. get_linter_domains ( ) ,
357+ ) ;
351358
352359 let javascript_linter = configuration. get_javascript_linter_configuration ( ) ;
353360 let json_linter = configuration. get_json_linter_configuration ( ) ;
@@ -360,7 +367,7 @@ impl Display for RageConfiguration<'_> {
360367 { KeyValuePair :: new( "CSS enabled" , markup!( { DisplayOption ( css_linter. enabled) } ) ) }
361368 { KeyValuePair :: new( "GraphQL enabled" , markup!( { DisplayOption ( graphql_linter. enabled) } ) ) }
362369 { KeyValuePair :: new( "Recommended" , markup!( { DisplayOption ( linter_configuration. recommended) } ) ) }
363- { RageConfigurationLintRules ( "Enabled rules" , linter_configuration ) }
370+ { RageConfigurationLintRules ( "Enabled rules" , enabled_rules ) }
364371 ) . fmt ( fmt) ?;
365372 }
366373 }
@@ -376,7 +383,40 @@ impl Display for RageConfiguration<'_> {
376383 }
377384}
378385
379- struct RageConfigurationLintRules < ' a > ( & ' a str , Rules ) ;
386+ fn linter_enabled_rules (
387+ rules : & Rules ,
388+ domains : Option < & biome_configuration:: analyzer:: RuleDomains > ,
389+ ) -> BTreeSet < RuleFilter < ' static > > {
390+ let mut enabled_rules = rules
391+ . as_enabled_rules ( )
392+ . into_iter ( )
393+ . collect :: < BTreeSet < _ > > ( ) ;
394+
395+ if let Some ( domains) = domains {
396+ let recommended_rules = Rules :: default ( ) . as_enabled_rules ( ) ;
397+ for ( domain, domain_value) in domains. iter ( ) {
398+ let domain_selector = DomainSelector ( domain. as_str ( ) ) ;
399+ let domain_rules = domain_selector
400+ . as_rule_filters ( )
401+ . into_iter ( )
402+ . filter ( |rule| rule. group ( ) != "nursery" ) ;
403+ match domain_value {
404+ RuleDomainValue :: All => enabled_rules. extend ( domain_rules) ,
405+ RuleDomainValue :: None => {
406+ for rule in domain_rules {
407+ enabled_rules. remove ( & rule) ;
408+ }
409+ }
410+ RuleDomainValue :: Recommended => enabled_rules
411+ . extend ( domain_rules. filter ( |rule| recommended_rules. contains ( rule) ) ) ,
412+ }
413+ }
414+ }
415+
416+ enabled_rules
417+ }
418+
419+ struct RageConfigurationLintRules < ' a > ( & ' a str , BTreeSet < RuleFilter < ' static > > ) ;
380420
381421impl Display for RageConfigurationLintRules < ' _ > {
382422 fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> io:: Result < ( ) > {
@@ -385,9 +425,7 @@ impl Display for RageConfigurationLintRules<'_> {
385425 let padding_rules = Padding :: new ( 4 ) ;
386426 fmt. write_markup ( markup ! { { padding} { rules_str} ":" } ) ?;
387427 fmt. write_markup ( markup ! { { SOFT_LINE } } ) ?;
388- let rules = self . 1 . as_enabled_rules ( ) ;
389- let rules = rules. iter ( ) . collect :: < std:: collections:: BTreeSet < _ > > ( ) ;
390- for rule in rules {
428+ for rule in & self . 1 {
391429 fmt. write_markup ( markup ! { { padding_rules} { rule} } ) ?;
392430 fmt. write_markup ( markup ! { { SOFT_LINE } } ) ?;
393431 }
0 commit comments