mirror of https://github.com/astral-sh/ruff
Tweaks
This commit is contained in:
parent
3d1ae648ad
commit
1dd0bd4e6e
|
|
@ -1,8 +1,8 @@
|
||||||
use ruff_python_ast::{self as ast, Stmt};
|
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
use ruff_python_ast as ast;
|
||||||
use ruff_python_semantic::analyze::visibility::{self, Visibility::Public};
|
use ruff_python_semantic::analyze::visibility::{self, Visibility::Public};
|
||||||
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// Checks for classes with too many public methods
|
/// Checks for classes with too many public methods
|
||||||
///
|
///
|
||||||
/// By default, this rule allows up to 20 statements, as configured by the
|
/// By default, this rule allows up to 20 statements, as configured by the
|
||||||
/// `pylint.max-public-methods` option.
|
/// [`pylint.max-public-methods`] option.
|
||||||
///
|
///
|
||||||
/// ## Why is this bad?
|
/// ## Why is this bad?
|
||||||
/// Classes with many public methods are harder to understand
|
/// Classes with many public methods are harder to understand
|
||||||
|
|
@ -19,8 +19,7 @@ use crate::checkers::ast::Checker;
|
||||||
/// Instead, consider refactoring the class into separate classes.
|
/// Instead, consider refactoring the class into separate classes.
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// With `pylint.max-public-settings` set to 5
|
/// Assuming that `pylint.max-public-settings` is set to 5:
|
||||||
///
|
|
||||||
/// ```python
|
/// ```python
|
||||||
/// class Linter:
|
/// class Linter:
|
||||||
/// def __init__(self):
|
/// def __init__(self):
|
||||||
|
|
@ -106,12 +105,12 @@ pub(crate) fn too_many_public_methods(
|
||||||
class_def: &ast::StmtClassDef,
|
class_def: &ast::StmtClassDef,
|
||||||
max_methods: usize,
|
max_methods: usize,
|
||||||
) {
|
) {
|
||||||
let ast::StmtClassDef { body, range, .. } = class_def;
|
let methods = class_def
|
||||||
let methods = body
|
.body
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|stmt| match stmt {
|
.filter(|stmt| {
|
||||||
Stmt::FunctionDef(node) => matches!(visibility::method_visibility(node), Public),
|
stmt.as_function_def_stmt()
|
||||||
_ => false,
|
.is_some_and(|node| matches!(visibility::method_visibility(node), Public))
|
||||||
})
|
})
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
|
|
@ -121,7 +120,7 @@ pub(crate) fn too_many_public_methods(
|
||||||
methods,
|
methods,
|
||||||
max_methods,
|
max_methods,
|
||||||
},
|
},
|
||||||
*range,
|
class_def.range(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue