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

Fix: warn constant on RHS of || in no-constant-condition (fixes #11181) #11253

Merged
merged 3 commits into from Jan 16, 2019

Conversation

MerlinMason
Copy link

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version: 5.9.0
  • Node Version: 11.3.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

Please show your full configuration:

Configuration
{
    "parser": "babel-eslint",
    "parserOptions": {
        "sourceType": "module",
        "allowImportExportEverywhere": true
    },
    "extends": [
        "airbnb",
        "plugin:lodash/recommended"
    ],
    "env": {
        "browser": true,
        "jquery": true,
        "node": true,
        "mocha": true
    },
    "globals": {
        "expect": true,
        "cy": true,
        "Cypress": true,
        "__VERSION__": true,
        "__RELEASED__": true,
        "__INTERCOMID__": true
    },
    "plugins": [
        "backbone",
        "compat",
        "mocha",
        "chai-friendly",
        "lodash",
        "json"
    ],
    "settings": {
        "backbone": {
            "Collection": ["BaseCollection"],
            "Model": ["BaseModel"],
            "View": ["BaseView"]
        }
    },
    "rules": {
        "no-unused-vars": [1, { "vars": "all", "args": "after-used", "ignoreRestSiblings": true, "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }],
        "no-unused-expressions": 0,
        "chai-friendly/no-unused-expressions": 2,
        "arrow-parens": ["error", "always"],
        "indent": ["error", 4, { "SwitchCase": 1 }],
        "quotes": [1, "double"],
        "comma-dangle": ["error", "never"],
        "new-cap": ["error", { "capIsNew": false }],
        "brace-style": [1, "1tbs", { "allowSingleLine": true }],
        "camelcase": 0,
        "no-plusplus": 0,
        "no-param-reassign": 0,
        "no-underscore-dangle": 0,
        "max-len": 0,
        "no-console": 0,
        "default-case": 0,
        "func-names": 0,
        "no-new": 0,
        "global-require": 0,
        "eol-last": 1,
        "class-methods-use-this": 0,
        "no-cond-assign": [1, "except-parens"],
        "newline-per-chained-call": [2, {"ignoreChainWithDepth": 5}],
        "eqeqeq": ["error", "always"],
        "valid-jsdoc": ["error", { "prefer": { "return": "returns", "extends": "extends" }, "preferType": { "object": "Object" }, "requireReturn": false, "requireReturnType": true, "requireReturnDescription": false, "matchDescription": ".+" }],
        "react/require-extension": [0, { "extensions": [".js"] }],
        "prefer-destructuring": [2, { "array": false, "object": true }, { "enforceForRenamedProperties": false }],
        "import/no-extraneous-dependencies": [0, {}],
        "import/no-unresolved": [2, { "ignore": ["env"] }],
        "import/extensions": 0,
        "import/no-cycle": 0,
        "mocha/no-exclusive-tests": "error",
        "backbone/collection-model": 0,
        "backbone/defaults-on-top": 2,
        "backbone/events-on-top": [2, ["el"]],
        "backbone/initialize-on-top": [2, { "View": ["el", "events"] }],
        "backbone/model-defaults": 0,
        "backbone/no-constructor": 2,
        "backbone/no-el-assign": 2,
        "backbone/no-native-jquery": [2, "selector"],
        "lodash/prefer-lodash-method": 0,
        "lodash/prefer-noop": 1,
        "lodash/import-scope": 0,
        "lodash/prefer-constant": 0,
        "lodash/prefer-filter": 0,
        "lodash/prefer-flat-map": 1,
        "lodash/collection-method-value": 0,
        "lodash/collection-return": 0,
        "lodash/prefer-lodash-chain": 1,
        "lodash/prop-shorthand": 0,
        "lodash/matches-syntax": 0,
        "lodash/matches-shorthand": 0
    }
}

What did you do? Please include the actual source code causing the issue.

if (category === "voucher" || "custom") { }

What did you expect to happen?
An error should be thrown as the condition will always evaluate to true.

What actually happened? Please include the actual, raw output from ESLint.
No error was thrown.

What changes did you make? (Give an overview)

  • Added tests.
  • Changed the return statement in the isConstant function.

Is there anything you'd like reviewers to focus on?
When using logical or, if the right side of the condition is a constant and truthy then the condition will always resolve to true. The changes to the return statement test for this eventuality.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jan 8, 2019
@MerlinMason MerlinMason changed the title Issue11181 Fix: handling of string literals on the right side of logical OR (fixes #11181) Jan 8, 2019
@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jan 16, 2019
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I'd like to get one more set of eyes on it before merging.

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kaicataldo kaicataldo changed the title Fix: handling of string literals on the right side of logical OR (fixes #11181) Fix: warn constant on RHS of || in no-constant-condition (fixes #11181) Jan 16, 2019
@kaicataldo kaicataldo added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jan 16, 2019
@kaicataldo kaicataldo merged commit c403445 into eslint:master Jan 16, 2019
@kaicataldo
Copy link
Member

Thanks for contributing to ESLint!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 16, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants