Skip to content

Commit

Permalink
Rename too-many-positional(-arguments) (astral-sh#12905)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanPlasse authored Aug 15, 2024
1 parent 6ed06af commit 52d27be
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::TooManyArguments) {
pylint::rules::too_many_arguments(checker, function_def);
}
if checker.enabled(Rule::TooManyPositional) {
pylint::rules::too_many_positional(checker, function_def);
if checker.enabled(Rule::TooManyPositionalArguments) {
pylint::rules::too_many_positional_arguments(checker, function_def);
}
if checker.enabled(Rule::TooManyReturnStatements) {
if let Some(diagnostic) = pylint::rules::too_many_return_statements(
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "R0914") => (RuleGroup::Preview, rules::pylint::rules::TooManyLocals),
(Pylint, "R0915") => (RuleGroup::Stable, rules::pylint::rules::TooManyStatements),
(Pylint, "R0916") => (RuleGroup::Preview, rules::pylint::rules::TooManyBooleanExpressions),
(Pylint, "R0917") => (RuleGroup::Preview, rules::pylint::rules::TooManyPositional),
(Pylint, "R0917") => (RuleGroup::Preview, rules::pylint::rules::TooManyPositionalArguments),
(Pylint, "R1701") => (RuleGroup::Removed, rules::pylint::rules::RepeatedIsinstanceCalls),
(Pylint, "R1702") => (RuleGroup::Preview, rules::pylint::rules::TooManyNestedBlocks),
(Pylint, "R1704") => (RuleGroup::Stable, rules::pylint::rules::RedefinedArgumentFromLocal),
Expand Down
7 changes: 5 additions & 2 deletions crates/ruff_linter/src/rules/pylint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ mod tests {
#[test_case(Rule::RedefinedLoopName, Path::new("redefined_loop_name.py"))]
#[test_case(Rule::ReturnInInit, Path::new("return_in_init.py"))]
#[test_case(Rule::TooManyArguments, Path::new("too_many_arguments.py"))]
#[test_case(Rule::TooManyPositional, Path::new("too_many_positional.py"))]
#[test_case(
Rule::TooManyPositionalArguments,
Path::new("too_many_positional_arguments.py")
)]
#[test_case(Rule::TooManyBranches, Path::new("too_many_branches.py"))]
#[test_case(
Rule::TooManyReturnStatements,
Expand Down Expand Up @@ -294,7 +297,7 @@ mod tests {
max_positional_args: 4,
..pylint::settings::Settings::default()
},
..LinterSettings::for_rule(Rule::TooManyPositional)
..LinterSettings::for_rule(Rule::TooManyPositionalArguments)
},
)?;
assert_messages!(diagnostics);
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/pylint/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) use too_many_boolean_expressions::*;
pub(crate) use too_many_branches::*;
pub(crate) use too_many_locals::*;
pub(crate) use too_many_nested_blocks::*;
pub(crate) use too_many_positional::*;
pub(crate) use too_many_positional_arguments::*;
pub(crate) use too_many_public_methods::*;
pub(crate) use too_many_return_statements::*;
pub(crate) use too_many_statements::*;
Expand Down Expand Up @@ -182,7 +182,7 @@ mod too_many_boolean_expressions;
mod too_many_branches;
mod too_many_locals;
mod too_many_nested_blocks;
mod too_many_positional;
mod too_many_positional_arguments;
mod too_many_public_methods;
mod too_many_return_statements;
mod too_many_statements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ use crate::checkers::ast::Checker;
/// ## Options
/// - `lint.pylint.max-positional-args`
#[violation]
pub struct TooManyPositional {
pub struct TooManyPositionalArguments {
c_pos: usize,
max_pos: usize,
}

impl Violation for TooManyPositional {
impl Violation for TooManyPositionalArguments {
#[derive_message_formats]
fn message(&self) -> String {
let TooManyPositional { c_pos, max_pos } = self;
let TooManyPositionalArguments { c_pos, max_pos } = self;
format!("Too many positional arguments ({c_pos}/{max_pos})")
}
}

/// PLR0917
pub(crate) fn too_many_positional(checker: &mut Checker, function_def: &ast::StmtFunctionDef) {
pub(crate) fn too_many_positional_arguments(
checker: &mut Checker,
function_def: &ast::StmtFunctionDef,
) {
let semantic = checker.semantic();

// Count the number of positional arguments.
Expand Down Expand Up @@ -109,7 +112,7 @@ pub(crate) fn too_many_positional(checker: &mut Checker, function_def: &ast::Stm
}

checker.diagnostics.push(Diagnostic::new(
TooManyPositional {
TooManyPositionalArguments {
c_pos: num_positional_args,
max_pos: checker.settings.pylint.max_positional_args,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
too_many_positional.py:1:5: PLR0917 Too many positional arguments (8/5)
too_many_positional_arguments.py:1:5: PLR0917 Too many positional arguments (8/5)
|
1 | def f(x, y, z, t, u, v, w, r): # Too many positional arguments (8/5)
| ^ PLR0917
2 | pass
|

too_many_positional.py:21:5: PLR0917 Too many positional arguments (6/5)
too_many_positional_arguments.py:21:5: PLR0917 Too many positional arguments (6/5)
|
21 | def f(x, y, z, /, u, v, w): # Too many positional arguments (6/5)
| ^ PLR0917
22 | pass
|

too_many_positional.py:29:5: PLR0917 Too many positional arguments (6/5)
too_many_positional_arguments.py:29:5: PLR0917 Too many positional arguments (6/5)
|
29 | def f(x, y, z, a, b, c, *, u, v, w): # Too many positional arguments (6/5)
| ^ PLR0917
30 | pass
|

too_many_positional.py:43:9: PLR0917 Too many positional arguments (6/5)
too_many_positional_arguments.py:43:9: PLR0917 Too many positional arguments (6/5)
|
41 | pass
42 |
Expand All @@ -31,12 +31,10 @@ too_many_positional.py:43:9: PLR0917 Too many positional arguments (6/5)
44 | pass
|

too_many_positional.py:47:9: PLR0917 Too many positional arguments (6/5)
too_many_positional_arguments.py:47:9: PLR0917 Too many positional arguments (6/5)
|
46 | @staticmethod
47 | def f(self, a, b, c, d, e): # Too many positional arguments (6/5)
| ^ PLR0917
48 | pass
|


0 comments on commit 52d27be

Please sign in to comment.