Skip to content

Commit 05c2617

Browse files
authored
fix(rage): print rules enabled by domains (#10358)
1 parent 8e4ada5 commit 05c2617

4 files changed

Lines changed: 164 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#10356](https://github.com/biomejs/biome/issues/10356): `biome rage --linter` now displays rules enabled through linter domains in the enabled rules list.

crates/biome_cli/src/commands/rage.rs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::commands::daemon::read_most_recent_log_file;
22
use crate::service::enumerate_pipes;
33
use crate::{CliDiagnostic, CliSession, VERSION, service};
4+
use biome_analyze::RuleFilter;
5+
use biome_configuration::analyzer::{DomainSelector, RuleDomainValue};
46
use biome_configuration::{ConfigurationPathHint, Rules};
57
use biome_console::fmt::{Display, Formatter};
68
use biome_console::{
@@ -17,6 +19,7 @@ use biome_service::configuration::{LoadedConfiguration, load_configuration};
1719
use biome_service::settings::Settings;
1820
use biome_service::workspace::{RageEntry, RageParams, client};
1921
use camino::Utf8PathBuf;
22+
use std::collections::BTreeSet;
2023
use std::{env, io, ops::Deref};
2124
use terminal_size::terminal_size;
2225
use 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

381421
impl 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
}

crates/biome_cli/tests/commands/rage.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,43 @@ fn with_linter_configuration() {
245245
));
246246
}
247247

248+
#[test]
249+
#[serial]
250+
fn with_linter_domain_configuration() {
251+
let fs = MemoryFileSystem::default();
252+
let mut console = BufferConsole::default();
253+
fs.insert(
254+
Utf8Path::new("biome.json").to_path_buf(),
255+
r#"{
256+
"linter": {
257+
"enabled": true,
258+
"rules": {
259+
"recommended": false
260+
},
261+
"domains": {
262+
"qwik": "all"
263+
}
264+
}
265+
}"#,
266+
);
267+
268+
let (fs, result) = run_rage(
269+
fs,
270+
&mut console,
271+
Args::from(["rage", "--linter"].as_slice()),
272+
);
273+
274+
assert!(result.is_ok(), "run_cli returned {result:?}");
275+
276+
assert_rage_snapshot(SnapshotPayload::new(
277+
module_path!(),
278+
"with_linter_domain_configuration",
279+
fs,
280+
console,
281+
result,
282+
));
283+
}
284+
248285
/// Runs the `rage` command mocking out the log directory.
249286
fn run_rage(
250287
fs: MemoryFileSystem,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
source: crates/biome_cli/tests/commands/rage.rs
3+
expression: content
4+
---
5+
## `biome.json`
6+
7+
```json
8+
{
9+
"linter": {
10+
"enabled": true,
11+
"rules": {
12+
"recommended": false
13+
},
14+
"domains": {
15+
"qwik": "all"
16+
}
17+
}
18+
}
19+
```
20+
21+
# Emitted Messages
22+
23+
```block
24+
CLI:
25+
Version: 0.0.0
26+
Color support: **PLACEHOLDER**
27+
28+
Platform:
29+
CPU Architecture: **PLACEHOLDER**
30+
OS: **PLACEHOLDER**
31+
32+
Environment:
33+
BIOME_LOG_PATH: **PLACEHOLDER**
34+
BIOME_LOG_PREFIX_NAME: unset
35+
BIOME_LOG_LEVEL: unset
36+
BIOME_LOG_KIND: unset
37+
BIOME_CONFIG_PATH: unset
38+
BIOME_THREADS: unset
39+
BIOME_WATCHER_KIND: unset
40+
BIOME_WATCHER_POLLING_INTERVAL: unset
41+
NO_COLOR: **PLACEHOLDER**
42+
TERM: **PLACEHOLDER**
43+
JS_RUNTIME_VERSION: unset
44+
JS_RUNTIME_NAME: unset
45+
NODE_PACKAGE_MANAGER: unset
46+
47+
Biome Configuration:
48+
Status: Loaded successfully
49+
Path: biome.json
50+
Formatter enabled: true
51+
Linter enabled: true
52+
Assist enabled: true
53+
VCS enabled: false
54+
HTML full support enabled: unset
55+
56+
Linter:
57+
JavaScript enabled: unset
58+
JSON enabled: unset
59+
CSS enabled: unset
60+
GraphQL enabled: unset
61+
Recommended: false
62+
Enabled rules:
63+
correctness/noQwikUseVisibleTask
64+
correctness/useImageSize
65+
correctness/useJsxKeyInIterable
66+
correctness/useQwikClasslist
67+
correctness/useQwikMethodUsage
68+
correctness/useQwikValidLexicalScope
69+
suspicious/noReactSpecificProps
70+
71+
Server:
72+
Version: 0.0.0
73+
Name: biome_lsp
74+
CPU Architecture: **PLACEHOLDER**
75+
OS: **PLACEHOLDER**
76+
77+
Workspace:
78+
Open Documents: 0
79+
```

0 commit comments

Comments
 (0)