ignore-rhs should be configurable to only apply outside of conditionals #4671
Comments
I don't see where the confusion comes in, typescript has no problems if you add an intermediate variable: const func = (b: boolean, s: string) => {
// typescript knows `typeof thing === true | string` according to how || evaluates.
const thing = b || s;
// since true | string is not a valid boolean type this gets flagged.
if(thing){
// ...
}
// however this, even though it evaluates to true | string it is not flagged when passed to an if statement.
if(b || s){
// ...
}
} can't the rule do the same? If the expression passed to if/while/ternary is not a boolean then throw an error, I don't even see how ignoring the right hand side would even cause it to ignore that. |
Yeah, this seems reasonable as a rule option. We could take it in. Please keep #4534 in mind: we're nearing the deadline for no more non-essential PRs. |
☠️ TSLint's time has come! ☠️ TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. ✨ It was a pleasure open sourcing with you all! |
🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖 🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋 |
Feature request
We'd like to use ignore-rhs but do not want to use it inside conditionals or other contexts (like the result of a
filter()
function) which require a boolean. This could potentially be calledignore-rhs-when-bool-not-required
though that's wordy.Here's an example. I'd like the first two statements to get flagged but the third to not be flagged - so in places where we absolutely must have a boolean, we're sure to get a strict one and not, for example, a truthy empty string.
The text was updated successfully, but these errors were encountered: