Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[strict-boolean-expressions] ignoreRhs is too lenient #1118

Closed
OliverJAsh opened this issue Oct 21, 2019 · 0 comments · Fixed by #1480
Closed

[strict-boolean-expressions] ignoreRhs is too lenient #1118

OliverJAsh opened this issue Oct 21, 2019 · 0 comments · Fixed by #1480
Labels
enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Oct 21, 2019

Repro

{
  "rules": {
    "@typescript-eslint/strict-boolean-expressions": [
      2,
      {
        "ignoreRhs": true,
        "allowNullable": true
      }
    ]
  }
}
{
  declare const myString: string;
  declare const myBoolean: boolean;
  const expression = myBoolean && myString; // Expect: no error (thanks to `ignoreRhs`)
  if (expression) {} // Expect: error
}

{
  declare const myString: string;
  declare const myBoolean: boolean;
  if (myBoolean && myString) {} // Expect: error. Actual: no error. ❌
}

Additional Info

This does error as expected in TSLint (with the equivalent rule of the same name).

In the first example, the right-hand side of expression will not be coerced (until it's later used in an if statement), so it's safe to for it to be a non-boolean type.

In the second example however, the right-hand side of the condition in the if statement will be coerced, so it's not safe for it to be a non-boolean type.

Versions

package version
@typescript-eslint/eslint-plugin 2.4.0
@typescript-eslint/parser 2.4.0
TypeScript 3.6.4
ESLint 6.5.1
node 12.8.1
npm 6.10.2
@OliverJAsh OliverJAsh added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 21, 2019
@bradzacher bradzacher added enhancement New feature or request and removed triage Waiting for maintainers to take a look labels Oct 21, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants