chore(linter): move no-negated-condition to eslint (#8149)

Moves `unicorn/no-negated-condition` to `eslint/no-negated-condition`

Maps `unicorn/no-negated-condition`to `eslint/no-negated-condition`

docs: https://eslint.org/docs/latest/rules/no-negated-condition
This commit is contained in:
Yuichiro Yamashita 2024-12-30 02:12:51 +09:00 committed by GitHub
parent f3050d4f31
commit a2adc4e832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 87 additions and 20 deletions

View file

@ -160,6 +160,10 @@ fn transform_rule_and_plugin_name<'a>(
return (rule_name, "eslint"); return (rule_name, "eslint");
} }
if plugin_name == "unicorn" && rule_name == "no-negated-condition" {
return ("no-negated-condition", "eslint");
}
(rule_name, plugin_name) (rule_name, plugin_name)
} }

View file

@ -93,6 +93,7 @@ mod eslint {
pub mod no_loss_of_precision; pub mod no_loss_of_precision;
pub mod no_magic_numbers; pub mod no_magic_numbers;
pub mod no_multi_str; pub mod no_multi_str;
pub mod no_negated_condition;
pub mod no_nested_ternary; pub mod no_nested_ternary;
pub mod no_new; pub mod no_new;
pub mod no_new_func; pub mod no_new_func;
@ -321,7 +322,6 @@ mod unicorn {
pub mod no_length_as_slice_end; pub mod no_length_as_slice_end;
pub mod no_lonely_if; pub mod no_lonely_if;
pub mod no_magic_array_flat_depth; pub mod no_magic_array_flat_depth;
pub mod no_negated_condition;
pub mod no_negation_in_equality_check; pub mod no_negation_in_equality_check;
pub mod no_nested_ternary; pub mod no_nested_ternary;
pub mod no_new_array; pub mod no_new_array;
@ -588,6 +588,7 @@ oxc_macros::declare_all_lint_rules! {
eslint::no_label_var, eslint::no_label_var,
eslint::no_loss_of_precision, eslint::no_loss_of_precision,
eslint::no_magic_numbers, eslint::no_magic_numbers,
eslint::no_negated_condition,
eslint::no_multi_str, eslint::no_multi_str,
eslint::no_new_func, eslint::no_new_func,
eslint::no_new_native_nonconstructor, eslint::no_new_native_nonconstructor,
@ -920,7 +921,6 @@ oxc_macros::declare_all_lint_rules! {
unicorn::no_length_as_slice_end, unicorn::no_length_as_slice_end,
unicorn::no_lonely_if, unicorn::no_lonely_if,
unicorn::no_magic_array_flat_depth, unicorn::no_magic_array_flat_depth,
unicorn::no_negated_condition,
unicorn::no_negation_in_equality_check, unicorn::no_negation_in_equality_check,
unicorn::no_nested_ternary, unicorn::no_nested_ternary,
unicorn::no_new_array, unicorn::no_new_array,

View file

@ -106,6 +106,20 @@ fn test() {
use crate::tester::Tester; use crate::tester::Tester;
let pass = vec![ 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",
// Test cases from eslint-plugin-unicorn
r"if (a) {}", r"if (a) {}",
r"if (a) {} else {}", r"if (a) {} else {}",
r"if (!a) {}", r"if (!a) {}",
@ -122,6 +136,13 @@ fn test() {
]; ];
let fail = vec![ 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",
// Test cases from eslint-plugin-unicorn
r"if (!a) {;} else {;}", r"if (!a) {;} else {;}",
r"if (a != b) {;} else {;}", r"if (a != b) {;} else {;}",
r"if (a !== b) {;} else {;}", r"if (a !== b) {;} else {;}",

View file

@ -2,126 +2,168 @@
source: crates/oxc_linter/src/tester.rs source: crates/oxc_linter/src/tester.rs
snapshot_kind: text snapshot_kind: text
--- ---
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5] ╭─[no_negated_condition.tsx:1:5]
1 │ if (!a) {;} else {;} 1 │ if (!a) {;} else {;}
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5] ╭─[no_negated_condition.tsx:1:5]
1 │ if (a != b) {;} else {;} 1 │ if (a != b) {;} else {;}
· ────── · ──────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5] ╭─[no_negated_condition.tsx:1:5]
1 │ if (a !== b) {;} else {;} 1 │ if (a !== b) {;} else {;}
· ─────── · ───────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ !a ? b : c 1 │ !a ? b : c
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ a != b ? c : d 1 │ a != b ? c : d
· ────── · ──────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ a !== b ? c : d 1 │ a !== b ? c : d
· ─────── · ───────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5]
1 │ if (!a) {;} else {;}
· ──
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5]
1 │ if (a != b) {;} else {;}
· ──────
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:5]
1 │ if (a !== b) {;} else {;}
· ───────
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1]
1 │ !a ? b : c
· ──
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1]
1 │ a != b ? c : d
· ──────
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1]
1 │ a !== b ? c : d
· ───────
╰────
help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:4] ╭─[no_negated_condition.tsx:1:4]
1 │ (( !a )) ? b : c 1 │ (( !a )) ? b : c
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ !(( a )) ? b : c 1 │ !(( a )) ? b : c
· ──────── · ────────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:4] ╭─[no_negated_condition.tsx:1:4]
1 │ if(!(( a ))) b(); else c(); 1 │ if(!(( a ))) b(); else c();
· ──────── · ────────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:7] ╭─[no_negated_condition.tsx:1:7]
1 │ if((( !a ))) b(); else c(); 1 │ if((( !a ))) b(); else c();
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:21] ╭─[no_negated_condition.tsx:1:21]
1 │ function a() {return!a ? b : c} 1 │ function a() {return!a ? b : c}
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:21] ╭─[no_negated_condition.tsx:1:21]
1 │ function a() {return!(( a )) ? b : c} 1 │ function a() {return!(( a )) ? b : c}
· ──────── · ────────
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ !a ? b : c ? d : e 1 │ !a ? b : c ? d : e
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:1] ╭─[no_negated_condition.tsx:1:1]
1 │ !a ? b : (( c ? d : e )) 1 │ !a ? b : (( c ? d : e ))
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:4] ╭─[no_negated_condition.tsx:1:4]
1 │ if(!a) b(); else c() 1 │ if(!a) b(); else c()
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:4] ╭─[no_negated_condition.tsx:1:4]
1 │ if(!a) {b()} else {c()} 1 │ if(!a) {b()} else {c()}
· ── · ──
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:4] ╭─[no_negated_condition.tsx:1:4]
1 │ if(!!a) b(); else c(); 1 │ if(!!a) b(); else c();
· ─── · ───
╰──── ╰────
help: Remove the negation operator and switch the consequent and alternate branches. help: Remove the negation operator and switch the consequent and alternate branches.
⚠ eslint-plugin-unicorn(no-negated-condition): Unexpected negated condition. ⚠ eslint(no-negated-condition): Unexpected negated condition.
╭─[no_negated_condition.tsx:1:2] ╭─[no_negated_condition.tsx:1:2]
1 │ (!!a) ? b() : c(); 1 │ (!!a) ? b() : c();
· ─── · ───