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

Add disallowed_methods #75

Open
0xLucqs opened this issue Sep 18, 2024 · 7 comments
Open

Add disallowed_methods #75

0xLucqs opened this issue Sep 18, 2024 · 7 comments

Comments

@0xLucqs
Copy link
Contributor

0xLucqs commented Sep 18, 2024

What it does

Denies the configured methods and functions in clippy.toml

Note: Even though this lint is warn-by-default, it will only trigger if methods are defined in the clippy.toml file.

Why is this bad?

Some methods are undesirable in certain contexts, and it’s beneficial to lint for them as needed.

Example

An example clippy.toml configuration:

disallowed-methods = [
    # Can use a string as the path of the disallowed method.
    "core::clone::Clone::clone",
    # Can also use an inline table with a `path` key.
    { path = "core::array::ArrayTCloneImpl::clone" },
    # When using an inline table, can add a `reason` for why the method
    # is disallowed.
    { path = "core::clone::Clone::<Array<T>>::clone", reason = "no cloning arrays" },
]

(not entirely sure about the syntax of this toml but should probably look like that

// Example code where clippy issues a warning
let xs = array![1, 2, 3, 4];
xs.clone(); // Clone::<Array<T>>::clone is disallowed in the config.
// The diagnostic contains the message "no cloning arrays".

let _number = (@1_u32).clone(); // core::clone::Clone::clone is disallowed in the config.

Use instead:

// Example code which does not raise clippy warning
let mut xs = array![]; // ArrayTrait::new is _not_ disallowed in the config.
xs.push(123); // ArrayTrait::push is _not_ disallowed in the config.
@Gianfranco99
Copy link
Contributor

I'd like to take ownership of this issue. My approach will be to first confirm that the syntax of the clippy.toml file adheres to the intended format for disallowed methods and functions. Specifically, I'll ensure that both string and inline table formats are supported, as shown in the example, and that the reason field is properly handled when provided.

Once the configuration parsing is verified, I'll:

Test Existing Configurations: Create test cases based on the provided examples to ensure Clippy issues warnings for disallowed methods such as Clone::clone, and that custom messages (like "no cloning arrays") are shown when specified in the config.

Extend Linting Capabilities: If needed, I’ll expand the lint to cover edge cases or additional method paths that might not currently be captured, ensuring Clippy correctly warns against all methods listed in clippy.toml.

Ensure Flexibility and Clarity: I will ensure the implementation remains flexible, allowing for future extension of disallowed methods and functions in a way that’s easy to configure in the .toml file.

Documentation & Examples: Update any relevant documentation to clarify how to use this feature, ensuring users can properly configure the clippy.toml file for their specific needs.

I’ll also make sure that any existing functionality continues to work as expected, and I'll write additional tests to validate these changes.

Let me know if this approach works for you, and I’ll get started right away!

Copy link

onlydustapp bot commented Sep 18, 2024

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

@od-hunter
Copy link

Hi @0xLucqs , please can I be assigned please?

Copy link

onlydustapp bot commented Sep 24, 2024

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!

@0xLucqs
Copy link
Contributor Author

0xLucqs commented Sep 24, 2024

yes @od-hunter

@od-hunter
Copy link

@0xLucqs , thanks for assigning me ser. I’d need your assistance as I am not 100% clear on what I am supposed to do please.

@0xLucqs
Copy link
Contributor Author

0xLucqs commented Sep 30, 2024

hello i think that we'll cancel the issue, did you start anything ?

@mkaput mkaput added this to cairo-lint Dec 9, 2024
@github-project-automation github-project-automation bot moved this to Triage in cairo-lint Dec 9, 2024
@mkaput mkaput moved this from Triage to Backlog in cairo-lint Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

3 participants