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

[no-unnecessary-condition] False positive - Value is always falsy #1176

Closed
FlorinAsavoaie opened this issue Nov 5, 2019 · 2 comments
Closed
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look

Comments

@FlorinAsavoaie
Copy link

FlorinAsavoaie commented Nov 5, 2019

Repro

module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 10,
    sourceType: "module",
    project: [
      "tsconfig.json"
    ],
  },
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  rules: {
    indent: ["error", 2],
    "@typescript-eslint/indent": ["error", 2],
    "@typescript-eslint/unified-signatures": "warn",
    "@typescript-eslint/quotes": "error",
    "@typescript-eslint/promise-function-async": "error",
    "@typescript-eslint/prefer-readonly": "error",
    "@typescript-eslint/prefer-for-of": "error",
    "@typescript-eslint/no-unnecessary-condition": "error",
    "@typescript-eslint/no-magic-numbers": "error",
    "@typescript-eslint/member-ordering": "error",
    "@typescript-eslint/member-naming": "error",
    "@typescript-eslint/brace-style": "error",
    "@typescript-eslint/array-type": "error"
  },
};
/* eslint-disable @typescript-eslint/no-unused-vars */
const myFunction = (someBool?: boolean): void => {
  const test = someBool || false;
};

Expected Result
No issue with code.

Actual Result
3:28 error Unnecessary conditional, value is always falsy @typescript-eslint/no-unnecessary-condition

Versions

package version
@typescript-eslint/eslint-plugin 2.6.1
@typescript-eslint/parser 2.6.1
TypeScript 3.6.4
ESLint 6.6.0
node 10.16.3
npm 6.12.0
@FlorinAsavoaie FlorinAsavoaie added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 5, 2019
@Retsam
Copy link
Contributor

Retsam commented Nov 6, 2019

It's reporting an error because the ignoreRhs option isn't set, so it's treating the right hand side of the || operator as a conditional.

Unfortunately, the current version of the rule requires you to choose between false-positives with ignoreRhs off, and some false-negatives with ignoreRhs on. See #1017 . Should be fixed by #1163 , but it's a breaking change that will need to wait for the next major version bump.

@bradzacher
Copy link
Member

As this is working as expected - I'm going to close this.

@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
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look
Projects
None yet
Development

No branches or pull requests

3 participants