diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index e661f876f9fe9..251026b5f088c 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -160,6 +160,10 @@ fn transform_rule_and_plugin_name<'a>( return (rule_name, "eslint"); } + if plugin_name == "unicorn" && rule_name == "no-negated-condition" { + return ("no-negated-condition", "eslint"); + } + (rule_name, plugin_name) } diff --git a/crates/oxc_linter/src/rules.rs b/crates/oxc_linter/src/rules.rs index 92b582e6710b3..d5f23e69b27fc 100644 --- a/crates/oxc_linter/src/rules.rs +++ b/crates/oxc_linter/src/rules.rs @@ -93,7 +93,6 @@ mod eslint { pub mod no_loss_of_precision; pub mod no_magic_numbers; pub mod no_multi_str; - pub mod no_negated_condition; pub mod no_nested_ternary; pub mod no_new; pub mod no_new_func; diff --git a/crates/oxc_linter/src/rules/eslint/no_negated_condition.rs b/crates/oxc_linter/src/rules/eslint/no_negated_condition.rs deleted file mode 100644 index 5fdbc39e6b97e..0000000000000 --- a/crates/oxc_linter/src/rules/eslint/no_negated_condition.rs +++ /dev/null @@ -1,79 +0,0 @@ -use crate::{context::LintContext, rule::Rule, AstNode}; -use oxc_macros::declare_oxc_lint; - -#[derive(Debug, Default, Clone)] -pub struct NoNegatedCondition; - -declare_oxc_lint!( - /// ### What it does - /// - /// This rule disallows the use of negated conditions in `if` statements to improve readability. - /// - /// ### Why is this bad? - /// - /// Negated conditions can make code harder to read and understand, especially in complex logic. - /// It is often clearer to use positive conditions or to refactor the code structure. - /// - /// ### Examples - /// - /// Examples of **incorrect** code for this rule: - /// ```js - /// if (!isReady) { - /// doSomething(); - /// } else { - /// doSomethingElse(); - /// } - /// ``` - /// - /// Examples of **correct** code for this rule: - /// ```js - /// if (isReady) { - /// doSomethingElse(); - /// } else { - /// doSomething(); - /// } - /// ``` - NoNegatedCondition, - style, - pending, -); - -impl Rule for NoNegatedCondition { - fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - // This rule is exactly the same as the eslint-plugin-unicorn's no-negated-condition rule. - crate::rules::unicorn::no_negated_condition::NoNegatedCondition.run(node, ctx); - } -} - -#[test] -fn test() { - use crate::tester::Tester; - - let pass = vec![ - "if (a) {}", - "if (a) {} else {}", - "if (!a) {}", - "if (!a) {} else if (b) {}", - "if (!a) {} else if (b) {} else {}", - "if (a == b) {}", - "if (a == b) {} else {}", - "if (a != b) {}", - "if (a != b) {} else if (b) {}", - "if (a != b) {} else if (b) {} else {}", - "if (a !== b) {}", - "if (a === b) {} else {}", - "a ? b : c", - ]; - - let fail = vec![ - "if (!a) {;} else {;}", - "if (a != b) {;} else {;}", - "if (a !== b) {;} else {;}", - "!a ? b : c", - "a != b ? c : d", - "a !== b ? c : d", - ]; - - Tester::new(NoNegatedCondition::NAME, NoNegatedCondition::CATEGORY, pass, fail) - .test_and_snapshot(); -}