Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
/* eslint @typescript-eslint/strict-boolean-expressions: [error, { allowNumber: false }] */
// 1 error, ok, if used in JSX could render 0
0 && {};
// 1 error but should be 2, because first 2 operands are "conditions"
1 && 2 && {};
// 1 error but should be 3
1 && 2 && 3 && {};
// 2 errors but should be 4
(1 || 2) && (3 || 4) && {};
// 1 error, ok? its equivalent to a ternary
1 && {} || null;
// but this isn't and only 1 error but should be 2
1 && 0 || null;
// 2 errors, ok? equivalent to if else if else
(1 && {}) || (2 && []) || null;
// still 2 errors but should be 4
(1 && 0) || (2 && 0) || null;
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/strict-boolean-expressions": ["error", { "allowNumber" : false }],
},
};
tsconfig
Expected Result
I'm not even sure what the correct behavior should be here.
I think when given a chain of &&
or ||
, all the operands should be checked except the last one.
If somebody used cond && valIfTrue || valIfFalse
instead of ternary it would be a breaking change for them.
Actual Result
It checks only the first operand in a chain.
It was implemented that way to allow cond && doIfTrue() || doIfFalse()
but its flawed and shouldn't be used after all.
Additional Info
I can send a PR
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.20.0 |
@typescript-eslint/parser |
5.20.0 |
TypeScript |
4.6.3 |
ESLint |
8.11.0 |
node |
16.14.0 |