Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(configuration): enabled rules calculation #2072

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading