-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0029b4f
commit 62df5a2
Showing
10 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
crates/ruff_linter/resources/test/fixtures/pylint/too_many_locals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def func(): | ||
# Ok | ||
# 11 is max default | ||
first = 1 | ||
second = 2 | ||
third = 3 | ||
fourth = 4 | ||
fifth = 5 | ||
sixth = 6 | ||
seventh = 7 | ||
eighth = 8 | ||
ninth = 9 | ||
tenth = 10 | ||
eleventh = 11 | ||
|
||
def func(): | ||
# PLR0914 | ||
first = 1 | ||
second = 2 | ||
third = 3 | ||
fourth = 4 | ||
fifth = 5 | ||
sixth = 6 | ||
seventh = 7 | ||
eighth = 8 | ||
ninth = 9 | ||
tenth = 10 | ||
eleventh = 11 | ||
twelfth = 12 | ||
thirteenth = 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
crates/ruff_linter/src/rules/pylint/rules/too_many_locals.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use ruff_diagnostics::Violation; | ||
use ruff_macros::{derive_message_formats, violation}; | ||
|
||
/// ## What it does | ||
/// Checks for functions/methods that include too many local variables. | ||
/// | ||
/// By default, this rule allows up to eleven arguments, as configured by the | ||
/// [`pylint.max-locals`] option. | ||
/// | ||
/// ## Why is this bad? | ||
/// Functions with many local variables are harder to understand and maintain. | ||
/// | ||
/// Consider refactoring functions with many local variables into smaller | ||
/// functions with fewer assignments. | ||
/// | ||
/// ## Options | ||
/// - `pylint.max-locals` | ||
#[violation] | ||
pub struct TooManyLocals { | ||
pub(crate) current_amount: usize, | ||
pub(crate) max_amount: usize, | ||
} | ||
|
||
impl Violation for TooManyLocals { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
let TooManyLocals { | ||
current_amount, | ||
max_amount, | ||
} = self; | ||
format!("Too many local variables: ({current_amount}/{max_amount})") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__too_many_locals.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pylint/mod.rs | ||
--- | ||
too_many_locals.py:30:5: PLR0914 Too many local variables: (13/11) | ||
| | ||
28 | eleventh = 11 | ||
29 | twelfth = 12 | ||
30 | thirteenth = 13 | ||
| ^ PLR0914 | ||
| | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.