ESLint rule to check the complexity of logical expressions

This rule checks the number of logical operators in a conditional expression to see its complexity.
``js
/ eslint complex-logic/complex-logic: ["error", 4] /
// incorrect
if (true && true && true && true && true && true) {
}
const foo = true && true && true && true && true && true ? 1 : 0;
// correct
if (true && true && true && true && true) {
}
const bar = true && true && true && true && true ? 1 : 0;
`
`shell`
npm install --save-dev eslint-plugin-complex-logic
`shell`
yarn add -D eslint-plugin-complex-logic
The rule takes one option, which is the maximum allowed number of logical operators in an expression. The default is 4.
You can set the option like this in .eslintrc.js:
`js``
module.exports = {
plugins: ["complex-logic"],
rules: {
"complex-logic/complex-logic": ["error", 4],
},
};
MIT