Skip to content

Commit

Permalink
fix(linter): keep rules disabled if the rule is not enabled in the co…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored and IWANABETHATGUY committed May 29, 2024
1 parent 823eeec commit b3c84c0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions crates/oxc_cli/fixtures/no_console_off/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "off"
}
}
1 change: 1 addition & 0 deletions crates/oxc_cli/fixtures/no_console_off/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log()
10 changes: 10 additions & 0 deletions crates/oxc_cli/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,16 @@ mod test {
assert_eq!(result.number_of_errors, 0);
}

#[test]
fn no_console_off() {
let args =
&["-c", "fixtures/no_console_off/eslintrc.json", "fixtures/no_console_off/test.js"];
let result = test(args);
assert_eq!(result.number_of_files, 1);
assert_eq!(result.number_of_warnings, 0);
assert_eq!(result.number_of_errors, 0);
}

#[test]
fn typescript_eslint() {
let args = &[
Expand Down
21 changes: 12 additions & 9 deletions crates/oxc_linter/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,23 @@ impl ESLintConfig {
let rule_config = &rule_configs[0];
let rule_name = &rule_config.rule_name;
let plugin_name = &rule_config.plugin_name;
if let Some(rule) = rules_for_override.iter().find(|r| r.name() == rule_name) {
match rule_config.severity {
AllowWarnDeny::Warn | AllowWarnDeny::Deny => {
match rule_config.severity {
AllowWarnDeny::Warn | AllowWarnDeny::Deny => {
if let Some(rule) = all_rules
.iter()
.find(|r| r.name() == rule_name && r.plugin_name() == plugin_name)
{
rules_to_replace.push(rule.read_json(rule_config.config.clone()));
}
AllowWarnDeny::Allow => {
}
AllowWarnDeny::Allow => {
if let Some(rule) = rules_for_override
.iter()
.find(|r| r.name() == rule_name && r.plugin_name() == plugin_name)
{
rules_to_remove.push(rule.clone());
}
}
} else if let Some(rule) = all_rules
.iter()
.find(|r| r.plugin_name() == plugin_name && r.name() == rule_name)
{
rules_to_replace.push(rule.read_json(rule_config.config.clone()));
}
}
_ => {
Expand Down

0 comments on commit b3c84c0

Please sign in to comment.