Bug: no-unnecessary-condition false negative inside string and number conditionals #7926
Closed
4 tasks done
Labels
bug
Something isn't working
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
wontfix
This will not be worked on
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.2.2&fileType=.tsx&code=CYUwxgNghgTiAEEQBd4CMD2GIC51aSgDsBuAWACgBLAM3gApNsBKeAb0vnloaYlY4UuXMBiIBnbCAB0EDAHNGBeAB8V8AOQ0sG5uSHwAvpWMVKoSLARJURAK4BbPPYdoQMfT3ouBnbnW9HAXgAehD4cQALDDsIYHhQZHBUdxgMGHhI9xA-ETFJJFkFQIdVdS0dPVDwqJi4hJRk%2BFT0zOy-U1NzcGg4RBQI5Bg8cSGqInlPANGYXwMvGeCwiOjY%2BMSmloysuFz4UQkpIsUZss1tDF0SapW69cawFJg07faDTqA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0yHJgBNK%2BSpPRRE0aB2iRwYAL4gtQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
The error "Unnecessary conditional, value is always truthy" should be reported on lines 3 and 4
Actual Result
No errors are detected
Additional Info
I discovered this because I was trying out eslint-plugin-sonarjs, and that plugin has a similar rule called no-gratuitous-expression that does detect these cases. The code for that rule is available here.
The text was updated successfully, but these errors were encountered: