Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit baf3e4e

Browse files
authored
fix(linter): correctly replace rule severity with duplicate rule name configurations (#8840)
See the snapshot changes of `apps/oxlint/fixtures/typescript_eslint/eslintrc.json`.
1 parent cebb350 commit baf3e4e

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

apps/oxlint/fixtures/typescript_eslint/eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"plugins": ["@typescript-eslint"],
44
"rules": {
55
"no-loss-of-precision": "off",
6-
"@typescript-eslint/no-loss-of-precision": "error",
7-
"@typescript-eslint/no-namespace": "warn"
6+
"@typescript-eslint/no-namespace": "warn",
7+
"@typescript-eslint/no-loss-of-precision": "error"
88
}
99
}

apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json --disable-typescript-plugin [email protected]

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ working directory:
1515
`----
1616
help: Consider removing this declaration.
1717

18-
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime.
18+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime.
1919
,-[fixtures/typescript_eslint/test.ts:4:1]
2020
3 |
2121
4 | 9007199254740993 // no-loss-of-precision
2222
: ^^^^^^^^^^^^^^^^
2323
`----
2424
25-
Found 2 warnings and 0 errors.
25+
Found 1 warning and 1 error.
2626
Finished in <variable>ms on 1 file with 48 rules using 1 threads.
2727
----------
28-
CLI result: LintSucceeded
28+
CLI result: LintFoundErrors
2929
----------

apps/oxlint/src/snapshots/_-c fixtures__typescript_eslint__eslintrc.json [email protected]

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ working directory:
2323
`----
2424
help: Replace the namespace with an ES2015 module or use `declare module`
2525
26-
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime.
26+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loss-of-precision.html\eslint(no-loss-of-precision)]8;;\: This number literal will lose precision at runtime.
2727
,-[fixtures/typescript_eslint/test.ts:4:1]
2828
3 |
2929
4 | 9007199254740993 // no-loss-of-precision
3030
: ^^^^^^^^^^^^^^^^
3131
`----
3232

33-
Found 3 warnings and 0 errors.
33+
Found 2 warnings and 1 error.
3434
Finished in <variable>ms on 1 file with 59 rules using 1 threads.
3535
----------
36-
CLI result: LintSucceeded
36+
CLI result: LintFoundErrors
3737
----------

crates/oxc_linter/src/config/rules.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl OxlintRules {
132132
if let Some(rule) = rules.get(&plugin_name) {
133133
rules_to_replace.push(RuleWithSeverity::new(
134134
rule.read_json(config),
135-
rule.severity,
135+
rule_config.severity,
136136
));
137137
}
138138
// If the given rule is not found in the rule list (for example, if all rules are disabled),
@@ -474,8 +474,7 @@ mod test {
474474
#[test]
475475
fn test_override_plugin_prefix_duplicates() {
476476
let configs = [
477-
// FIXME: this should be valid
478-
// json!({ "@typescript-eslint/no-unused-vars": "error" }),
477+
json!({ "@typescript-eslint/no-unused-vars": "error" }),
479478
json!({ "no-unused-vars": "off", "typescript/no-unused-vars": "error" }),
480479
json!({ "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "error" }),
481480
];
@@ -501,7 +500,7 @@ mod test {
501500
assert_eq!(rules.len(), 1, "{config:?}");
502501
let rule = rules.iter().next().unwrap();
503502
assert_eq!(rule.name(), "no-unused-vars", "{config:?}");
504-
assert_eq!(rule.severity, AllowWarnDeny::Warn, "{config:?}");
503+
assert_eq!(rule.severity, AllowWarnDeny::Deny, "{config:?}");
505504
}
506505
}
507506
}

0 commit comments

Comments
 (0)