keep-starknet-strange / cairo-lint

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

Add `comparison_to_empty` #74

Open 0xLucqs opened 2 months ago

0xLucqs commented 2 months ago

What it does

Checks for comparing to an empty slice such as [], and suggests using .is_empty() where applicable.

Why is this bad?

Some structures can answer .is_empty() much faster than checking for equality. So it is good to get into the habit of using .is_empty(), and having it is cheap. Besides, it makes the intent clearer than a manual comparison in some contexts.

Example

if s == ArrayTrait::new() {
    ..
}

Use instead:

if arr.is_empty() {
    ..
}
0xLucqs commented 2 months ago

hey @Benjtalkshow wanna try this one ?

onlydustapp[bot] commented 2 months ago

Hey @SridharVadla45! Thanks for showing interest. We've created an application for you to contribute to Cairo lint. Go check it out on OnlyDust!

0xLucqs commented 2 months ago

sure any idea on how to proceed ?

BernalHQ commented 2 months ago

Hi @0xLucqs, can i try this.

first i m going to identify which structs in Cairo support is_empty. Once identified, I’ll implement the logic to catch those cases and suggest fixes. Lastly, I’ll write some tests.

onlydustapp[bot] commented 2 months ago

Hey @BernalHQ! Thanks for showing interest. We've created an application for you to contribute to Cairo lint. Go check it out on OnlyDust!

0xLucqs commented 2 months ago

Hey @BernalHQ can you pick another issue plz (or if @SridharVadla45 doesn’t answer in the coming days you can take it)

BernalHQ commented 2 months ago

Ok, i going to looking another issue, and i can do It, if dont answer It.

jcampos2907 commented 2 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Ive been leaning rust for the past year and looking to get a good first issue

lauchaves commented 2 months ago

Hey @0xLucqs is this one available? If so, may I work on this! :D

onlydustapp[bot] commented 2 months ago

Hey @lauchaves! Thanks for showing interest. We've created an application for you to contribute to Cairo lint. Go check it out on OnlyDust!

MariangelaNM commented 2 months ago

I am applying to this issue via OnlyDust platform.

Hi @0xLucqs, is there an opportunity for me to work on this project again? I previously worked on it and would love to contribute further.

JoE11-y commented 2 months ago

Hey @0xLucqs, I’d love to take a look at this too.

augustin-v commented 2 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am an enthusiastic self-taught developer, that learnt Rust as my first language. With hands-on experience optimizing gas usage in projects like Node Guardians exercises (thinking in cairo, brainfvckvm). Which helped me learn how to write optimized code

How I plan on tackling this issue

As I have already reviewed the codebase, I would first create a linting rule that flags these comparisons and suggests using .is_empty() instead, and then test to ensure the rule correctly identifies and suggests improvements.

od-hunter commented 2 months ago

Hi @0xLucqs , please can I be assigned please? This would be my first time contributing to this repo and I’d love to be given the opportunity.

onlydustapp[bot] commented 2 months ago

Hey @od-hunter! Thanks for showing interest. We've created an application for you to contribute to Cairo lint. Go check it out on OnlyDust!

Benjtalkshow commented 2 months ago

hey @Benjtalkshow wanna try this one ?

Hey @0xLucqs I can handle the issue. I wanna try it

0xLucqs commented 2 months ago

did anyone start anything ? In case no i this issue will be paused

Benjtalkshow commented 2 months ago

did anyone start anything ? In case no i this issue will be paused

Hey @0xLucqs , I already started working on it. Should i continue?

0xLucqs commented 2 months ago

can you open a pr to show me what you have ?

SumitGoulikar commented 2 months ago

Hi @0xLucqs , can I be assigned please? This would be my first time contributing to this repository and I would love to be given this opportunity.

Benjtalkshow commented 2 months ago

can you open a pr to show me what you have ?

Alright

Benjtalkshow commented 2 months ago

Hello @0xLucqs , I just made a draft PR regarding this issue. I will appreciate it if this issue is assigned to me. Thanks

vic-Gray commented 2 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have experience optimizing Rust code for performance and clarity, focusing on efficient and maintainable solutions to address challenges.

How I plan on tackling this issue

The check compares a slice to an empty one, recommending .is_empty() for better performance and clarity. I'd replace manual comparisons with .is_empty() to improve the code.