diff --git a/crates/ruff/src/rules/mccabe/rules.rs b/crates/ruff/src/rules/mccabe/rules.rs index 71febbc601..5b07789db6 100644 --- a/crates/ruff/src/rules/mccabe/rules.rs +++ b/crates/ruff/src/rules/mccabe/rules.rs @@ -50,13 +50,18 @@ use ruff_python_ast::source_code::Locator; pub struct ComplexStructure { pub name: String, pub complexity: usize, + pub max_complexity: usize, } impl Violation for ComplexStructure { #[derive_message_formats] fn message(&self) -> String { - let ComplexStructure { name, complexity } = self; - format!("`{name}` is too complex ({complexity})") + let ComplexStructure { + name, + complexity, + max_complexity, + } = self; + format!("`{name}` is too complex ({complexity} > {max_complexity})") } } @@ -135,6 +140,7 @@ pub fn function_is_too_complex( ComplexStructure { name: name.to_string(), complexity, + max_complexity, }, identifier_range(stmt, locator), )) diff --git a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap index 632935557d..9a1351878d 100644 --- a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap +++ b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: ComplexStructure - body: "`trivial` is too complex (1)" + body: "`trivial` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`expr_as_statement` is too complex (1)" + body: "`expr_as_statement` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -30,7 +30,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`sequential` is too complex (1)" + body: "`sequential` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -43,7 +43,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`if_elif_else_dead_path` is too complex (3)" + body: "`if_elif_else_dead_path` is too complex (3 > 0)" suggestion: ~ fixable: false location: @@ -56,7 +56,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`nested_ifs` is too complex (3)" + body: "`nested_ifs` is too complex (3 > 0)" suggestion: ~ fixable: false location: @@ -69,7 +69,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`for_loop` is too complex (2)" + body: "`for_loop` is too complex (2 > 0)" suggestion: ~ fixable: false location: @@ -82,7 +82,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`for_else` is too complex (2)" + body: "`for_else` is too complex (2 > 0)" suggestion: ~ fixable: false location: @@ -95,7 +95,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`recursive` is too complex (2)" + body: "`recursive` is too complex (2 > 0)" suggestion: ~ fixable: false location: @@ -108,7 +108,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`nested_functions` is too complex (3)" + body: "`nested_functions` is too complex (3 > 0)" suggestion: ~ fixable: false location: @@ -121,7 +121,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`a` is too complex (2)" + body: "`a` is too complex (2 > 0)" suggestion: ~ fixable: false location: @@ -134,7 +134,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`b` is too complex (1)" + body: "`b` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -147,7 +147,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`try_else` is too complex (4)" + body: "`try_else` is too complex (4 > 0)" suggestion: ~ fixable: false location: @@ -160,7 +160,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`nested_try_finally` is too complex (1)" + body: "`nested_try_finally` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -173,7 +173,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`foobar` is too complex (3)" + body: "`foobar` is too complex (3 > 0)" suggestion: ~ fixable: false location: @@ -186,7 +186,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`annotated_assign` is too complex (1)" + body: "`annotated_assign` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -199,7 +199,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`handle` is too complex (9)" + body: "`handle` is too complex (9 > 0)" suggestion: ~ fixable: false location: @@ -212,7 +212,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`a` is too complex (1)" + body: "`a` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -225,7 +225,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`b` is too complex (2)" + body: "`b` is too complex (2 > 0)" suggestion: ~ fixable: false location: @@ -238,7 +238,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`c` is too complex (1)" + body: "`c` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -251,7 +251,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`error` is too complex (1)" + body: "`error` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -264,7 +264,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`info` is too complex (1)" + body: "`info` is too complex (1 > 0)" suggestion: ~ fixable: false location: @@ -277,7 +277,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`exception` is too complex (1)" + body: "`exception` is too complex (1 > 0)" suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap index b00affeb57..5bcea57845 100644 --- a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap +++ b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: ComplexStructure - body: "`try_else` is too complex (4)" + body: "`try_else` is too complex (4 > 3)" suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: ComplexStructure - body: "`handle` is too complex (9)" + body: "`handle` is too complex (9 > 3)" suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs index a37eec9c03..e39a5d0bf0 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs @@ -16,7 +16,7 @@ impl Violation for TooManyArguments { #[derive_message_formats] fn message(&self) -> String { let TooManyArguments { c_args, max_args } = self; - format!("Too many arguments to function call ({c_args}/{max_args})") + format!("Too many arguments to function call ({c_args} > {max_args})") } } diff --git a/crates/ruff/src/rules/pylint/rules/too_many_branches.rs b/crates/ruff/src/rules/pylint/rules/too_many_branches.rs index 51e847e35b..86d31810de 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_branches.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_branches.rs @@ -18,7 +18,7 @@ impl Violation for TooManyBranches { branches, max_branches, } = self; - format!("Too many branches ({branches}/{max_branches})") + format!("Too many branches ({branches} > {max_branches})") } } diff --git a/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs b/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs index 9ddbad22c5..687225e6e7 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_return_statements.rs @@ -19,7 +19,7 @@ impl Violation for TooManyReturnStatements { returns, max_returns, } = self; - format!("Too many return statements ({returns}/{max_returns})") + format!("Too many return statements ({returns} > {max_returns})") } } diff --git a/crates/ruff/src/rules/pylint/rules/too_many_statements.rs b/crates/ruff/src/rules/pylint/rules/too_many_statements.rs index 981e4abb9c..8a07fe92b0 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_statements.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_statements.rs @@ -18,7 +18,7 @@ impl Violation for TooManyStatements { statements, max_statements, } = self; - format!("Too many statements ({statements}/{max_statements})") + format!("Too many statements ({statements} > {max_statements})") } } diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap index f0b94fef5d..b5380f2bc8 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyReturnStatements - body: Too many return statements (11/6) + body: Too many return statements (11 > 6) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap index ae130f88de..d5f086b68f 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyBranches - body: Too many branches (13/12) + body: Too many branches (13 > 12) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap index e43addadf7..322ae7535f 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyArguments - body: Too many arguments to function call (8/5) + body: Too many arguments to function call (8 > 5) suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyArguments - body: Too many arguments to function call (6/5) + body: Too many arguments to function call (6 > 5) suggestion: ~ fixable: false location: @@ -30,7 +30,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyArguments - body: Too many arguments to function call (6/5) + body: Too many arguments to function call (6 > 5) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap index 4cd6c40b28..b2400d3d11 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyStatements - body: Too many statements (52/50) + body: Too many statements (52 > 50) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap index b01b0aaae8..403cd755a1 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyArguments - body: Too many arguments to function call (6/4) + body: Too many arguments to function call (6 > 4) suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyArguments - body: Too many arguments to function call (6/4) + body: Too many arguments to function call (6 > 4) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap index cf25b6cd3a..aabf525484 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyArguments - body: Too many arguments to function call (6/5) + body: Too many arguments to function call (6 > 5) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap index 57b5398732..5861ab0c68 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyBranches - body: Too many branches (2/1) + body: Too many branches (2 > 1) suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyBranches - body: Too many branches (2/1) + body: Too many branches (2 > 1) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap index de06f89203..a670693bf4 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyReturnStatements - body: Too many return statements (2/1) + body: Too many return statements (2 > 1) suggestion: ~ fixable: false location: diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap index b025184907..67f07d5303 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: name: TooManyStatements - body: Too many statements (2/1) + body: Too many statements (2 > 1) suggestion: ~ fixable: false location: @@ -17,7 +17,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyStatements - body: Too many statements (3/1) + body: Too many statements (3 > 1) suggestion: ~ fixable: false location: @@ -30,7 +30,7 @@ expression: diagnostics parent: ~ - kind: name: TooManyStatements - body: Too many statements (2/1) + body: Too many statements (2 > 1) suggestion: ~ fixable: false location: