Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 14, 2023
1 parent 3d1ae64 commit 1dd0bd4
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions crates/ruff/src/rules/pylint/rules/too_many_public_methods.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use ruff_python_ast::{self as ast, Stmt};

use ruff_diagnostics::{Diagnostic, 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_text_size::Ranged;

use crate::checkers::ast::Checker;

/// ## What it does
/// Checks for classes with too many public methods
///
/// 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?
/// Classes with many public methods are harder to understand
Expand All @@ -19,8 +19,7 @@ use crate::checkers::ast::Checker;
/// Instead, consider refactoring the class into separate classes.
///
/// ## Example
/// With `pylint.max-public-settings` set to 5
///
/// Assuming that `pylint.max-public-settings` is set to 5:
/// ```python
/// class Linter:
/// def __init__(self):
Expand Down Expand Up @@ -106,12 +105,12 @@ pub(crate) fn too_many_public_methods(
class_def: &ast::StmtClassDef,
max_methods: usize,
) {
let ast::StmtClassDef { body, range, .. } = class_def;
let methods = body
let methods = class_def
.body
.iter()
.filter(|stmt| match stmt {
Stmt::FunctionDef(node) => matches!(visibility::method_visibility(node), Public),
_ => false,
.filter(|stmt| {
stmt.as_function_def_stmt()
.is_some_and(|node| matches!(visibility::method_visibility(node), Public))
})
.count();

Expand All @@ -121,7 +120,7 @@ pub(crate) fn too_many_public_methods(
methods,
max_methods,
},
*range,
class_def.range(),
));
}
}

0 comments on commit 1dd0bd4

Please sign in to comment.