Skip to content

Commit

Permalink
Use value > max style in pylint and mccabe messages (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Mar 16, 2023
1 parent de1106b commit 9ae9cc9
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 45 deletions.
10 changes: 8 additions & 2 deletions crates/ruff/src/rules/mccabe/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
}
}

Expand Down Expand Up @@ -135,6 +140,7 @@ pub fn function_is_too_complex(
ComplexStructure {
name: name.to_string(),
complexity,
max_complexity,
},
identifier_range(stmt, locator),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pylint/rules/too_many_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pylint/rules/too_many_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pylint/rules/too_many_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9ae9cc9

Please sign in to comment.