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

[Linter] Checks for equal operands to comparison, logical and bitwise, difference and division binary operators (==, >, etc., &&, ||, &, |, ^, - and /). #17115

Merged
merged 19 commits into from
Dec 4, 2024

Conversation

tx-tomcat
Copy link
Contributor

@tx-tomcat tx-tomcat commented Apr 10, 2024

Description

Implements a new lint rule that detects binary operations with identical operands, which often indicate programming errors or redundant code. This lint helps maintain code quality by catching potentially problematic patterns early in development.

What it checks

The lint analyzes binary operations for the following operators when used with identical operands:

  • Comparison operators: ==, !=, >, >=, <, <=

    let x = 10;
    let _ = x == x;  // ⚠️ Warning: Equal operands in comparison
  • Logical operators: &&, ||

    let _ = true && true;  // ⚠️ Warning: Redundant logical operation
  • Bitwise operators: &, |, ^

    let x = 5;
    let _ = x & x;  // ⚠️ Warning: Redundant bitwise operation
  • Arithmetic operators: -, /

    let x = 10;
    let _ = x - x;  // ⚠️ Warning: Subtraction with equal operands

Test plan

Added more use case including true positive, true negative, false positive, false negative case

Release notes

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Apr 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2024 7:46pm
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2024 7:46pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Dec 4, 2024 7:46pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Dec 4, 2024 7:46pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Dec 4, 2024 7:46pm

Copy link

vercel bot commented May 31, 2024

@tx-tomcat is attempting to deploy a commit to the Mysten Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Aug 5, 2024

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Aug 5, 2024
));
}

fn equal_operands(lhs: &Value_, op: BinOp_, rhs: &Value_) -> Option<&'static str> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I have it working, I am not sure how to feel about this

@tnowacki tnowacki temporarily deployed to sui-typescript-aws-kms-test-env December 4, 2024 19:46 — with GitHub Actions Inactive
@tnowacki tnowacki merged commit e1a12ab into MystenLabs:main Dec 4, 2024
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants