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
// array length check
function someFnArray(items: object[]) {
return JSON.stringify(items.length || 'emptyArray')
}
enum Foo {
Zero,
One
}
// nullable enum check
function someFnEnum(foo?: Foo) {
JSON.stringify(foo || 'falsy enum ')
}
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/strict-boolean-expressions": ["warn", {
"allowNumber": false,
"allowNullableEnum": false
}]
}
}
tsconfig
Expected Result
I expect no autofix, or a safe autofix
Actual Result
autofixes to
// array length check
function someFnArray(items: object[]) {
return JSON.stringify((items.length > 0) || 'emptyArray')
}
enum Foo {
Zero,
One
}
// nullable enum check
function someFnEnum(foo?: Foo) {
JSON.stringify((foo != null) || 'falsy enum ')
}
Additional Info
This has come up several times before for other checks, see #7312, #6173, #7743, possibly more.
When working on this issue I think the remaining autofixes should be audited for safety (there aren't many) and quite possibly all converted to suggestions.