-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
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.
JoshuaKGoldberg, ronami and kripod
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin