# prefer-includes-over-repeated-comparisons πŸ“ Prefer `.includes()` over repeated equality comparisons. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). Comparing the same expression against multiple values is easier to scan as a membership check. This rule only reports strict equality comparisons joined by `||`. It ignores optional chains, side-effectful compared values, and `NaN` values because an `Array#includes()` rewrite would not have the same behavior. This rule does not autofix because the best rewrite depends on context. Plain member expressions are still reported, so consider accessors and proxies before rewriting. ## Examples ```js // ❌ value === 'a' || value === 'b' || value === 'c'; // βœ… ['a', 'b', 'c'].includes(value); ``` ```js // ❌ args[0] === '-h' || args[0] === '--help' || args[0] === '--version'; // βœ… ['-h', '--help', '--version'].includes(args[0]); ``` ```js // βœ… value === 'a' || value === 'b'; ``` ```js // βœ… value !== 'a' && value !== 'b'; ``` Comparing several distinct expressions against the same value is not reported, since there is no single subject to check for membership. ```js // βœ… state.a === undefined || state.b === undefined || state.c === undefined; ``` ## Options Type: `object` ### `minimumComparisons` Type: `integer`\ Minimum: `2`\ Default: `3` The minimum number of equality comparisons before reporting. ```js /* eslint unicorn/prefer-includes-over-repeated-comparisons: ["error", {"minimumComparisons": 4}] */ // βœ… value === 'a' || value === 'b' || value === 'c'; // ❌ value === 'a' || value === 'b' || value === 'c' || value === 'd'; ```