mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Rename function-is-too-complex to complex-structure
This commit is contained in:
parent
7db6a2d6d4
commit
70ff65154d
8 changed files with 35 additions and 35 deletions
|
@ -749,7 +749,7 @@ For more, see [mccabe](https://pypi.org/project/mccabe/) on PyPI.
|
||||||
|
|
||||||
| Code | Name | Message | Fix |
|
| Code | Name | Message | Fix |
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| C901 | [function-is-too-complex](https://github.com/charliermarsh/ruff/blob/main/docs/rules/function-is-too-complex.md) | `{name}` is too complex ({complexity}) | |
|
| C901 | [complex-structure](https://github.com/charliermarsh/ruff/blob/main/docs/rules/complex-structure.md) | `{name}` is too complex ({complexity}) | |
|
||||||
|
|
||||||
### isort (I)
|
### isort (I)
|
||||||
|
|
||||||
|
|
|
@ -566,7 +566,7 @@ where
|
||||||
flake8_return::rules::function(self, body);
|
flake8_return::rules::function(self, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.settings.rules.enabled(&Rule::FunctionIsTooComplex) {
|
if self.settings.rules.enabled(&Rule::ComplexStructure) {
|
||||||
if let Some(diagnostic) = mccabe::rules::function_is_too_complex(
|
if let Some(diagnostic) = mccabe::rules::function_is_too_complex(
|
||||||
stmt,
|
stmt,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -203,7 +203,7 @@ ruff_macros::define_rule_mapping!(
|
||||||
// flake8-debugger
|
// flake8-debugger
|
||||||
T100 => rules::flake8_debugger::rules::Debugger,
|
T100 => rules::flake8_debugger::rules::Debugger,
|
||||||
// mccabe
|
// mccabe
|
||||||
C901 => rules::mccabe::rules::FunctionIsTooComplex,
|
C901 => rules::mccabe::rules::ComplexStructure,
|
||||||
// flake8-tidy-imports
|
// flake8-tidy-imports
|
||||||
TID251 => rules::flake8_tidy_imports::banned_api::BannedApi,
|
TID251 => rules::flake8_tidy_imports::banned_api::BannedApi,
|
||||||
TID252 => rules::flake8_tidy_imports::relative_imports::RelativeImports,
|
TID252 => rules::flake8_tidy_imports::relative_imports::RelativeImports,
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod tests {
|
||||||
Path::new("mccabe/C901.py"),
|
Path::new("mccabe/C901.py"),
|
||||||
&Settings {
|
&Settings {
|
||||||
mccabe: super::settings::Settings { max_complexity },
|
mccabe: super::settings::Settings { max_complexity },
|
||||||
..Settings::for_rules(vec![Rule::FunctionIsTooComplex])
|
..Settings::for_rules(vec![Rule::ComplexStructure])
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
assert_yaml_snapshot!(snapshot, diagnostics);
|
assert_yaml_snapshot!(snapshot, diagnostics);
|
||||||
|
|
|
@ -44,15 +44,15 @@ define_violation!(
|
||||||
/// return 2
|
/// return 2
|
||||||
/// return 1
|
/// return 1
|
||||||
/// ```
|
/// ```
|
||||||
pub struct FunctionIsTooComplex {
|
pub struct ComplexStructure {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub complexity: usize,
|
pub complexity: usize,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
impl Violation for FunctionIsTooComplex {
|
impl Violation for ComplexStructure {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
let FunctionIsTooComplex { name, complexity } = self;
|
let ComplexStructure { name, complexity } = self;
|
||||||
format!("`{name}` is too complex ({complexity})")
|
format!("`{name}` is too complex ({complexity})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ pub fn function_is_too_complex(
|
||||||
let complexity = get_complexity_number(body) + 1;
|
let complexity = get_complexity_number(body) + 1;
|
||||||
if complexity > max_complexity {
|
if complexity > max_complexity {
|
||||||
Some(Diagnostic::new(
|
Some(Diagnostic::new(
|
||||||
FunctionIsTooComplex {
|
ComplexStructure {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
complexity,
|
complexity,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/rules/mccabe/mod.rs
|
source: crates/ruff/src/rules/mccabe/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: trivial
|
name: trivial
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -15,7 +15,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: expr_as_statement
|
name: expr_as_statement
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -27,7 +27,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: sequential
|
name: sequential
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -39,7 +39,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: if_elif_else_dead_path
|
name: if_elif_else_dead_path
|
||||||
complexity: 3
|
complexity: 3
|
||||||
location:
|
location:
|
||||||
|
@ -51,7 +51,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: nested_ifs
|
name: nested_ifs
|
||||||
complexity: 3
|
complexity: 3
|
||||||
location:
|
location:
|
||||||
|
@ -63,7 +63,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: for_loop
|
name: for_loop
|
||||||
complexity: 2
|
complexity: 2
|
||||||
location:
|
location:
|
||||||
|
@ -75,7 +75,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: for_else
|
name: for_else
|
||||||
complexity: 2
|
complexity: 2
|
||||||
location:
|
location:
|
||||||
|
@ -87,7 +87,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: recursive
|
name: recursive
|
||||||
complexity: 2
|
complexity: 2
|
||||||
location:
|
location:
|
||||||
|
@ -99,7 +99,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: nested_functions
|
name: nested_functions
|
||||||
complexity: 3
|
complexity: 3
|
||||||
location:
|
location:
|
||||||
|
@ -111,7 +111,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: a
|
name: a
|
||||||
complexity: 2
|
complexity: 2
|
||||||
location:
|
location:
|
||||||
|
@ -123,7 +123,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: b
|
name: b
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -135,7 +135,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: try_else
|
name: try_else
|
||||||
complexity: 4
|
complexity: 4
|
||||||
location:
|
location:
|
||||||
|
@ -147,7 +147,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: nested_try_finally
|
name: nested_try_finally
|
||||||
complexity: 3
|
complexity: 3
|
||||||
location:
|
location:
|
||||||
|
@ -159,7 +159,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: foobar
|
name: foobar
|
||||||
complexity: 3
|
complexity: 3
|
||||||
location:
|
location:
|
||||||
|
@ -171,7 +171,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: annotated_assign
|
name: annotated_assign
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -183,7 +183,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: handle
|
name: handle
|
||||||
complexity: 9
|
complexity: 9
|
||||||
location:
|
location:
|
||||||
|
@ -195,7 +195,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: a
|
name: a
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -207,7 +207,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: b
|
name: b
|
||||||
complexity: 2
|
complexity: 2
|
||||||
location:
|
location:
|
||||||
|
@ -219,7 +219,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: c
|
name: c
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -231,7 +231,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: error
|
name: error
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -243,7 +243,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: info
|
name: info
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
@ -255,7 +255,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: exception
|
name: exception
|
||||||
complexity: 1
|
complexity: 1
|
||||||
location:
|
location:
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/rules/mccabe/mod.rs
|
source: crates/ruff/src/rules/mccabe/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: try_else
|
name: try_else
|
||||||
complexity: 4
|
complexity: 4
|
||||||
location:
|
location:
|
||||||
|
@ -15,7 +15,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
FunctionIsTooComplex:
|
ComplexStructure:
|
||||||
name: handle
|
name: handle
|
||||||
complexity: 9
|
complexity: 9
|
||||||
location:
|
location:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# function-is-too-complex (C901)
|
# complex-structure (C901)
|
||||||
|
|
||||||
Derived from the **mccabe** linter.
|
Derived from the **mccabe** linter.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue