mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 10:00:42 +00:00
Rename too-many-positional(-arguments) (#12905)
This commit is contained in:
parent
6ed06afd28
commit
52d27befe8
7 changed files with 23 additions and 19 deletions
|
@ -263,8 +263,8 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||||
if checker.enabled(Rule::TooManyArguments) {
|
if checker.enabled(Rule::TooManyArguments) {
|
||||||
pylint::rules::too_many_arguments(checker, function_def);
|
pylint::rules::too_many_arguments(checker, function_def);
|
||||||
}
|
}
|
||||||
if checker.enabled(Rule::TooManyPositional) {
|
if checker.enabled(Rule::TooManyPositionalArguments) {
|
||||||
pylint::rules::too_many_positional(checker, function_def);
|
pylint::rules::too_many_positional_arguments(checker, function_def);
|
||||||
}
|
}
|
||||||
if checker.enabled(Rule::TooManyReturnStatements) {
|
if checker.enabled(Rule::TooManyReturnStatements) {
|
||||||
if let Some(diagnostic) = pylint::rules::too_many_return_statements(
|
if let Some(diagnostic) = pylint::rules::too_many_return_statements(
|
||||||
|
|
|
@ -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, "R0914") => (RuleGroup::Preview, rules::pylint::rules::TooManyLocals),
|
||||||
(Pylint, "R0915") => (RuleGroup::Stable, rules::pylint::rules::TooManyStatements),
|
(Pylint, "R0915") => (RuleGroup::Stable, rules::pylint::rules::TooManyStatements),
|
||||||
(Pylint, "R0916") => (RuleGroup::Preview, rules::pylint::rules::TooManyBooleanExpressions),
|
(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, "R1701") => (RuleGroup::Removed, rules::pylint::rules::RepeatedIsinstanceCalls),
|
||||||
(Pylint, "R1702") => (RuleGroup::Preview, rules::pylint::rules::TooManyNestedBlocks),
|
(Pylint, "R1702") => (RuleGroup::Preview, rules::pylint::rules::TooManyNestedBlocks),
|
||||||
(Pylint, "R1704") => (RuleGroup::Stable, rules::pylint::rules::RedefinedArgumentFromLocal),
|
(Pylint, "R1704") => (RuleGroup::Stable, rules::pylint::rules::RedefinedArgumentFromLocal),
|
||||||
|
|
|
@ -123,7 +123,10 @@ mod tests {
|
||||||
#[test_case(Rule::RedefinedLoopName, Path::new("redefined_loop_name.py"))]
|
#[test_case(Rule::RedefinedLoopName, Path::new("redefined_loop_name.py"))]
|
||||||
#[test_case(Rule::ReturnInInit, Path::new("return_in_init.py"))]
|
#[test_case(Rule::ReturnInInit, Path::new("return_in_init.py"))]
|
||||||
#[test_case(Rule::TooManyArguments, Path::new("too_many_arguments.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::TooManyBranches, Path::new("too_many_branches.py"))]
|
||||||
#[test_case(
|
#[test_case(
|
||||||
Rule::TooManyReturnStatements,
|
Rule::TooManyReturnStatements,
|
||||||
|
@ -294,7 +297,7 @@ mod tests {
|
||||||
max_positional_args: 4,
|
max_positional_args: 4,
|
||||||
..pylint::settings::Settings::default()
|
..pylint::settings::Settings::default()
|
||||||
},
|
},
|
||||||
..LinterSettings::for_rule(Rule::TooManyPositional)
|
..LinterSettings::for_rule(Rule::TooManyPositionalArguments)
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
assert_messages!(diagnostics);
|
assert_messages!(diagnostics);
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub(crate) use too_many_boolean_expressions::*;
|
||||||
pub(crate) use too_many_branches::*;
|
pub(crate) use too_many_branches::*;
|
||||||
pub(crate) use too_many_locals::*;
|
pub(crate) use too_many_locals::*;
|
||||||
pub(crate) use too_many_nested_blocks::*;
|
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_public_methods::*;
|
||||||
pub(crate) use too_many_return_statements::*;
|
pub(crate) use too_many_return_statements::*;
|
||||||
pub(crate) use too_many_statements::*;
|
pub(crate) use too_many_statements::*;
|
||||||
|
@ -182,7 +182,7 @@ mod too_many_boolean_expressions;
|
||||||
mod too_many_branches;
|
mod too_many_branches;
|
||||||
mod too_many_locals;
|
mod too_many_locals;
|
||||||
mod too_many_nested_blocks;
|
mod too_many_nested_blocks;
|
||||||
mod too_many_positional;
|
mod too_many_positional_arguments;
|
||||||
mod too_many_public_methods;
|
mod too_many_public_methods;
|
||||||
mod too_many_return_statements;
|
mod too_many_return_statements;
|
||||||
mod too_many_statements;
|
mod too_many_statements;
|
||||||
|
|
|
@ -42,21 +42,24 @@ use crate::checkers::ast::Checker;
|
||||||
/// ## Options
|
/// ## Options
|
||||||
/// - `lint.pylint.max-positional-args`
|
/// - `lint.pylint.max-positional-args`
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct TooManyPositional {
|
pub struct TooManyPositionalArguments {
|
||||||
c_pos: usize,
|
c_pos: usize,
|
||||||
max_pos: usize,
|
max_pos: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Violation for TooManyPositional {
|
impl Violation for TooManyPositionalArguments {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
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})")
|
format!("Too many positional arguments ({c_pos}/{max_pos})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PLR0917
|
/// 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();
|
let semantic = checker.semantic();
|
||||||
|
|
||||||
// Count the number of positional arguments.
|
// Count the number of positional arguments.
|
||||||
|
@ -109,7 +112,7 @@ pub(crate) fn too_many_positional(checker: &mut Checker, function_def: &ast::Stm
|
||||||
}
|
}
|
||||||
|
|
||||||
checker.diagnostics.push(Diagnostic::new(
|
checker.diagnostics.push(Diagnostic::new(
|
||||||
TooManyPositional {
|
TooManyPositionalArguments {
|
||||||
c_pos: num_positional_args,
|
c_pos: num_positional_args,
|
||||||
max_pos: checker.settings.pylint.max_positional_args,
|
max_pos: checker.settings.pylint.max_positional_args,
|
||||||
},
|
},
|
|
@ -1,28 +1,28 @@
|
||||||
---
|
---
|
||||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
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)
|
1 | def f(x, y, z, t, u, v, w, r): # Too many positional arguments (8/5)
|
||||||
| ^ PLR0917
|
| ^ PLR0917
|
||||||
2 | pass
|
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)
|
21 | def f(x, y, z, /, u, v, w): # Too many positional arguments (6/5)
|
||||||
| ^ PLR0917
|
| ^ PLR0917
|
||||||
22 | pass
|
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)
|
29 | def f(x, y, z, a, b, c, *, u, v, w): # Too many positional arguments (6/5)
|
||||||
| ^ PLR0917
|
| ^ PLR0917
|
||||||
30 | pass
|
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
|
41 | pass
|
||||||
42 |
|
42 |
|
||||||
|
@ -31,12 +31,10 @@ too_many_positional.py:43:9: PLR0917 Too many positional arguments (6/5)
|
||||||
44 | pass
|
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
|
46 | @staticmethod
|
||||||
47 | def f(self, a, b, c, d, e): # Too many positional arguments (6/5)
|
47 | def f(self, a, b, c, d, e): # Too many positional arguments (6/5)
|
||||||
| ^ PLR0917
|
| ^ PLR0917
|
||||||
48 | pass
|
48 | pass
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue