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

[pylint] - implement R0202 and R0203 with autofixes #8335

Merged
merged 2 commits into from
Nov 30, 2023

Conversation

diceroll123
Copy link
Contributor

Summary

Implements no-classmethod-decorator/R0202 and no-staticmethod-decorator/R0203 with autofixes.

They're similar enough that all code is reusable for both.

See: #970

Test Plan

cargo test

@diceroll123 diceroll123 force-pushed the autofix-R0202-and-R0203 branch 3 times, most recently from 603e274 to 33803fa Compare October 30, 2023 04:19
@github-actions

This comment was marked as outdated.


let mut diagnostic = Diagnostic::new(
diagnostic_type.clone(),
TextRange::new(stmt.range().start(), stmt.range().start()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really know what range we should highlight with the diagnostic, please advise!

use crate::checkers::ast::Checker;

/// ## What it does
/// Checks for the use of a classmethod being made without the decorator.

Choose a reason for hiding this comment

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

It would be nice to add some examples here. Personally I don't even know how you define a classmethod without a decorator. 😊

(just a random observer here who's interested in new Pylint rules, thanks for working on this!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my mistake!

@diceroll123
Copy link
Contributor Author

I've also had the idea that this could very easily work for property, but that doesn't seem to be a pylint rule. 🤔

And making it a new RUF rule would mean moving some code around to make this reusable between rules, all ears for ideas there.

@zanieb
Copy link
Member

zanieb commented Nov 2, 2023

Thanks for the contribution!

I wonder if people are actually writing class/staticmethods like this still?

Would you mind updating with main so we get preview ecosystem checks?

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Thanks!

@zanieb zanieb merged commit 4212b41 into astral-sh:main Nov 30, 2023
17 checks passed
@zanieb zanieb added rule Implementing or modifying a lint rule preview Related to preview mode features labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants