unicorn/no-negated-condition
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-negated-condition": "error",
},
},
];const foo = !a && !b ? x : y;const foo = a != null && b != null ? x : y;if (!a || !b) {
x();
} else {
y();
}const foo = a || b ? y : x;const foo = a == null || b == null ? y : x;if (a && b) {
y();
} else {
x();
}Examples from the ESLint documentation.
unicorn/no-negated-condition
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-negated-condition": "error",
},
},
];unicorn/no-negated-condition
unicorn plugin · pedantic
{
"rules": {
"unicorn/no-negated-condition": "error"
}
}style/noNegationElse
style · since 1.0.0
{
"linter": {
"rules": {
"style": {
"noNegationElse": "error"
}
}
}
}Enforce a case style for filenames and directory names.
Disallow negated expression in equality check.
Enforce using the digits argument with Number#toFixed().
Disallow classes that only have static members.