Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
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 havesearched for related issues and found none that matched my issue.
- I haveread 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 00&&{};// 1 error but should be 2, because first 2 operands are "conditions"1&&2&&{};// 1 error but should be 31&&2&&3&&{};// 2 errors but should be 4(1||2)&&(3||4)&&{};// 1 error, ok? its equivalent to a ternary1&&{}||null;// but this isn't and only 1 error but should be 21&&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
{"compilerOptions": {"strict":true }}
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 usedcond && 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 allowcond && 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 |