diff --git a/crates/ruff/src/rules/flake8_bandit/helpers.rs b/crates/ruff/src/rules/flake8_bandit/helpers.rs index 1de1cc92e16ac..37b0d6d7454af 100644 --- a/crates/ruff/src/rules/flake8_bandit/helpers.rs +++ b/crates/ruff/src/rules/flake8_bandit/helpers.rs @@ -8,7 +8,7 @@ static PASSWORD_CANDIDATE_REGEX: Lazy = Lazy::new(|| { Regex::new(r"(^|_)(?i)(pas+wo?r?d|pass(phrase)?|pwd|token|secrete?)($|_)").unwrap() }); -pub(crate) fn string_literal(expr: &Expr) -> Option<&str> { +pub(super) fn string_literal(expr: &Expr) -> Option<&str> { match expr { Expr::Constant(ast::ExprConstant { value: Constant::Str(string), @@ -18,11 +18,11 @@ pub(crate) fn string_literal(expr: &Expr) -> Option<&str> { } } -pub(crate) fn matches_password_name(string: &str) -> bool { +pub(super) fn matches_password_name(string: &str) -> bool { PASSWORD_CANDIDATE_REGEX.is_match(string) } -pub(crate) fn is_untyped_exception(type_: Option<&Expr>, model: &SemanticModel) -> bool { +pub(super) fn is_untyped_exception(type_: Option<&Expr>, model: &SemanticModel) -> bool { type_.map_or(true, |type_| { if let Expr::Tuple(ast::ExprTuple { elts, .. }) = &type_ { elts.iter().any(|type_| { diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs index 27241912ac6f0..ad13566cc5b98 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/helpers.rs @@ -1,6 +1,6 @@ use rustpython_parser::ast::{self, Expr, Keyword}; -pub(crate) fn expr_name(func: &Expr) -> Option<&str> { +pub(super) fn expr_name(func: &Expr) -> Option<&str> { if let Expr::Name(ast::ExprName { id, .. }) = func { Some(id) } else { @@ -8,7 +8,7 @@ pub(crate) fn expr_name(func: &Expr) -> Option<&str> { } } -pub(crate) fn exactly_one_argument_with_matching_function<'a>( +pub(super) fn exactly_one_argument_with_matching_function<'a>( name: &str, func: &Expr, args: &'a [Expr], @@ -26,7 +26,7 @@ pub(crate) fn exactly_one_argument_with_matching_function<'a>( Some(&args[0]) } -pub(crate) fn first_argument_with_matching_function<'a>( +pub(super) fn first_argument_with_matching_function<'a>( name: &str, func: &Expr, args: &'a [Expr], diff --git a/crates/ruff/src/rules/flake8_django/rules/helpers.rs b/crates/ruff/src/rules/flake8_django/rules/helpers.rs index 3d0f72e10eb66..3dc13530457c3 100644 --- a/crates/ruff/src/rules/flake8_django/rules/helpers.rs +++ b/crates/ruff/src/rules/flake8_django/rules/helpers.rs @@ -3,14 +3,14 @@ use rustpython_parser::ast::Expr; use ruff_python_semantic::model::SemanticModel; /// Return `true` if a Python class appears to be a Django model, based on its base classes. -pub(crate) fn is_model(model: &SemanticModel, base: &Expr) -> bool { +pub(super) fn is_model(model: &SemanticModel, base: &Expr) -> bool { model.resolve_call_path(base).map_or(false, |call_path| { call_path.as_slice() == ["django", "db", "models", "Model"] }) } /// Return `true` if a Python class appears to be a Django model form, based on its base classes. -pub(crate) fn is_model_form(model: &SemanticModel, base: &Expr) -> bool { +pub(super) fn is_model_form(model: &SemanticModel, base: &Expr) -> bool { model.resolve_call_path(base).map_or(false, |call_path| { call_path.as_slice() == ["django", "forms", "ModelForm"] || call_path.as_slice() == ["django", "forms", "models", "ModelForm"] @@ -18,7 +18,7 @@ pub(crate) fn is_model_form(model: &SemanticModel, base: &Expr) -> bool { } /// Return `true` if the expression is constructor for a Django model field. -pub(crate) fn is_model_field(model: &SemanticModel, expr: &Expr) -> bool { +pub(super) fn is_model_field(model: &SemanticModel, expr: &Expr) -> bool { model.resolve_call_path(expr).map_or(false, |call_path| { call_path .as_slice() @@ -27,7 +27,7 @@ pub(crate) fn is_model_field(model: &SemanticModel, expr: &Expr) -> bool { } /// Return the name of the field type, if the expression is constructor for a Django model field. -pub(crate) fn get_model_field_name<'a>( +pub(super) fn get_model_field_name<'a>( model: &'a SemanticModel, expr: &'a Expr, ) -> Option<&'a str> { diff --git a/crates/ruff/src/rules/flake8_return/helpers.rs b/crates/ruff/src/rules/flake8_return/helpers.rs index bfa8508e14c96..307d8936c324c 100644 --- a/crates/ruff/src/rules/flake8_return/helpers.rs +++ b/crates/ruff/src/rules/flake8_return/helpers.rs @@ -6,7 +6,7 @@ use ruff_python_whitespace::UniversalNewlines; /// Return `true` if a function's return statement include at least one /// non-`None` value. -pub(crate) fn result_exists(returns: &[(&Stmt, Option<&Expr>)]) -> bool { +pub(super) fn result_exists(returns: &[(&Stmt, Option<&Expr>)]) -> bool { returns.iter().any(|(_, expr)| { expr.map(|expr| { !matches!( @@ -25,7 +25,7 @@ pub(crate) fn result_exists(returns: &[(&Stmt, Option<&Expr>)]) -> bool { /// /// This method assumes that the statement is the last statement in its body; specifically, that /// the statement isn't followed by a semicolon, followed by a multi-line statement. -pub(crate) fn end_of_last_statement(stmt: &Stmt, locator: &Locator) -> TextSize { +pub(super) fn end_of_last_statement(stmt: &Stmt, locator: &Locator) -> TextSize { // End-of-file, so just return the end of the statement. if stmt.end() == locator.text_len() { stmt.end() diff --git a/crates/ruff/src/rules/flynt/helpers.rs b/crates/ruff/src/rules/flynt/helpers.rs index 2530740a63d5e..f3314714990ca 100644 --- a/crates/ruff/src/rules/flynt/helpers.rs +++ b/crates/ruff/src/rules/flynt/helpers.rs @@ -13,7 +13,7 @@ fn to_formatted_value_expr(inner: &Expr) -> Expr { } /// Convert a string to a constant string expression. -pub(crate) fn to_constant_string(s: &str) -> Expr { +pub(super) fn to_constant_string(s: &str) -> Expr { let node = ast::ExprConstant { value: Constant::Str(s.to_owned()), kind: None, @@ -47,7 +47,7 @@ fn is_simple_callee(func: &Expr) -> bool { } /// Convert an expression to a f-string element (if it looks like a good idea). -pub(crate) fn to_fstring_elem(expr: &Expr) -> Option { +pub(super) fn to_fstring_elem(expr: &Expr) -> Option { match expr { // These are directly handled by `unparse_fstring_elem`: Expr::Constant(ast::ExprConstant { diff --git a/crates/ruff/src/rules/isort/helpers.rs b/crates/ruff/src/rules/isort/helpers.rs index fe60ccef67130..4bcf005aa4bb6 100644 --- a/crates/ruff/src/rules/isort/helpers.rs +++ b/crates/ruff/src/rules/isort/helpers.rs @@ -8,7 +8,7 @@ use crate::rules::isort::types::TrailingComma; /// Return `true` if a `Stmt::ImportFrom` statement ends with a magic /// trailing comma. -pub(crate) fn trailing_comma(stmt: &Stmt, locator: &Locator) -> TrailingComma { +pub(super) fn trailing_comma(stmt: &Stmt, locator: &Locator) -> TrailingComma { let contents = locator.slice(stmt.range()); let mut count = 0u32; let mut trailing_comma = TrailingComma::Absent; @@ -36,7 +36,7 @@ pub(crate) fn trailing_comma(stmt: &Stmt, locator: &Locator) -> TrailingComma { } /// Return `true` if a [`Stmt`] is preceded by a "comment break" -pub(crate) fn has_comment_break(stmt: &Stmt, locator: &Locator) -> bool { +pub(super) fn has_comment_break(stmt: &Stmt, locator: &Locator) -> bool { // Starting from the `Stmt` (`def f(): pass`), we want to detect patterns like // this: // diff --git a/crates/ruff/src/rules/pandas_vet/helpers.rs b/crates/ruff/src/rules/pandas_vet/helpers.rs index 42b2548e7149f..d011be8daf7ae 100644 --- a/crates/ruff/src/rules/pandas_vet/helpers.rs +++ b/crates/ruff/src/rules/pandas_vet/helpers.rs @@ -4,7 +4,7 @@ use rustpython_parser::ast::Expr; use ruff_python_semantic::binding::{BindingKind, Importation}; use ruff_python_semantic::model::SemanticModel; -pub(crate) enum Resolution { +pub(super) enum Resolution { /// The expression resolves to an irrelevant expression type (e.g., a constant). IrrelevantExpression, /// The expression resolves to an irrelevant binding (e.g., a function definition). @@ -16,7 +16,7 @@ pub(crate) enum Resolution { } /// Test an [`Expr`] for relevance to Pandas-related operations. -pub(crate) fn test_expression(expr: &Expr, model: &SemanticModel) -> Resolution { +pub(super) fn test_expression(expr: &Expr, model: &SemanticModel) -> Resolution { match expr { Expr::Constant(_) | Expr::Tuple(_) diff --git a/crates/ruff/src/rules/pep8_naming/helpers.rs b/crates/ruff/src/rules/pep8_naming/helpers.rs index 11e96981ca5a2..72efccade2a8e 100644 --- a/crates/ruff/src/rules/pep8_naming/helpers.rs +++ b/crates/ruff/src/rules/pep8_naming/helpers.rs @@ -4,11 +4,11 @@ use rustpython_parser::ast::{self, Expr, Stmt}; use ruff_python_semantic::model::SemanticModel; use ruff_python_stdlib::str::{is_lower, is_upper}; -pub(crate) fn is_camelcase(name: &str) -> bool { +pub(super) fn is_camelcase(name: &str) -> bool { !is_lower(name) && !is_upper(name) && !name.contains('_') } -pub(crate) fn is_mixed_case(name: &str) -> bool { +pub(super) fn is_mixed_case(name: &str) -> bool { !is_lower(name) && name .strip_prefix('_') @@ -18,11 +18,11 @@ pub(crate) fn is_mixed_case(name: &str) -> bool { .map_or_else(|| false, char::is_lowercase) } -pub(crate) fn is_acronym(name: &str, asname: &str) -> bool { +pub(super) fn is_acronym(name: &str, asname: &str) -> bool { name.chars().filter(|c| c.is_uppercase()).join("") == asname } -pub(crate) fn is_named_tuple_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { +pub(super) fn is_named_tuple_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { let Stmt::Assign(ast::StmtAssign { value, .. }) = stmt else { return false; }; @@ -37,7 +37,7 @@ pub(crate) fn is_named_tuple_assignment(model: &SemanticModel, stmt: &Stmt) -> b }) } -pub(crate) fn is_typed_dict_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { +pub(super) fn is_typed_dict_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { let Stmt::Assign(ast::StmtAssign { value, .. }) = stmt else { return false; }; @@ -49,7 +49,7 @@ pub(crate) fn is_typed_dict_assignment(model: &SemanticModel, stmt: &Stmt) -> bo }) } -pub(crate) fn is_type_var_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { +pub(super) fn is_type_var_assignment(model: &SemanticModel, stmt: &Stmt) -> bool { let Stmt::Assign(ast::StmtAssign { value, .. }) = stmt else { return false; }; @@ -62,7 +62,7 @@ pub(crate) fn is_type_var_assignment(model: &SemanticModel, stmt: &Stmt) -> bool }) } -pub(crate) fn is_typed_dict_class(model: &SemanticModel, bases: &[Expr]) -> bool { +pub(super) fn is_typed_dict_class(model: &SemanticModel, bases: &[Expr]) -> bool { bases .iter() .any(|base| model.match_typing_expr(base, "TypedDict")) diff --git a/crates/ruff/src/rules/pydocstyle/helpers.rs b/crates/ruff/src/rules/pydocstyle/helpers.rs index a6f8ef6cb9473..774fd1ff57e35 100644 --- a/crates/ruff/src/rules/pydocstyle/helpers.rs +++ b/crates/ruff/src/rules/pydocstyle/helpers.rs @@ -9,7 +9,7 @@ use ruff_python_semantic::model::SemanticModel; use ruff_python_whitespace::UniversalNewlines; /// Return the index of the first logical line in a string. -pub(crate) fn logical_line(content: &str) -> Option { +pub(super) fn logical_line(content: &str) -> Option { // Find the first logical line. let mut logical_line = None; for (i, line) in content.universal_newlines().enumerate() { @@ -28,12 +28,17 @@ pub(crate) fn logical_line(content: &str) -> Option { /// Normalize a word by removing all non-alphanumeric characters /// and converting it to lowercase. -pub(crate) fn normalize_word(first_word: &str) -> String { +pub(super) fn normalize_word(first_word: &str) -> String { first_word .replace(|c: char| !c.is_alphanumeric(), "") .to_lowercase() } +/// Return true if a line ends with an odd number of backslashes (i.e., ends with an escape). +pub(super) fn ends_with_backslash(line: &str) -> bool { + line.chars().rev().take_while(|c| *c == '\\').count() % 2 == 1 +} + /// Check decorator list to see if function should be ignored. pub(crate) fn should_ignore_definition( model: &SemanticModel, @@ -64,11 +69,6 @@ pub(crate) fn should_ignore_definition( false } -/// Return true if a line ends with an odd number of backslashes (i.e., ends with an escape). -pub(crate) fn ends_with_backslash(line: &str) -> bool { - line.chars().rev().take_while(|c| *c == '\\').count() % 2 == 1 -} - /// Check if a docstring should be ignored. pub(crate) fn should_ignore_docstring(contents: &str) -> bool { // Avoid analyzing docstrings that contain implicit string concatenations. diff --git a/crates/ruff/src/rules/pylint/helpers.rs b/crates/ruff/src/rules/pylint/helpers.rs index d7d6c95b45af6..306737b28c54e 100644 --- a/crates/ruff/src/rules/pylint/helpers.rs +++ b/crates/ruff/src/rules/pylint/helpers.rs @@ -8,7 +8,7 @@ use std::fmt; use crate::settings::Settings; -pub(crate) fn in_dunder_init(model: &SemanticModel, settings: &Settings) -> bool { +pub(super) fn in_dunder_init(model: &SemanticModel, settings: &Settings) -> bool { let scope = model.scope(); let ( ScopeKind::Function(ast::StmtFunctionDef { @@ -49,7 +49,7 @@ pub(crate) fn in_dunder_init(model: &SemanticModel, settings: &Settings) -> bool /// A wrapper around [`Cmpop`] that implements `Display`. #[derive(Debug)] -pub(crate) struct CmpopExt(Cmpop); +pub(super) struct CmpopExt(Cmpop); impl From<&Cmpop> for CmpopExt { fn from(cmpop: &Cmpop) -> Self { diff --git a/crates/ruff/src/rules/pyupgrade/helpers.rs b/crates/ruff/src/rules/pyupgrade/helpers.rs index b035b2b1e6496..5a4294590d848 100644 --- a/crates/ruff/src/rules/pyupgrade/helpers.rs +++ b/crates/ruff/src/rules/pyupgrade/helpers.rs @@ -3,7 +3,7 @@ use regex::{Captures, Regex}; static CURLY_BRACES: Lazy = Lazy::new(|| Regex::new(r"(\\N\{[^}]+})|([{}])").unwrap()); -pub(crate) fn curly_escape(text: &str) -> String { +pub(super) fn curly_escape(text: &str) -> String { // Match all curly braces. This will include named unicode escapes (like // \N{SNOWMAN}), which we _don't_ want to escape, so take care to preserve them. CURLY_BRACES diff --git a/crates/ruff/src/rules/tryceratops/helpers.rs b/crates/ruff/src/rules/tryceratops/helpers.rs index 3517f33e2b976..e7067a9eee5d2 100644 --- a/crates/ruff/src/rules/tryceratops/helpers.rs +++ b/crates/ruff/src/rules/tryceratops/helpers.rs @@ -6,13 +6,13 @@ use ruff_python_semantic::analyze::logging; use ruff_python_semantic::model::SemanticModel; /// Collect `logging`-like calls from an AST. -pub(crate) struct LoggerCandidateVisitor<'a, 'b> { +pub(super) struct LoggerCandidateVisitor<'a, 'b> { semantic_model: &'a SemanticModel<'b>, - pub(crate) calls: Vec<&'b ast::ExprCall>, + pub(super) calls: Vec<&'b ast::ExprCall>, } impl<'a, 'b> LoggerCandidateVisitor<'a, 'b> { - pub(crate) fn new(semantic_model: &'a SemanticModel<'b>) -> Self { + pub(super) fn new(semantic_model: &'a SemanticModel<'b>) -> Self { LoggerCandidateVisitor { semantic_model, calls: Vec::new(),