Add prefer-math-min-max#2432
Merged
Merged
Conversation
sindresorhus
requested changes
Aug 21, 2024
| @@ -0,0 +1,56 @@ | |||
| # Prefer `Math.min()` and `Math.max()` over ternary expressions for simple comparisons | |||
Owner
There was a problem hiding this comment.
Suggested change
| # Prefer `Math.min()` and `Math.max()` over ternary expressions for simple comparisons | |
| # Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons |
| <!-- end auto-generated rule header --> | ||
| <!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` --> | ||
|
|
||
| Enforce the use of `Math.min()` and `Math.max()` instead of ternary expressions for simple comparisons. This makes the code more readable. |
Owner
There was a problem hiding this comment.
This is repeating the title.
fisker
reviewed
Aug 21, 2024
Collaborator
|
Two edge cases will be broken
(0,foo) > 10 ? 10 : (0,foo)
function a() {
return+foo > 10 ? 10 : +foo
} |
fisker
reviewed
Aug 21, 2024
fisker
reviewed
Aug 21, 2024
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
Author
fisker
reviewed
Aug 21, 2024
Contributor
Author
|
Code coverage 100%, reached |
fisker
reviewed
Aug 22, 2024
|
col.width > 0 ? col.width : 0conver to It broke the logic. |
Owner
|
It's impossible to account for that without types. And I don't think it should account for that regardless. Implicit type conversion is an anti-pattern. If you want to do it, I suggest disabling the rule. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Close #2373