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

Update: Fix && vs || short-circuiting false negatives (fixes #13634) #13769

Merged
merged 2 commits into from Oct 22, 2020

Commits on Oct 18, 2020

  1. Update: Fix && vs || short-circuiting false negatives (fixes #13634)

    When `constructor-super`, `no-throw-literal`, and
    `prefer-promise-reject-errors` are looking for plausible constructor or
    error values, they fail to consider the short-circuiting behavior
    differences between the `&&` and `||` operators. This results in a false
    negative where these rules allow `foo && 42` when that expression cannot
    be a constructor or error. If the left side is falsy, the expression
    short-circuits with the falsy value. If the left side is truthy, the
    result of the expression is the right side value. All three rules
    already report the right side value in isolation but currently
    incorrectly allow it when on the right side of an `&&` expression.
    
    When @mdjermanovic added support for logical assignment operators, we
    decided to ship with the corrected behavior for `&&=` by only checking
    the right side of the expression, accepting that treatment of `&&=`
    would be inconsistent with existing treatment of `&&`. This PR then
    fixes the `&&` treatment in what we believe can be a semver-minor bug
    fix.
    
    A future improvement could detect statically falsy values on the left
    side of `&&` expressions and report those as well. Such a change could
    also update the `||` treatment to ignore plausibly-(constructor|error)
    values on the right side if the left side is statically truthy but not
    plausibly a constructor or error, so `42 || foo` should fail.
    btmills committed Oct 18, 2020
    Copy the full SHA
    2b951cb View commit details
    Browse the repository at this point in the history

Commits on Oct 22, 2020

  1. Use correct short-circuit term

    Co-authored-by: Nicholas C. Zakas <nicholas@nczconsulting.com>
    btmills and nzakas committed Oct 22, 2020
    Copy the full SHA
    a14b800 View commit details
    Browse the repository at this point in the history