-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginhas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
It'd be great to have a lint rule that disallows (possible) strings and numbers from being implicitly converted to booleans:
const str: string | null = ''
if (str) {
// ignores the empty string, the programmer likely attempted to guard against null
}
const num: number | undefined = 0
if (!num) {
// ignores the 0 value, but the programmer likely attempted to guard against undefined
}
Besides if
statements this would apply to ternary statements as well as &&
, ||
and !
operators.
For the above examples passing code could be:
const str: string | null = ''
if (typeof str === 'string') {
// …
}
if (str !== null) {
// …
}
const num: number | undefined = 0
if (typeof num !== 'undefined') {
// ...
}
I can see a stricter version of this rule which enforces explicit conversions even if a value can only be a string or number.
sindresorhus, SpainTrain, jamesaspence, awerlang, Djaler and 3 more
Metadata
Metadata
Assignees
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginhas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin