keep-starknet-strange / cairo-lint

A collection of lints to catch common mistakes and improve your Cairo code.
21 stars 35 forks source link

feat(lint): Add double_parens #24

Closed coxmars closed 3 months ago

coxmars commented 3 months ago

Summary 📌

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

Changes Made ⚡️

image
0xLucqs commented 3 months ago

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 commented 3 months ago

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