Skip to content

Commit

Permalink
fix(configuration): enabled rules calculation (#2072)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant authored Mar 13, 2024
1 parent 409eb10 commit 5bc24f1
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 71 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ New entries must be placed in a section entitled `Unreleased`.
Read
our [guidelines for writing a good changelog entry](https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#changelog).

## Ureleased

### Analyzer

### CLI

### Configuration

#### Bug fixes

- Fix enabled rules calculation. The precendence of individual rules, `all` and `recommend` presets in top-level and group-level configs is now correctly respected. More details can be seen in ([#2072](https://github.com/biomejs/biome/pull/2072)) ([#2028](https://github.com/biomejs/biome/issues/2028)). Contributed by @Sec-ant

### Editors

### Formatter

### JavaScript APIs

### Linter

### Parser

## 1.6.1 (2024-03-12)

### CLI
Expand Down
52 changes: 52 additions & 0 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,58 @@ fn top_level_not_all_down_level_all() {
));
}

#[test]
fn top_level_all_down_level_empty() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

// style rules that are not recommended should be enabled.
let biome_json = r#"{
"linter": {
"rules": {
"all": true,
"nursery": {
"all": false
},
"suspicious": {
"all": false
},
"style": {}
}
}
}"#;

// style/noRestrictedGlobals
// style/noShoutyConstants
let code = r#"
console.log(event);
const FOO = "FOO";
console.log(FOO);
"#;

let file_path = Path::new("fix.js");
fs.insert(file_path.into(), code.as_bytes());

let config_path = Path::new("biome.json");
fs.insert(config_path.into(), biome_json.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("lint"), file_path.as_os_str().to_str().unwrap()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"top_level_all_down_level_empty",
fs,
console,
result,
));
}

#[test]
fn ignore_configured_globals() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"linter": {
"rules": {
"all": true,
"nursery": {
"all": false
},
"suspicious": {
"all": false
},
"style": {}
}
}
}
```

## `fix.js`

```js

console.log(event);
const FOO = "FOO";
console.log(FOO);

```

# Emitted Messages

```block
fix.js:2:17 lint/style/noRestrictedGlobals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Do not use the global variable event.
> 2 │ console.log(event);
│ ^^^^^
3 │ const FOO = "FOO";
4 │ console.log(FOO);
i Use a local variable instead.
```

```block
fix.js:3:11 lint/style/noShoutyConstants FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Redundant constant declaration.
2 │ console.log(event);
> 3 │ const FOO = "FOO";
│ ^^^^^^^^^^^
4 │ console.log(FOO);
5 │
i Used here.
2 │ console.log(event);
3 │ const FOO = "FOO";
> 4 │ console.log(FOO);
│ ^^^
5 │
i You should avoid declaring constants with a string that's the same
value as the variable name. It introduces a level of unnecessary
indirection when it's only two additional characters to inline.
i Unsafe fix: Use the constant value directly
1 1 │
2 2 │ console.log(event);
3 │ - ····const·FOO·=·"FOO";
4 │ - ····console.log(FOO);
3 │ + ····console.log("FOO");
5 4 │
```

```block
Checked 1 file in <TIME>. No fixes needed.
Found 2 warnings.
```
Loading

0 comments on commit 5bc24f1

Please sign in to comment.