Skip to content

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

Merged
zanieb merged 2 commits intoastral-sh:mainfrom
diceroll123:autofix-R0202-and-R0203
Nov 30, 2023
Merged

[pylint] - implement R0202 and R0203 with autofixes#8335
zanieb merged 2 commits intoastral-sh:mainfrom
diceroll123:autofix-R0202-and-R0203

Conversation

@diceroll123
Copy link
Copy Markdown
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
Copy Markdown
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.
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@diceroll123 diceroll123 force-pushed the autofix-R0202-and-R0203 branch from 7755784 to 41c13a3 Compare November 2, 2023 11:52
@diceroll123 diceroll123 force-pushed the autofix-R0202-and-R0203 branch from 41c13a3 to f16096e Compare November 24, 2023 20:36
@github-actions
Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Copy Markdown
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
@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.

3 participants