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

feat(lint): Add double_parens #24

Merged
merged 8 commits into from
Aug 19, 2024

Conversation

coxmars
Copy link
Contributor

@coxmars coxmars commented Aug 11, 2024

Summary 📌

This PR introduces a new lint double_parens that detects and removes unnecessary double parentheses, improving code readability.

Changes Made ⚡️

  • Implementation of double_parens Lint

    • Added a new lint in plugin.rs to detect and fix double parentheses.
    • Implemented the fix logic in fix.rs, ensuring that unnecessary parentheses are removed while preserving the original code structure.
    • Added test_file! structure in tests.rs.
  • Test Coverage 🥷🏼

    • Added test cases in test_files/double_parens to validate the double_parens lint:
      • Basic case of double parentheses around a number.
      • Unnecessary parentheses around an arithmetic expression.
      • Ensured no modifications are made when parentheses are necessary.
  • Test Results

image

@0xLucqs
Copy link
Contributor

0xLucqs commented Aug 12, 2024

Can you also add a few more test cases (this is from the clippy codebase)

fn dummy_fn<T>(_: T) {}

struct DummyStruct;

impl DummyStruct {
    fn dummy_method<T>(self, _: T) {}
}

fn simple_double_parens() -> i32 {
    ((0))
    //~^ ERROR: consider removing unnecessary double parentheses
    //~| NOTE: `-D clippy::double-parens` implied by `-D warnings`
}

fn fn_double_parens() {
    dummy_fn((0));
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn method_double_parens(x: DummyStruct) {
    x.dummy_method((0));
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn tuple_double_parens() -> (i32, i32) {
    ((1, 2))
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn unit_double_parens() {
    (())
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn fn_tuple_ok() {
    dummy_fn((1, 2));
}

fn method_tuple_ok(x: DummyStruct) {
    x.dummy_method((1, 2));
}

fn fn_unit_ok() {
    dummy_fn(());
}

fn method_unit_ok(x: DummyStruct) {
    x.dummy_method(());
}

// Issue #3206
fn inside_macro() {
    assert_eq!((1, 2), (1, 2), "Error");
    assert_eq!(((1, 2)), (1, 2), "Error");
    //~^ ERROR: consider removing unnecessary double parentheses
}

fn main() {}

@coxmars
Copy link
Contributor Author

coxmars commented Aug 15, 2024

Hi @0xLucqs I already add more test for this lint, 10 in total and I tested and it is working. Let me know if you need something else, thanks 🫡

image

Copy link
Contributor

@0xLucqs 0xLucqs left a comment

Choose a reason for hiding this comment

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

Rebase and apply the suggestion and it's good to go

@coxmars coxmars force-pushed the feat/double-parens-lint branch from 846e943 to 345fc3d Compare August 17, 2024 18:36
@0xLucqs 0xLucqs merged commit b9a1161 into software-mansion:main Aug 19, 2024
1 check passed
@coxmars coxmars deleted the feat/double-parens-lint branch September 20, 2024 18:23
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.

2 participants