Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…13769) * 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. * Use correct short-circuit term Co-authored-by: Nicholas C. Zakas <nicholas@nczconsulting.com> Co-authored-by: Nicholas C. Zakas <nicholas@nczconsulting.com>
- Loading branch information
Showing
6 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters