Skip to content
Closed
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
24 changes: 24 additions & 0 deletions .changeset/modern-frogs-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
"@biomejs/biome": minor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a minor? I thought it was a bug fix. That's not a new feature imho

---

Rule's `options` is now optional in the Biome configuration files for rules with a `fix` kind.

Previously, configuring a rule's `fix` required `options` to be set.
Now, `options` is optional.
The following configuration is now valid:

```json
{
"linter": {
"rules": {
"correctness": {
"noUnusedImports": {
"level": "on",
"fix": "safe"
}
}
}
}
}
```
10 changes: 5 additions & 5 deletions crates/biome_cli/src/execute/migrate/eslint_to_biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn migrate_eslint_rule(
biome_config::RuleWithFixOptions {
level: severity.into(),
fix: None,
options: *Box::new((*rule_options).into()),
options: Some(*Box::new((*rule_options).into())),
},
));
}
Expand Down Expand Up @@ -534,7 +534,7 @@ fn migrate_eslint_rule(
biome_config::RuleWithFixOptions {
level: severity.into(),
fix: None,
options: *Box::new((*rule_options).into()),
options: Some(*Box::new((*rule_options).into())),
},
));
}
Expand All @@ -551,7 +551,7 @@ fn migrate_eslint_rule(
biome_config::RuleWithFixOptions {
level: severity.into(),
fix: None,
options: rule_options.into(),
options: Some(rule_options.into()),
},
));
}
Expand All @@ -567,7 +567,7 @@ fn migrate_eslint_rule(
biome_config::RuleWithFixOptions {
level: severity.into(),
fix: None,
options: rule_options.into(),
options: Some(rule_options.into()),
},
));
}
Expand Down Expand Up @@ -602,7 +602,7 @@ fn migrate_eslint_rule(
biome_config::RuleWithFixOptions {
level: severity.into(),
fix: None,
options: options.into(),
options: Some(options.into()),
},
));
}
Expand Down
65 changes: 65 additions & 0 deletions crates/biome_cli/tests/cases/config_extends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,68 @@ fn extends_config_merge_overrides() {
result,
));
}

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

let shared = Utf8Path::new("shared.json");
fs.insert(
shared.into(),
r#"{
"linter": {
"enabled": true,
"rules": {
"correctness": {
"noUnusedVariables": {
"level": "on",
"options": {
"ignoreRestSiblings": false
}
}
}
}
}
}"#,
);

let biome_json = Utf8Path::new("biome.json");
fs.insert(
biome_json.into(),
r#"{
"extends": ["shared.json"],
"linter": {
"enabled": true,
"rules": {
"correctness": {
"noUnusedVariables": {
"level": "on",
"fix": "safe"
}
}
}
}
}"#,
);

let test_file = Utf8Path::new("test.js");
fs.insert(
test_file.into(),
"const { a, ...rest } = { a: 1, b: 2}; export { rest }",
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["lint", test_file.as_str()].as_slice()),
);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"extends_config_rule_options_merge",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{
"extends": ["shared.json"],
"linter": {
"enabled": true,
"rules": {
"correctness": {
"noUnusedVariables": {
"level": "on",
"fix": "safe"
}
}
}
}
}
```

## `shared.json`

```json
{
"linter": {
"enabled": true,
"rules": {
"correctness": {
"noUnusedVariables": {
"level": "on",
"options": {
"ignoreRestSiblings": false
}
}
}
}
}
}
```

## `test.js`

```js
const { a, ...rest } = { a: 1, b: 2}; export { rest }
```

# Emitted Messages

```block
test.js:1:9 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! This variable a is unused.

> 1 │ const { a, ...rest } = { a: 1, b: 2}; export { rest }
│ ^

i Unused variables are often the result of an incomplete refactoring, typos, or other sources of bugs.

i You can use the ignoreRestSiblings option to ignore unused variables in an object destructuring with a spread.


```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 warning.
```
13 changes: 8 additions & 5 deletions crates/biome_configuration/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ impl<T: Clone + Default + 'static> RuleFixConfiguration<T> {
pub fn get_options(&self) -> Option<RuleOptions> {
match self {
Self::Plain(_) => None,
Self::WithOptions(options) => {
Some(RuleOptions::new(options.options.clone(), options.fix))
}
Self::WithOptions(options) => Some(RuleOptions::new(
options.options.clone().unwrap_or_default(),
options.fix,
)),
}
}
}
Expand Down Expand Up @@ -403,14 +404,16 @@ pub struct RuleWithFixOptions<T: Default> {
#[serde(skip_serializing_if = "Option::is_none")]
pub fix: Option<FixKind>,
/// Rule's options
pub options: T,
pub options: Option<T>,
}

impl<T: Default> Merge for RuleWithFixOptions<T> {
fn merge_with(&mut self, other: Self) {
self.level = other.level;
self.fix = other.fix.or(self.fix);
self.options = other.options;
if other.options.is_some() {
self.options = other.options;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/biome_configuration/tests/valid/optional_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"linter": {
"rules": {
"correctness": {
"noUnusedImports": {
"level": "on",
"fix": "safe"
}
}
}
}
}
Loading
Loading