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

Add prefer-math-min-max #2432

Merged
merged 26 commits into from
Aug 23, 2024
Merged

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Aug 21, 2024

Close #2373

@@ -0,0 +1,56 @@
# Prefer `Math.min()` and `Math.max()` over ternary expressions for simple comparisons
Copy link
Owner

Choose a reason for hiding this comment

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

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.
Copy link
Owner

Choose a reason for hiding this comment

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

This is repeating the title.

@fisker
Copy link
Collaborator

fisker commented Aug 21, 2024

Two edge cases will be broken

  1. need parens
(0,foo) > 10 ? 10 : (0,foo)
  1. need insert space before
function a() {
  return+foo > 10 ? 10 : +foo
}

@axetroy

This comment was marked as outdated.

@axetroy
Copy link
Contributor Author

axetroy commented Aug 21, 2024

Two edge cases will be broken

1. need parens
(0,foo) > 10 ? 10 : (0,foo)
2. need insert space before
function a() {
  return+foo > 10 ? 10 : +foo
}

Resolve the edge case in 87815e9 and 48de8a4

@axetroy
Copy link
Contributor Author

axetroy commented Aug 22, 2024

Code coverage 100%, reached

Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

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

Good job

@sindresorhus sindresorhus merged commit 7369077 into sindresorhus:main Aug 23, 2024
17 checks passed
@axetroy axetroy deleted the prefer-math-min-max branch August 23, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: prefer-math-min-max
3 participants