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
feat: add enforceForInnerExpressions
option to no-extra-boolean-cast
#18222
Merged
mdjermanovic
merged 14 commits into
eslint:main
from
kirkwaiblinger:no-extra-boolean-cast-inspect-more-expressions
May 6, 2024
+1,457
−216
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ce5ac38
fix: [no-extra-boolean-cast] inspect comma expressions and ?? express…
kirkwaiblinger 554caaf
check ternaries recursively too
kirkwaiblinger c60535b
pr feedback
kirkwaiblinger c5c1630
Merge branch 'main' into no-extra-boolean-cast-inspect-more-expressions
kirkwaiblinger 8326217
change docs
kirkwaiblinger 822ec6c
add option for recursive expression checks
kirkwaiblinger e24feeb
better wording
kirkwaiblinger c327282
format
kirkwaiblinger 464d921
enforceForInnerExpressions
kirkwaiblinger 6b5b3f3
feedback
kirkwaiblinger 4af5bd5
nice, anyOf is clever about additionalProperties
kirkwaiblinger c775385
test cov
kirkwaiblinger c8a1dc3
test coverage
kirkwaiblinger ba74952
docs
kirkwaiblinger File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was assuming that
previousNode
isparent.test
(as in the description of this function on line 167, which we should also update), but now it can beconsequent
/alternate
, in which case onlySequenceExpression
would need parentheses.For example:
After the autofix:
Parentheses around
b = c
andd = e
are unnecessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one took me a while to figure out trying to make use of the existing infrastructure.
I would have expected to be able to write
, which essentially just handles the right-associativity, but it seems that eslint's precedence() function differs from MDN's table, in that it treats AssignmentExpressions and similar as lower precedence than ternary, rather than equal... See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table, vs
eslint/lib/rules/utils/ast-utils.js
Lines 1509 to 1602 in 239a7e2
Think that there should be a followup to change to match the MDN version, or is it better to just leave the current system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can consider changing this in a followup if the current logic is confusing and the new one would be better for practical use, but we'll need to check all rules that use
getPrecedence()
to see if they would need to be updated.