mirror of https://github.com/astral-sh/ruff
Move McCabe violations (#2534)
This commit is contained in:
parent
d985473f4f
commit
14c5000ad5
|
|
@ -149,7 +149,7 @@ ruff_macros::define_rule_mapping!(
|
|||
// flake8-debugger
|
||||
T100 => rules::flake8_debugger::rules::Debugger,
|
||||
// mccabe
|
||||
C901 => violations::FunctionIsTooComplex,
|
||||
C901 => rules::mccabe::rules::FunctionIsTooComplex,
|
||||
// flake8-tidy-imports
|
||||
TID251 => rules::flake8_tidy_imports::banned_api::BannedApi,
|
||||
TID252 => rules::flake8_tidy_imports::relative_imports::RelativeImports,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
use rustpython_ast::{ExcepthandlerKind, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::define_violation;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::source_code::Locator;
|
||||
use crate::violations;
|
||||
use crate::violation::Violation;
|
||||
use ruff_macros::derive_message_formats;
|
||||
|
||||
define_violation!(
|
||||
pub struct FunctionIsTooComplex {
|
||||
pub name: String,
|
||||
pub complexity: usize,
|
||||
}
|
||||
);
|
||||
impl Violation for FunctionIsTooComplex {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let FunctionIsTooComplex { name, complexity } = self;
|
||||
format!("`{name}` is too complex ({complexity})")
|
||||
}
|
||||
}
|
||||
|
||||
fn get_complexity_number(stmts: &[Stmt]) -> usize {
|
||||
let mut complexity = 0;
|
||||
|
|
@ -66,7 +82,7 @@ pub fn function_is_too_complex(
|
|||
let complexity = get_complexity_number(body) + 1;
|
||||
if complexity > max_complexity {
|
||||
Some(Diagnostic::new(
|
||||
violations::FunctionIsTooComplex {
|
||||
FunctionIsTooComplex {
|
||||
name: name.to_string(),
|
||||
complexity,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,22 +6,6 @@ use crate::define_violation;
|
|||
|
||||
use crate::violation::{AlwaysAutofixableViolation, Violation};
|
||||
|
||||
// mccabe
|
||||
|
||||
define_violation!(
|
||||
pub struct FunctionIsTooComplex {
|
||||
pub name: String,
|
||||
pub complexity: usize,
|
||||
}
|
||||
);
|
||||
impl Violation for FunctionIsTooComplex {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let FunctionIsTooComplex { name, complexity } = self;
|
||||
format!("`{name}` is too complex ({complexity})")
|
||||
}
|
||||
}
|
||||
|
||||
// flake8-print
|
||||
|
||||
define_violation!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue