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

Rule proposal: Forbid subtraction then compare to zero #2596

Open
fisker opened this issue Mar 19, 2025 · 0 comments
Open

Rule proposal: Forbid subtraction then compare to zero #2596

fisker opened this issue Mar 19, 2025 · 0 comments

Comments

@fisker
Copy link
Collaborator

fisker commented Mar 19, 2025

Description

Improve readability.

Examples

// ❌
if (a - b > 0);

// ✅
if (a > b);
// ❌
if (a - b >= 0);

// ✅
if (a >= b);
// ❌
if (a - b < 0);

// ✅
if (a < b);
// ❌
if (a - b <= 0);

// ✅
if (a <= b);

Proposed rule name

Not sure, maybe directly-compare?

Additional Info

Real-world cases: 1 2, checked history it's written like this because there was a compare function before..

@fregante fregante changed the title Rule proposal: Forbid subtraction then comapre to zero Rule proposal: Forbid subtraction then compare to zero Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant