mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Disallow unreachable_pub
(#4314)
This commit is contained in:
parent
97802e7466
commit
c10a4535b9
444 changed files with 1376 additions and 1106 deletions
|
@ -33,4 +33,5 @@ rustflags = [
|
|||
"-Wclippy::rc_buffer",
|
||||
"-Wclippy::rc_mutex",
|
||||
"-Wclippy::rest_pat_in_fully_bound_structs",
|
||||
"-Wunreachable_pub"
|
||||
]
|
||||
|
|
|
@ -168,7 +168,7 @@ fn is_end_of_file(stmt: &Stmt, locator: &Locator) -> bool {
|
|||
/// remove the entire start and end lines.
|
||||
/// - If the `Stmt` is the last statement in its parent body, replace it with a
|
||||
/// `pass` instead.
|
||||
pub fn delete_stmt(
|
||||
pub(crate) fn delete_stmt(
|
||||
stmt: &Stmt,
|
||||
parent: Option<&Stmt>,
|
||||
deleted: &[&Stmt],
|
||||
|
@ -205,7 +205,7 @@ pub fn delete_stmt(
|
|||
}
|
||||
|
||||
/// Generate a `Fix` to remove any unused imports from an `import` statement.
|
||||
pub fn remove_unused_imports<'a>(
|
||||
pub(crate) fn remove_unused_imports<'a>(
|
||||
unused_imports: impl Iterator<Item = &'a str>,
|
||||
stmt: &Stmt,
|
||||
parent: Option<&Stmt>,
|
||||
|
@ -330,7 +330,7 @@ pub fn remove_unused_imports<'a>(
|
|||
///
|
||||
/// Supports the removal of parentheses when this is the only (kw)arg left.
|
||||
/// For this behavior, set `remove_parentheses` to `true`.
|
||||
pub fn remove_argument(
|
||||
pub(crate) fn remove_argument(
|
||||
locator: &Locator,
|
||||
call_at: TextSize,
|
||||
expr_range: TextRange,
|
||||
|
@ -434,7 +434,7 @@ pub fn remove_argument(
|
|||
/// name on which the `lru_cache` symbol would be made available (`"functools.lru_cache"`).
|
||||
///
|
||||
/// Attempts to reuse existing imports when possible.
|
||||
pub fn get_or_import_symbol(
|
||||
pub(crate) fn get_or_import_symbol(
|
||||
module: &str,
|
||||
member: &str,
|
||||
at: TextSize,
|
||||
|
|
|
@ -10,10 +10,13 @@ use ruff_python_ast::source_code::Locator;
|
|||
use crate::linter::FixTable;
|
||||
use crate::registry::{AsRule, Rule};
|
||||
|
||||
pub mod actions;
|
||||
pub(crate) mod actions;
|
||||
|
||||
/// Auto-fix errors in a file, and write the fixed source code to disk.
|
||||
pub fn fix_file(diagnostics: &[Diagnostic], locator: &Locator) -> Option<(String, FixTable)> {
|
||||
pub(crate) fn fix_file(
|
||||
diagnostics: &[Diagnostic],
|
||||
locator: &Locator,
|
||||
) -> Option<(String, FixTable)> {
|
||||
let mut with_fixes = diagnostics
|
||||
.iter()
|
||||
.filter(|diag| diag.fix.is_some())
|
||||
|
|
|
@ -7,11 +7,11 @@ use ruff_python_semantic::context::Snapshot;
|
|||
/// Used to, e.g., store functions, whose bodies shouldn't be analyzed until all
|
||||
/// module-level definitions have been analyzed.
|
||||
#[derive(Default)]
|
||||
pub struct Deferred<'a> {
|
||||
pub string_type_definitions: Vec<(TextRange, &'a str, Snapshot)>,
|
||||
pub type_definitions: Vec<(&'a Expr, Snapshot)>,
|
||||
pub functions: Vec<Snapshot>,
|
||||
pub lambdas: Vec<(&'a Expr, Snapshot)>,
|
||||
pub for_loops: Vec<Snapshot>,
|
||||
pub assignments: Vec<Snapshot>,
|
||||
pub(crate) struct Deferred<'a> {
|
||||
pub(crate) string_type_definitions: Vec<(TextRange, &'a str, Snapshot)>,
|
||||
pub(crate) type_definitions: Vec<(&'a Expr, Snapshot)>,
|
||||
pub(crate) functions: Vec<Snapshot>,
|
||||
pub(crate) lambdas: Vec<(&'a Expr, Snapshot)>,
|
||||
pub(crate) for_loops: Vec<Snapshot>,
|
||||
pub(crate) assignments: Vec<Snapshot>,
|
||||
}
|
||||
|
|
|
@ -5628,7 +5628,7 @@ impl<'a> Checker<'a> {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn check_ast(
|
||||
pub(crate) fn check_ast(
|
||||
python_ast: &Suite,
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::rules::flake8_no_pep420::rules::implicit_namespace_package;
|
|||
use crate::rules::pep8_naming::rules::invalid_module_name;
|
||||
use crate::settings::Settings;
|
||||
|
||||
pub fn check_file_path(
|
||||
pub(crate) fn check_file_path(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &Settings,
|
||||
|
|
|
@ -73,7 +73,7 @@ fn extract_import_map(path: &Path, package: Option<&Path>, blocks: &[&Block]) ->
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn check_imports(
|
||||
pub(crate) fn check_imports(
|
||||
python_ast: &Suite,
|
||||
locator: &Locator,
|
||||
indexer: &Indexer,
|
||||
|
|
|
@ -30,7 +30,7 @@ fn expand_indent(line: &str) -> usize {
|
|||
indent
|
||||
}
|
||||
|
||||
pub fn check_logical_lines(
|
||||
pub(crate) fn check_logical_lines(
|
||||
tokens: &[LexResult],
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
|
@ -136,7 +136,7 @@ impl<'a> LogicalLinesContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn push<K: Into<DiagnosticKind>>(&mut self, kind: K, range: TextRange) {
|
||||
pub(crate) fn push<K: Into<DiagnosticKind>>(&mut self, kind: K, range: TextRange) {
|
||||
let kind = kind.into();
|
||||
if self.settings.rules.enabled(kind.rule()) {
|
||||
self.diagnostics.push(Diagnostic {
|
||||
|
@ -148,7 +148,7 @@ impl<'a> LogicalLinesContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn push_diagnostic(&mut self, diagnostic: Diagnostic) {
|
||||
pub(crate) fn push_diagnostic(&mut self, diagnostic: Diagnostic) {
|
||||
if self.settings.rules.enabled(diagnostic.kind.rule()) {
|
||||
self.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
pub mod ast;
|
||||
pub mod filesystem;
|
||||
pub mod imports;
|
||||
pub(crate) mod ast;
|
||||
pub(crate) mod filesystem;
|
||||
pub(crate) mod imports;
|
||||
#[cfg(feature = "logical_lines")]
|
||||
pub(crate) mod logical_lines;
|
||||
pub mod noqa;
|
||||
pub mod physical_lines;
|
||||
pub mod tokens;
|
||||
pub(crate) mod noqa;
|
||||
pub(crate) mod physical_lines;
|
||||
pub(crate) mod tokens;
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::rule_redirects::get_redirect_target;
|
|||
use crate::rules::ruff::rules::{UnusedCodes, UnusedNOQA};
|
||||
use crate::settings::Settings;
|
||||
|
||||
pub fn check_noqa(
|
||||
pub(crate) fn check_noqa(
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
locator: &Locator,
|
||||
comment_ranges: &[TextRange],
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::rules::pylint;
|
|||
use crate::rules::pyupgrade::rules::unnecessary_coding_comment;
|
||||
use crate::settings::Settings;
|
||||
|
||||
pub fn check_physical_lines(
|
||||
pub(crate) fn check_physical_lines(
|
||||
path: &Path,
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::settings::Settings;
|
|||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
pub fn check_tokens(
|
||||
pub(crate) fn check_tokens(
|
||||
locator: &Locator,
|
||||
tokens: &[LexResult],
|
||||
settings: &Settings,
|
||||
|
|
|
@ -16,7 +16,7 @@ fn compose_call_path_inner<'a>(expr: &'a Expression, parts: &mut Vec<&'a str>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compose_call_path(expr: &Expression) -> Option<String> {
|
||||
pub(crate) fn compose_call_path(expr: &Expression) -> Option<String> {
|
||||
let mut segments = vec![];
|
||||
compose_call_path_inner(expr, &mut segments);
|
||||
if segments.is_empty() {
|
||||
|
@ -26,7 +26,7 @@ pub fn compose_call_path(expr: &Expression) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compose_module_path(module: &NameOrAttribute) -> String {
|
||||
pub(crate) fn compose_module_path(module: &NameOrAttribute) -> String {
|
||||
match module {
|
||||
NameOrAttribute::N(name) => name.value.to_string(),
|
||||
NameOrAttribute::A(attr) => {
|
||||
|
|
|
@ -4,21 +4,21 @@ use libcst_native::{
|
|||
ImportNames, Module, SimpleString, SmallStatement, Statement,
|
||||
};
|
||||
|
||||
pub fn match_module(module_text: &str) -> Result<Module> {
|
||||
pub(crate) fn match_module(module_text: &str) -> Result<Module> {
|
||||
match libcst_native::parse_module(module_text, None) {
|
||||
Ok(module) => Ok(module),
|
||||
Err(_) => bail!("Failed to extract CST from source"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn match_expression(expression_text: &str) -> Result<Expression> {
|
||||
pub(crate) fn match_expression(expression_text: &str) -> Result<Expression> {
|
||||
match libcst_native::parse_expression(expression_text) {
|
||||
Ok(expression) => Ok(expression),
|
||||
Err(_) => bail!("Failed to extract CST from source"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn match_expr<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Expr<'b>> {
|
||||
pub(crate) fn match_expr<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Expr<'b>> {
|
||||
if let Some(Statement::Simple(expr)) = module.body.first_mut() {
|
||||
if let Some(SmallStatement::Expr(expr)) = expr.body.first_mut() {
|
||||
Ok(expr)
|
||||
|
@ -30,7 +30,7 @@ pub fn match_expr<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Expr<'b>
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_import<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Import<'b>> {
|
||||
pub(crate) fn match_import<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Import<'b>> {
|
||||
if let Some(Statement::Simple(expr)) = module.body.first_mut() {
|
||||
if let Some(SmallStatement::Import(expr)) = expr.body.first_mut() {
|
||||
Ok(expr)
|
||||
|
@ -42,7 +42,9 @@ pub fn match_import<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut Import
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_import_from<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut ImportFrom<'b>> {
|
||||
pub(crate) fn match_import_from<'a, 'b>(
|
||||
module: &'a mut Module<'b>,
|
||||
) -> Result<&'a mut ImportFrom<'b>> {
|
||||
if let Some(Statement::Simple(expr)) = module.body.first_mut() {
|
||||
if let Some(SmallStatement::ImportFrom(expr)) = expr.body.first_mut() {
|
||||
Ok(expr)
|
||||
|
@ -54,7 +56,7 @@ pub fn match_import_from<'a, 'b>(module: &'a mut Module<'b>) -> Result<&'a mut I
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_aliases<'a, 'b>(
|
||||
pub(crate) fn match_aliases<'a, 'b>(
|
||||
import_from: &'a mut ImportFrom<'b>,
|
||||
) -> Result<&'a mut Vec<ImportAlias<'b>>> {
|
||||
if let ImportNames::Aliases(aliases) = &mut import_from.names {
|
||||
|
@ -64,7 +66,7 @@ pub fn match_aliases<'a, 'b>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_call<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut Call<'b>> {
|
||||
pub(crate) fn match_call<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut Call<'b>> {
|
||||
if let Expression::Call(call) = expression {
|
||||
Ok(call)
|
||||
} else {
|
||||
|
@ -72,7 +74,7 @@ pub fn match_call<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_comparison<'a, 'b>(
|
||||
pub(crate) fn match_comparison<'a, 'b>(
|
||||
expression: &'a mut Expression<'b>,
|
||||
) -> Result<&'a mut Comparison<'b>> {
|
||||
if let Expression::Comparison(comparison) = expression {
|
||||
|
@ -82,7 +84,7 @@ pub fn match_comparison<'a, 'b>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_dict<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut Dict<'b>> {
|
||||
pub(crate) fn match_dict<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut Dict<'b>> {
|
||||
if let Expression::Dict(dict) = expression {
|
||||
Ok(dict)
|
||||
} else {
|
||||
|
@ -90,7 +92,7 @@ pub fn match_dict<'a, 'b>(expression: &'a mut Expression<'b>) -> Result<&'a mut
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_attribute<'a, 'b>(
|
||||
pub(crate) fn match_attribute<'a, 'b>(
|
||||
expression: &'a mut Expression<'b>,
|
||||
) -> Result<&'a mut Attribute<'b>> {
|
||||
if let Expression::Attribute(attribute) = expression {
|
||||
|
@ -100,7 +102,7 @@ pub fn match_attribute<'a, 'b>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn match_simple_string<'a, 'b>(
|
||||
pub(crate) fn match_simple_string<'a, 'b>(
|
||||
expression: &'a mut Expression<'b>,
|
||||
) -> Result<&'a mut SimpleString<'b>> {
|
||||
if let Expression::SimpleString(simple_string) = expression {
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
pub mod helpers;
|
||||
pub mod matchers;
|
||||
pub(crate) mod helpers;
|
||||
pub(crate) mod matchers;
|
||||
|
|
|
@ -13,11 +13,14 @@ use ruff_python_ast::source_code::Locator;
|
|||
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
|
||||
|
||||
/// Extract doc lines (standalone comments) from a token sequence.
|
||||
pub fn doc_lines_from_tokens<'a>(lxr: &'a [LexResult], locator: &'a Locator<'a>) -> DocLines<'a> {
|
||||
pub(crate) fn doc_lines_from_tokens<'a>(
|
||||
lxr: &'a [LexResult],
|
||||
locator: &'a Locator<'a>,
|
||||
) -> DocLines<'a> {
|
||||
DocLines::new(lxr, locator)
|
||||
}
|
||||
|
||||
pub struct DocLines<'a> {
|
||||
pub(crate) struct DocLines<'a> {
|
||||
inner: std::iter::Flatten<core::slice::Iter<'a, LexResult>>,
|
||||
locator: &'a Locator<'a>,
|
||||
prev: TextSize,
|
||||
|
@ -104,7 +107,7 @@ impl<'a> StringLinesVisitor<'a> {
|
|||
}
|
||||
|
||||
/// Extract doc lines (standalone strings) start positions from an AST.
|
||||
pub fn doc_lines_from_ast(python_ast: &Suite, locator: &Locator) -> Vec<TextSize> {
|
||||
pub(crate) fn doc_lines_from_ast(python_ast: &Suite, locator: &Locator) -> Vec<TextSize> {
|
||||
let mut visitor = StringLinesVisitor::new(locator);
|
||||
visitor.visit_body(python_ast);
|
||||
visitor.string_lines
|
||||
|
|
|
@ -6,67 +6,67 @@ use rustpython_parser::ast::Expr;
|
|||
|
||||
use ruff_python_semantic::definition::Definition;
|
||||
|
||||
pub mod extraction;
|
||||
pub mod google;
|
||||
pub mod numpy;
|
||||
pub mod sections;
|
||||
pub mod styles;
|
||||
pub(crate) mod extraction;
|
||||
pub(crate) mod google;
|
||||
pub(crate) mod numpy;
|
||||
pub(crate) mod sections;
|
||||
pub(crate) mod styles;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Docstring<'a> {
|
||||
pub definition: &'a Definition<'a>,
|
||||
pub expr: &'a Expr,
|
||||
pub(crate) struct Docstring<'a> {
|
||||
pub(crate) definition: &'a Definition<'a>,
|
||||
pub(crate) expr: &'a Expr,
|
||||
/// The content of the docstring, including the leading and trailing quotes.
|
||||
pub contents: &'a str,
|
||||
pub(crate) contents: &'a str,
|
||||
|
||||
/// The range of the docstring body (without the quotes). The range is relative to [`Self::contents`].
|
||||
pub body_range: TextRange,
|
||||
pub indentation: &'a str,
|
||||
pub(crate) body_range: TextRange,
|
||||
pub(crate) indentation: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Docstring<'a> {
|
||||
pub fn body(&self) -> DocstringBody {
|
||||
pub(crate) fn body(&self) -> DocstringBody {
|
||||
DocstringBody { docstring: self }
|
||||
}
|
||||
|
||||
pub const fn start(&self) -> TextSize {
|
||||
pub(crate) const fn start(&self) -> TextSize {
|
||||
self.expr.start()
|
||||
}
|
||||
|
||||
pub const fn end(&self) -> TextSize {
|
||||
pub(crate) const fn end(&self) -> TextSize {
|
||||
self.expr.end()
|
||||
}
|
||||
|
||||
pub const fn range(&self) -> TextRange {
|
||||
pub(crate) const fn range(&self) -> TextRange {
|
||||
self.expr.range()
|
||||
}
|
||||
|
||||
pub fn leading_quote(&self) -> &'a str {
|
||||
pub(crate) fn leading_quote(&self) -> &'a str {
|
||||
&self.contents[TextRange::up_to(self.body_range.start())]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct DocstringBody<'a> {
|
||||
pub(crate) struct DocstringBody<'a> {
|
||||
docstring: &'a Docstring<'a>,
|
||||
}
|
||||
|
||||
impl<'a> DocstringBody<'a> {
|
||||
#[inline]
|
||||
pub fn start(self) -> TextSize {
|
||||
pub(crate) fn start(self) -> TextSize {
|
||||
self.range().start()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn end(self) -> TextSize {
|
||||
pub(crate) fn end(self) -> TextSize {
|
||||
self.range().end()
|
||||
}
|
||||
|
||||
pub fn range(self) -> TextRange {
|
||||
pub(crate) fn range(self) -> TextRange {
|
||||
self.docstring.body_range + self.docstring.start()
|
||||
}
|
||||
|
||||
pub fn as_str(self) -> &'a str {
|
||||
pub(crate) fn as_str(self) -> &'a str {
|
||||
&self.docstring.contents[self.docstring.body_range]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ pub(crate) struct SectionContexts<'a> {
|
|||
|
||||
impl<'a> SectionContexts<'a> {
|
||||
/// Extract all `SectionContext` values from a docstring.
|
||||
pub fn from_docstring(docstring: &'a Docstring<'a>, style: SectionStyle) -> Self {
|
||||
pub(crate) fn from_docstring(docstring: &'a Docstring<'a>, style: SectionStyle) -> Self {
|
||||
let contents = docstring.body();
|
||||
|
||||
let mut contexts = Vec::new();
|
||||
|
@ -190,11 +190,11 @@ impl<'a> SectionContexts<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.contexts.len()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> SectionContextsIter {
|
||||
pub(crate) fn iter(&self) -> SectionContextsIter {
|
||||
SectionContextsIter {
|
||||
docstring_body: self.docstring.body(),
|
||||
inner: self.contexts.iter(),
|
||||
|
|
|
@ -13,7 +13,7 @@ static COMMA_SEPARATED_LIST_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").
|
|||
|
||||
/// Parse a comma-separated list of `RuleSelector` values (e.g.,
|
||||
/// "F401,E501").
|
||||
pub fn parse_prefix_codes(value: &str) -> Vec<RuleSelector> {
|
||||
pub(crate) fn parse_prefix_codes(value: &str) -> Vec<RuleSelector> {
|
||||
let mut codes: Vec<RuleSelector> = vec![];
|
||||
for code in COMMA_SEPARATED_LIST_RE.split(value) {
|
||||
let code = code.trim();
|
||||
|
@ -30,7 +30,7 @@ pub fn parse_prefix_codes(value: &str) -> Vec<RuleSelector> {
|
|||
}
|
||||
|
||||
/// Parse a comma-separated list of strings (e.g., "__init__.py,__main__.py").
|
||||
pub fn parse_strings(value: &str) -> Vec<String> {
|
||||
pub(crate) fn parse_strings(value: &str) -> Vec<String> {
|
||||
COMMA_SEPARATED_LIST_RE
|
||||
.split(value)
|
||||
.map(str::trim)
|
||||
|
@ -40,7 +40,7 @@ pub fn parse_strings(value: &str) -> Vec<String> {
|
|||
}
|
||||
|
||||
/// Parse a boolean.
|
||||
pub fn parse_bool(value: &str) -> Result<bool> {
|
||||
pub(crate) fn parse_bool(value: &str) -> Result<bool> {
|
||||
match value.trim() {
|
||||
"true" => Ok(true),
|
||||
"false" => Ok(false),
|
||||
|
@ -138,7 +138,7 @@ fn tokenize_files_to_codes_mapping(value: &str) -> Vec<Token> {
|
|||
|
||||
/// Parse a 'files-to-codes' mapping, mimicking Flake8's internal logic.
|
||||
/// See: <https://github.com/PyCQA/flake8/blob/7dfe99616fc2f07c0017df2ba5fa884158f3ea8a/src/flake8/utils.py#L45>
|
||||
pub fn parse_files_to_codes_mapping(value: &str) -> Result<Vec<PatternPrefixPair>> {
|
||||
pub(crate) fn parse_files_to_codes_mapping(value: &str) -> Result<Vec<PatternPrefixPair>> {
|
||||
if value.trim().is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ pub fn parse_files_to_codes_mapping(value: &str) -> Result<Vec<PatternPrefixPair
|
|||
}
|
||||
|
||||
/// Collect a list of `PatternPrefixPair` structs as a `BTreeMap`.
|
||||
pub fn collect_per_file_ignores(
|
||||
pub(crate) fn collect_per_file_ignores(
|
||||
pairs: Vec<PatternPrefixPair>,
|
||||
) -> FxHashMap<String, Vec<RuleSelector>> {
|
||||
let mut per_file_ignores: FxHashMap<String, Vec<RuleSelector>> = FxHashMap::default();
|
||||
|
|
|
@ -175,7 +175,7 @@ impl From<&Plugin> for Linter {
|
|||
///
|
||||
/// For example, if the user specified a `mypy-init-return` setting, we should
|
||||
/// infer that `flake8-annotations` is active.
|
||||
pub fn infer_plugins_from_options(flake8: &HashMap<String, Option<String>>) -> Vec<Plugin> {
|
||||
pub(crate) fn infer_plugins_from_options(flake8: &HashMap<String, Option<String>>) -> Vec<Plugin> {
|
||||
let mut plugins = BTreeSet::new();
|
||||
for key in flake8.keys() {
|
||||
match key.as_str() {
|
||||
|
@ -292,7 +292,7 @@ pub fn infer_plugins_from_options(flake8: &HashMap<String, Option<String>>) -> V
|
|||
///
|
||||
/// For example, if the user ignores `ANN101`, we should infer that
|
||||
/// `flake8-annotations` is active.
|
||||
pub fn infer_plugins_from_codes(selectors: &HashSet<RuleSelector>) -> Vec<Plugin> {
|
||||
pub(crate) fn infer_plugins_from_codes(selectors: &HashSet<RuleSelector>) -> Vec<Plugin> {
|
||||
// Ignore cases in which we've knowingly changed rule prefixes.
|
||||
[
|
||||
Plugin::Flake82020,
|
||||
|
|
|
@ -25,13 +25,13 @@ enum State {
|
|||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct StateMachine {
|
||||
pub(crate) struct StateMachine {
|
||||
state: State,
|
||||
bracket_count: usize,
|
||||
}
|
||||
|
||||
impl StateMachine {
|
||||
pub fn consume(&mut self, tok: &Tok) -> bool {
|
||||
pub(crate) fn consume(&mut self, tok: &Tok) -> bool {
|
||||
match tok {
|
||||
Tok::NonLogicalNewline
|
||||
| Tok::Newline
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub mod docstring_detection;
|
||||
pub(crate) mod docstring_detection;
|
||||
|
|
|
@ -21,7 +21,7 @@ pub(super) struct Diff<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Diff<'a> {
|
||||
pub fn from_message(message: &'a Message) -> Option<Diff> {
|
||||
pub(crate) fn from_message(message: &'a Message) -> Option<Diff> {
|
||||
message.fix.as_ref().map(|fix| Diff {
|
||||
source_code: &message.file,
|
||||
fix,
|
||||
|
|
|
@ -113,8 +113,8 @@ impl Emitter for TextEmitter {
|
|||
}
|
||||
|
||||
pub(super) struct RuleCodeAndBody<'a> {
|
||||
pub message: &'a Message,
|
||||
pub show_fix_status: bool,
|
||||
pub(crate) message: &'a Message,
|
||||
pub(crate) show_fix_status: bool,
|
||||
}
|
||||
|
||||
impl Display for RuleCodeAndBody<'_> {
|
||||
|
@ -141,7 +141,7 @@ impl Display for RuleCodeAndBody<'_> {
|
|||
}
|
||||
|
||||
pub(super) struct MessageCodeFrame<'a> {
|
||||
pub message: &'a Message,
|
||||
pub(crate) message: &'a Message,
|
||||
}
|
||||
|
||||
impl Display for MessageCodeFrame<'_> {
|
||||
|
|
|
@ -27,7 +27,7 @@ static NOQA_LINE_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||
static SPLIT_COMMA_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").unwrap());
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Directive<'a> {
|
||||
pub(crate) enum Directive<'a> {
|
||||
None,
|
||||
// (leading spaces, noqa_range, trailing_spaces)
|
||||
All(TextSize, TextRange, TextSize),
|
||||
|
@ -36,7 +36,7 @@ pub enum Directive<'a> {
|
|||
}
|
||||
|
||||
/// Extract the noqa `Directive` from a line of Python source code.
|
||||
pub fn extract_noqa_directive<'a>(range: TextRange, locator: &'a Locator) -> Directive<'a> {
|
||||
pub(crate) fn extract_noqa_directive<'a>(range: TextRange, locator: &'a Locator) -> Directive<'a> {
|
||||
let text = &locator.contents()[range];
|
||||
match NOQA_LINE_REGEX.captures(text) {
|
||||
Some(caps) => match (
|
||||
|
@ -123,7 +123,7 @@ fn parse_file_exemption(line: &str) -> ParsedExemption {
|
|||
|
||||
/// Returns `true` if the string list of `codes` includes `code` (or an alias
|
||||
/// thereof).
|
||||
pub fn includes(needle: Rule, haystack: &[&str]) -> bool {
|
||||
pub(crate) fn includes(needle: Rule, haystack: &[&str]) -> bool {
|
||||
let needle = needle.noqa_code();
|
||||
haystack
|
||||
.iter()
|
||||
|
@ -131,7 +131,7 @@ pub fn includes(needle: Rule, haystack: &[&str]) -> bool {
|
|||
}
|
||||
|
||||
/// Returns `true` if the given [`Rule`] is ignored at the specified `lineno`.
|
||||
pub fn rule_is_ignored(
|
||||
pub(crate) fn rule_is_ignored(
|
||||
code: Rule,
|
||||
offset: TextSize,
|
||||
noqa_line_for: &NoqaMapping,
|
||||
|
@ -146,7 +146,7 @@ pub fn rule_is_ignored(
|
|||
}
|
||||
}
|
||||
|
||||
pub enum FileExemption {
|
||||
pub(crate) enum FileExemption {
|
||||
None,
|
||||
All,
|
||||
Codes(Vec<NoqaCode>),
|
||||
|
@ -154,7 +154,7 @@ pub enum FileExemption {
|
|||
|
||||
/// Extract the [`FileExemption`] for a given Python source file, enumerating any rules that are
|
||||
/// globally ignored within the file.
|
||||
pub fn file_exemption(contents: &str, comment_ranges: &[TextRange]) -> FileExemption {
|
||||
pub(crate) fn file_exemption(contents: &str, comment_ranges: &[TextRange]) -> FileExemption {
|
||||
let mut exempt_codes: Vec<NoqaCode> = vec![];
|
||||
|
||||
for range in comment_ranges {
|
||||
|
@ -184,7 +184,7 @@ pub fn file_exemption(contents: &str, comment_ranges: &[TextRange]) -> FileExemp
|
|||
}
|
||||
|
||||
/// Adds noqa comments to suppress all diagnostics of a file.
|
||||
pub fn add_noqa(
|
||||
pub(crate) fn add_noqa(
|
||||
path: &Path,
|
||||
diagnostics: &[Diagnostic],
|
||||
locator: &Locator,
|
||||
|
@ -368,9 +368,9 @@ fn push_codes<I: Display>(str: &mut String, codes: impl Iterator<Item = I>) {
|
|||
#[derive(Debug)]
|
||||
pub(crate) struct NoqaDirectiveLine<'a> {
|
||||
// The range of the text line for which the noqa directive applies.
|
||||
pub range: TextRange,
|
||||
pub directive: Directive<'a>,
|
||||
pub matches: Vec<NoqaCode>,
|
||||
pub(crate) range: TextRange,
|
||||
pub(crate) directive: Directive<'a>,
|
||||
pub(crate) matches: Vec<NoqaCode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -379,7 +379,10 @@ pub(crate) struct NoqaDirectives<'a> {
|
|||
}
|
||||
|
||||
impl<'a> NoqaDirectives<'a> {
|
||||
pub fn from_commented_ranges(comment_ranges: &[TextRange], locator: &'a Locator<'a>) -> Self {
|
||||
pub(crate) fn from_commented_ranges(
|
||||
comment_ranges: &[TextRange],
|
||||
locator: &'a Locator<'a>,
|
||||
) -> Self {
|
||||
let mut directives = Vec::new();
|
||||
|
||||
for comment_range in comment_ranges {
|
||||
|
@ -409,11 +412,11 @@ impl<'a> NoqaDirectives<'a> {
|
|||
Self { inner: directives }
|
||||
}
|
||||
|
||||
pub fn find_line_with_directive(&self, offset: TextSize) -> Option<&NoqaDirectiveLine> {
|
||||
pub(crate) fn find_line_with_directive(&self, offset: TextSize) -> Option<&NoqaDirectiveLine> {
|
||||
self.find_line_index(offset).map(|index| &self.inner[index])
|
||||
}
|
||||
|
||||
pub fn find_line_with_directive_mut(
|
||||
pub(crate) fn find_line_with_directive_mut(
|
||||
&mut self,
|
||||
offset: TextSize,
|
||||
) -> Option<&mut NoqaDirectiveLine<'a>> {
|
||||
|
@ -438,7 +441,7 @@ impl<'a> NoqaDirectives<'a> {
|
|||
.ok()
|
||||
}
|
||||
|
||||
pub fn lines(&self) -> &[NoqaDirectiveLine] {
|
||||
pub(crate) fn lines(&self) -> &[NoqaDirectiveLine] {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static PARTIAL_DICTIONARY_REGEX: Lazy<Regex> =
|
|||
static PRINT_RETURN_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(print|return)\b\s*").unwrap());
|
||||
|
||||
/// Returns `true` if a comment contains Python code.
|
||||
pub fn comment_contains_code(line: &str, task_tags: &[String]) -> bool {
|
||||
pub(crate) fn comment_contains_code(line: &str, task_tags: &[String]) -> bool {
|
||||
let line = if let Some(line) = line.trim().strip_prefix('#') {
|
||||
line.trim_start_matches([' ', '#'])
|
||||
} else {
|
||||
|
|
|
@ -46,7 +46,7 @@ fn is_standalone_comment(line: &str) -> bool {
|
|||
}
|
||||
|
||||
/// ERA001
|
||||
pub fn commented_out_code(
|
||||
pub(crate) fn commented_out_code(
|
||||
locator: &Locator,
|
||||
range: TextRange,
|
||||
settings: &Settings,
|
||||
|
|
|
@ -121,7 +121,7 @@ fn is_sys(checker: &Checker, expr: &Expr, target: &str) -> bool {
|
|||
}
|
||||
|
||||
/// YTT101, YTT102, YTT301, YTT303
|
||||
pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||
pub(crate) fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
||||
if is_sys(checker, value, "version") {
|
||||
match &slice.node {
|
||||
ExprKind::Slice(ast::ExprSlice {
|
||||
|
@ -172,7 +172,7 @@ pub fn subscript(checker: &mut Checker, value: &Expr, slice: &Expr) {
|
|||
}
|
||||
|
||||
/// YTT103, YTT201, YTT203, YTT204, YTT302
|
||||
pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &[Expr]) {
|
||||
pub(crate) fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &[Expr]) {
|
||||
match &left.node {
|
||||
ExprKind::Subscript(ast::ExprSubscript { value, slice, .. })
|
||||
if is_sys(checker, value, "version_info") =>
|
||||
|
@ -285,7 +285,7 @@ pub fn compare(checker: &mut Checker, left: &Expr, ops: &[Cmpop], comparators: &
|
|||
}
|
||||
|
||||
/// YTT202
|
||||
pub fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
|
||||
pub(crate) fn name_or_attribute(checker: &mut Checker, expr: &Expr) {
|
||||
if checker
|
||||
.ctx
|
||||
.resolve_call_path(expr)
|
||||
|
|
|
@ -6,7 +6,11 @@ use ruff_diagnostics::Edit;
|
|||
use ruff_python_ast::source_code::Locator;
|
||||
|
||||
/// ANN204
|
||||
pub fn add_return_annotation(locator: &Locator, stmt: &Stmt, annotation: &str) -> Result<Edit> {
|
||||
pub(crate) fn add_return_annotation(
|
||||
locator: &Locator,
|
||||
stmt: &Stmt,
|
||||
annotation: &str,
|
||||
) -> Result<Edit> {
|
||||
let contents = &locator.contents()[stmt.range()];
|
||||
|
||||
// Find the colon (following the `def` keyword).
|
||||
|
|
|
@ -27,7 +27,7 @@ pub(super) fn match_function_def(stmt: &Stmt) -> (&str, &Arguments, Option<&Expr
|
|||
}
|
||||
|
||||
/// Return the name of the function, if it's overloaded.
|
||||
pub fn overloaded_name(checker: &Checker, definition: &Definition) -> Option<String> {
|
||||
pub(crate) fn overloaded_name(checker: &Checker, definition: &Definition) -> Option<String> {
|
||||
if let Definition::Member(Member {
|
||||
kind: MemberKind::Function | MemberKind::NestedFunction | MemberKind::Method,
|
||||
stmt,
|
||||
|
@ -47,7 +47,11 @@ pub fn overloaded_name(checker: &Checker, definition: &Definition) -> Option<Str
|
|||
|
||||
/// Return `true` if the definition is the implementation for an overloaded
|
||||
/// function.
|
||||
pub fn is_overload_impl(checker: &Checker, definition: &Definition, overloaded_name: &str) -> bool {
|
||||
pub(crate) fn is_overload_impl(
|
||||
checker: &Checker,
|
||||
definition: &Definition,
|
||||
overloaded_name: &str,
|
||||
) -> bool {
|
||||
if let Definition::Member(Member {
|
||||
kind: MemberKind::Function | MemberKind::NestedFunction | MemberKind::Method,
|
||||
stmt,
|
||||
|
|
|
@ -446,7 +446,7 @@ fn check_dynamically_typed<F>(
|
|||
}
|
||||
|
||||
/// Generate flake8-annotation checks for a given `Definition`.
|
||||
pub fn definition(
|
||||
pub(crate) fn definition(
|
||||
checker: &Checker,
|
||||
definition: &Definition,
|
||||
visibility: Visibility,
|
||||
|
|
|
@ -8,7 +8,7 @@ static PASSWORD_CANDIDATE_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||
Regex::new(r"(^|_)(?i)(pas+wo?r?d|pass(phrase)?|pwd|token|secrete?)($|_)").unwrap()
|
||||
});
|
||||
|
||||
pub fn string_literal(expr: &Expr) -> Option<&str> {
|
||||
pub(crate) fn string_literal(expr: &Expr) -> Option<&str> {
|
||||
match &expr.node {
|
||||
ExprKind::Constant(ast::ExprConstant {
|
||||
value: Constant::Str(string),
|
||||
|
@ -18,11 +18,11 @@ pub fn string_literal(expr: &Expr) -> Option<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn matches_password_name(string: &str) -> bool {
|
||||
pub(crate) fn matches_password_name(string: &str) -> bool {
|
||||
PASSWORD_CANDIDATE_REGEX.is_match(string)
|
||||
}
|
||||
|
||||
pub fn is_untyped_exception(type_: Option<&Expr>, checker: &Checker) -> bool {
|
||||
pub(crate) fn is_untyped_exception(type_: Option<&Expr>, checker: &Checker) -> bool {
|
||||
type_.map_or(true, |type_| {
|
||||
if let ExprKind::Tuple(ast::ExprTuple { elts, .. }) = &type_.node {
|
||||
elts.iter().any(|type_| {
|
||||
|
|
|
@ -36,6 +36,6 @@ impl Violation for Assert {
|
|||
}
|
||||
|
||||
/// S101
|
||||
pub fn assert_used(stmt: &Stmt) -> Diagnostic {
|
||||
pub(crate) fn assert_used(stmt: &Stmt) -> Diagnostic {
|
||||
Diagnostic::new(Assert, TextRange::at(stmt.start(), "assert".text_len()))
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn get_int_value(expr: &Expr) -> Option<u16> {
|
|||
}
|
||||
|
||||
/// S103
|
||||
pub fn bad_file_permissions(
|
||||
pub(crate) fn bad_file_permissions(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -14,7 +14,7 @@ impl Violation for ExecBuiltin {
|
|||
}
|
||||
|
||||
/// S102
|
||||
pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Diagnostic> {
|
||||
pub(crate) fn exec_used(expr: &Expr, func: &Expr) -> Option<Diagnostic> {
|
||||
let ExprKind::Name(ast::ExprName { id, .. }) = &func.node else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ impl Violation for HardcodedBindAllInterfaces {
|
|||
}
|
||||
|
||||
/// S104
|
||||
pub fn hardcoded_bind_all_interfaces(value: &str, range: TextRange) -> Option<Diagnostic> {
|
||||
pub(crate) fn hardcoded_bind_all_interfaces(value: &str, range: TextRange) -> Option<Diagnostic> {
|
||||
if value == "0.0.0.0" {
|
||||
Some(Diagnostic::new(HardcodedBindAllInterfaces, range))
|
||||
} else {
|
||||
|
|
|
@ -36,7 +36,7 @@ fn check_password_kwarg(arg: &Arg, default: &Expr) -> Option<Diagnostic> {
|
|||
}
|
||||
|
||||
/// S107
|
||||
pub fn hardcoded_password_default(arguments: &Arguments) -> Vec<Diagnostic> {
|
||||
pub(crate) fn hardcoded_password_default(arguments: &Arguments) -> Vec<Diagnostic> {
|
||||
let mut diagnostics: Vec<Diagnostic> = Vec::new();
|
||||
|
||||
let defaults_start =
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Violation for HardcodedPasswordFuncArg {
|
|||
}
|
||||
|
||||
/// S106
|
||||
pub fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Diagnostic> {
|
||||
pub(crate) fn hardcoded_password_func_arg(keywords: &[Keyword]) -> Vec<Diagnostic> {
|
||||
keywords
|
||||
.iter()
|
||||
.filter_map(|keyword| {
|
||||
|
|
|
@ -46,7 +46,10 @@ fn password_target(target: &Expr) -> Option<&str> {
|
|||
}
|
||||
|
||||
/// S105
|
||||
pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) -> Vec<Diagnostic> {
|
||||
pub(crate) fn compare_to_hardcoded_password_string(
|
||||
left: &Expr,
|
||||
comparators: &[Expr],
|
||||
) -> Vec<Diagnostic> {
|
||||
comparators
|
||||
.iter()
|
||||
.filter_map(|comp| {
|
||||
|
@ -65,7 +68,10 @@ pub fn compare_to_hardcoded_password_string(left: &Expr, comparators: &[Expr]) -
|
|||
}
|
||||
|
||||
/// S105
|
||||
pub fn assign_hardcoded_password_string(value: &Expr, targets: &[Expr]) -> Option<Diagnostic> {
|
||||
pub(crate) fn assign_hardcoded_password_string(
|
||||
value: &Expr,
|
||||
targets: &[Expr],
|
||||
) -> Option<Diagnostic> {
|
||||
if string_literal(value)
|
||||
.filter(|string| !string.is_empty())
|
||||
.is_some()
|
||||
|
|
|
@ -92,7 +92,7 @@ fn unparse_string_format_expression(checker: &mut Checker, expr: &Expr) -> Optio
|
|||
}
|
||||
|
||||
/// S608
|
||||
pub fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) {
|
||||
pub(crate) fn hardcoded_sql_expression(checker: &mut Checker, expr: &Expr) {
|
||||
match unparse_string_format_expression(checker, expr) {
|
||||
Some(string) if matches_sql_statement(&string) => {
|
||||
checker
|
||||
|
|
|
@ -20,7 +20,7 @@ impl Violation for HardcodedTempFile {
|
|||
}
|
||||
|
||||
/// S108
|
||||
pub fn hardcoded_tmp_directory(
|
||||
pub(crate) fn hardcoded_tmp_directory(
|
||||
expr: &Expr,
|
||||
value: &str,
|
||||
prefixes: &[String],
|
||||
|
|
|
@ -42,7 +42,7 @@ enum HashlibCall {
|
|||
}
|
||||
|
||||
/// S324
|
||||
pub fn hashlib_insecure_hash_functions(
|
||||
pub(crate) fn hashlib_insecure_hash_functions(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Violation for Jinja2AutoescapeFalse {
|
|||
}
|
||||
|
||||
/// S701
|
||||
pub fn jinja2_autoescape_false(
|
||||
pub(crate) fn jinja2_autoescape_false(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Violation for LoggingConfigInsecureListen {
|
|||
}
|
||||
|
||||
/// S612
|
||||
pub fn logging_config_insecure_listen(
|
||||
pub(crate) fn logging_config_insecure_listen(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
pub use assert_used::{assert_used, Assert};
|
||||
pub use bad_file_permissions::{bad_file_permissions, BadFilePermissions};
|
||||
pub use exec_used::{exec_used, ExecBuiltin};
|
||||
pub use hardcoded_bind_all_interfaces::{
|
||||
pub(crate) use assert_used::{assert_used, Assert};
|
||||
pub(crate) use bad_file_permissions::{bad_file_permissions, BadFilePermissions};
|
||||
pub(crate) use exec_used::{exec_used, ExecBuiltin};
|
||||
pub(crate) use hardcoded_bind_all_interfaces::{
|
||||
hardcoded_bind_all_interfaces, HardcodedBindAllInterfaces,
|
||||
};
|
||||
pub use hardcoded_password_default::{hardcoded_password_default, HardcodedPasswordDefault};
|
||||
pub use hardcoded_password_func_arg::{hardcoded_password_func_arg, HardcodedPasswordFuncArg};
|
||||
pub use hardcoded_password_string::{
|
||||
pub(crate) use hardcoded_password_default::{hardcoded_password_default, HardcodedPasswordDefault};
|
||||
pub(crate) use hardcoded_password_func_arg::{
|
||||
hardcoded_password_func_arg, HardcodedPasswordFuncArg,
|
||||
};
|
||||
pub(crate) use hardcoded_password_string::{
|
||||
assign_hardcoded_password_string, compare_to_hardcoded_password_string, HardcodedPasswordString,
|
||||
};
|
||||
pub use hardcoded_sql_expression::{hardcoded_sql_expression, HardcodedSQLExpression};
|
||||
pub use hardcoded_tmp_directory::{hardcoded_tmp_directory, HardcodedTempFile};
|
||||
pub use hashlib_insecure_hash_functions::{
|
||||
pub(crate) use hardcoded_sql_expression::{hardcoded_sql_expression, HardcodedSQLExpression};
|
||||
pub(crate) use hardcoded_tmp_directory::{hardcoded_tmp_directory, HardcodedTempFile};
|
||||
pub(crate) use hashlib_insecure_hash_functions::{
|
||||
hashlib_insecure_hash_functions, HashlibInsecureHashFunction,
|
||||
};
|
||||
pub use jinja2_autoescape_false::{jinja2_autoescape_false, Jinja2AutoescapeFalse};
|
||||
pub use logging_config_insecure_listen::{
|
||||
pub(crate) use jinja2_autoescape_false::{jinja2_autoescape_false, Jinja2AutoescapeFalse};
|
||||
pub(crate) use logging_config_insecure_listen::{
|
||||
logging_config_insecure_listen, LoggingConfigInsecureListen,
|
||||
};
|
||||
pub use request_with_no_cert_validation::{
|
||||
pub(crate) use request_with_no_cert_validation::{
|
||||
request_with_no_cert_validation, RequestWithNoCertValidation,
|
||||
};
|
||||
pub use request_without_timeout::{request_without_timeout, RequestWithoutTimeout};
|
||||
pub use shell_injection::{
|
||||
pub(crate) use request_without_timeout::{request_without_timeout, RequestWithoutTimeout};
|
||||
pub(crate) use shell_injection::{
|
||||
shell_injection, CallWithShellEqualsTrue, StartProcessWithAShell, StartProcessWithNoShell,
|
||||
StartProcessWithPartialPath, SubprocessPopenWithShellEqualsTrue,
|
||||
SubprocessWithoutShellEqualsTrue,
|
||||
};
|
||||
pub use snmp_insecure_version::{snmp_insecure_version, SnmpInsecureVersion};
|
||||
pub use snmp_weak_cryptography::{snmp_weak_cryptography, SnmpWeakCryptography};
|
||||
pub use suspicious_function_call::{
|
||||
pub(crate) use snmp_insecure_version::{snmp_insecure_version, SnmpInsecureVersion};
|
||||
pub(crate) use snmp_weak_cryptography::{snmp_weak_cryptography, SnmpWeakCryptography};
|
||||
pub(crate) use suspicious_function_call::{
|
||||
suspicious_function_call, SuspiciousEvalUsage, SuspiciousFTPLibUsage,
|
||||
SuspiciousInsecureCipherModeUsage, SuspiciousInsecureCipherUsage, SuspiciousInsecureHashUsage,
|
||||
SuspiciousMarkSafeUsage, SuspiciousMarshalUsage, SuspiciousMktempUsage,
|
||||
|
@ -39,9 +41,9 @@ pub use suspicious_function_call::{
|
|||
SuspiciousXMLExpatReaderUsage, SuspiciousXMLMiniDOMUsage, SuspiciousXMLPullDOMUsage,
|
||||
SuspiciousXMLSaxUsage,
|
||||
};
|
||||
pub use try_except_continue::{try_except_continue, TryExceptContinue};
|
||||
pub use try_except_pass::{try_except_pass, TryExceptPass};
|
||||
pub use unsafe_yaml_load::{unsafe_yaml_load, UnsafeYAMLLoad};
|
||||
pub(crate) use try_except_continue::{try_except_continue, TryExceptContinue};
|
||||
pub(crate) use try_except_pass::{try_except_pass, TryExceptPass};
|
||||
pub(crate) use unsafe_yaml_load::{unsafe_yaml_load, UnsafeYAMLLoad};
|
||||
|
||||
mod assert_used;
|
||||
mod bad_file_permissions;
|
||||
|
|
|
@ -37,7 +37,7 @@ const HTTPX_METHODS: [&str; 11] = [
|
|||
];
|
||||
|
||||
/// S501
|
||||
pub fn request_with_no_cert_validation(
|
||||
pub(crate) fn request_with_no_cert_validation(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -27,7 +27,7 @@ impl Violation for RequestWithoutTimeout {
|
|||
const HTTP_VERBS: [&str; 7] = ["get", "options", "head", "post", "put", "patch", "delete"];
|
||||
|
||||
/// S113
|
||||
pub fn request_without_timeout(
|
||||
pub(crate) fn request_without_timeout(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -181,7 +181,12 @@ fn try_string_literal(expr: &Expr) -> Option<&str> {
|
|||
}
|
||||
|
||||
/// S602, S603, S604, S605, S606, S607
|
||||
pub fn shell_injection(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: &[Keyword]) {
|
||||
pub(crate) fn shell_injection(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
keywords: &[Keyword],
|
||||
) {
|
||||
let call_kind = get_call_kind(func, &checker.ctx);
|
||||
|
||||
if matches!(call_kind, Some(CallKind::Subprocess)) {
|
||||
|
|
|
@ -18,7 +18,7 @@ impl Violation for SnmpInsecureVersion {
|
|||
}
|
||||
|
||||
/// S508
|
||||
pub fn snmp_insecure_version(
|
||||
pub(crate) fn snmp_insecure_version(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -20,7 +20,7 @@ impl Violation for SnmpWeakCryptography {
|
|||
}
|
||||
|
||||
/// S509
|
||||
pub fn snmp_weak_cryptography(
|
||||
pub(crate) fn snmp_weak_cryptography(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -220,7 +220,7 @@ impl Violation for SuspiciousFTPLibUsage {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Reason {
|
||||
pub(crate) enum Reason {
|
||||
Pickle,
|
||||
Marshal,
|
||||
InsecureHash,
|
||||
|
@ -250,7 +250,7 @@ struct SuspiciousMembers<'a> {
|
|||
}
|
||||
|
||||
impl<'a> SuspiciousMembers<'a> {
|
||||
pub const fn new(members: &'a [&'a [&'a str]], reason: Reason) -> Self {
|
||||
pub(crate) const fn new(members: &'a [&'a [&'a str]], reason: Reason) -> Self {
|
||||
Self { members, reason }
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ struct SuspiciousModule<'a> {
|
|||
}
|
||||
|
||||
impl<'a> SuspiciousModule<'a> {
|
||||
pub const fn new(name: &'a str, reason: Reason) -> Self {
|
||||
pub(crate) const fn new(name: &'a str, reason: Reason) -> Self {
|
||||
Self { name, reason }
|
||||
}
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ const SUSPICIOUS_MODULES: &[SuspiciousModule] = &[
|
|||
];
|
||||
|
||||
/// S001
|
||||
pub fn suspicious_function_call(checker: &mut Checker, expr: &Expr) {
|
||||
pub(crate) fn suspicious_function_call(checker: &mut Checker, expr: &Expr) {
|
||||
let ExprKind::Call(ast::ExprCall { func, .. }) = &expr.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Violation for TryExceptContinue {
|
|||
}
|
||||
|
||||
/// S112
|
||||
pub fn try_except_continue(
|
||||
pub(crate) fn try_except_continue(
|
||||
checker: &mut Checker,
|
||||
excepthandler: &Excepthandler,
|
||||
type_: Option<&Expr>,
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Violation for TryExceptPass {
|
|||
}
|
||||
|
||||
/// S110
|
||||
pub fn try_except_pass(
|
||||
pub(crate) fn try_except_pass(
|
||||
checker: &mut Checker,
|
||||
excepthandler: &Excepthandler,
|
||||
type_: Option<&Expr>,
|
||||
|
|
|
@ -31,7 +31,12 @@ impl Violation for UnsafeYAMLLoad {
|
|||
}
|
||||
|
||||
/// S506
|
||||
pub fn unsafe_yaml_load(checker: &mut Checker, func: &Expr, args: &[Expr], keywords: &[Keyword]) {
|
||||
pub(crate) fn unsafe_yaml_load(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
keywords: &[Keyword],
|
||||
) {
|
||||
if checker
|
||||
.ctx
|
||||
.resolve_call_path(func)
|
||||
|
|
|
@ -21,7 +21,7 @@ impl Violation for BlindExcept {
|
|||
}
|
||||
|
||||
/// BLE001
|
||||
pub fn blind_except(
|
||||
pub(crate) fn blind_except(
|
||||
checker: &mut Checker,
|
||||
type_: Option<&Expr>,
|
||||
name: Option<&str>,
|
||||
|
|
|
@ -98,7 +98,7 @@ fn add_if_boolean(checker: &mut Checker, arg: &Expr, kind: DiagnosticKind) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_positional_boolean_in_def(
|
||||
pub(crate) fn check_positional_boolean_in_def(
|
||||
checker: &mut Checker,
|
||||
name: &str,
|
||||
decorator_list: &[Expr],
|
||||
|
@ -141,7 +141,7 @@ pub fn check_positional_boolean_in_def(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_boolean_default_value_in_function_definition(
|
||||
pub(crate) fn check_boolean_default_value_in_function_definition(
|
||||
checker: &mut Checker,
|
||||
name: &str,
|
||||
decorator_list: &[Expr],
|
||||
|
@ -162,7 +162,7 @@ pub fn check_boolean_default_value_in_function_definition(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_boolean_positional_value_in_function_call(
|
||||
pub(crate) fn check_boolean_positional_value_in_function_call(
|
||||
checker: &mut Checker,
|
||||
args: &[Expr],
|
||||
func: &Expr,
|
||||
|
|
|
@ -69,7 +69,7 @@ fn is_empty_body(body: &[Stmt]) -> bool {
|
|||
|
||||
/// B024
|
||||
/// B027
|
||||
pub fn abstract_base_class(
|
||||
pub(crate) fn abstract_base_class(
|
||||
checker: &mut Checker,
|
||||
stmt: &Stmt,
|
||||
name: &str,
|
||||
|
|
|
@ -50,7 +50,7 @@ fn assertion_error(msg: Option<&Expr>) -> Stmt {
|
|||
}
|
||||
|
||||
/// B011
|
||||
pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option<&Expr>) {
|
||||
pub(crate) fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: Option<&Expr>) {
|
||||
let ExprKind::Constant(ast::ExprConstant {
|
||||
value: Constant::Bool(false),
|
||||
..
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruff_macros::{derive_message_formats, violation};
|
|||
use crate::checkers::ast::Checker;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum AssertionKind {
|
||||
pub(crate) enum AssertionKind {
|
||||
AssertRaises,
|
||||
PytestRaises,
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ impl Violation for AssertRaisesException {
|
|||
}
|
||||
|
||||
/// B017
|
||||
pub fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[Withitem]) {
|
||||
pub(crate) fn assert_raises_exception(checker: &mut Checker, stmt: &Stmt, items: &[Withitem]) {
|
||||
let Some(item) = items.first() else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ impl Violation for AssignmentToOsEnviron {
|
|||
}
|
||||
}
|
||||
/// B003
|
||||
pub fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) {
|
||||
pub(crate) fn assignment_to_os_environ(checker: &mut Checker, targets: &[Expr]) {
|
||||
if targets.len() != 1 {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ fn is_cache_func(checker: &Checker, expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
/// B019
|
||||
pub fn cached_instance_method(checker: &mut Checker, decorator_list: &[Expr]) {
|
||||
pub(crate) fn cached_instance_method(checker: &mut Checker, decorator_list: &[Expr]) {
|
||||
if !matches!(checker.ctx.scope().kind, ScopeKind::Class(_)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ impl Violation for CannotRaiseLiteral {
|
|||
}
|
||||
|
||||
/// B016
|
||||
pub fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) {
|
||||
pub(crate) fn cannot_raise_literal(checker: &mut Checker, expr: &Expr) {
|
||||
let ExprKind::Constant ( _) = &expr.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -112,7 +112,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
seen
|
||||
}
|
||||
|
||||
pub fn duplicate_exceptions(checker: &mut Checker, handlers: &[Excepthandler]) {
|
||||
pub(crate) fn duplicate_exceptions(checker: &mut Checker, handlers: &[Excepthandler]) {
|
||||
let mut seen: FxHashSet<CallPath> = FxHashSet::default();
|
||||
let mut duplicates: FxHashMap<CallPath, Vec<&Expr>> = FxHashMap::default();
|
||||
for handler in handlers {
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Violation for ExceptWithEmptyTuple {
|
|||
}
|
||||
|
||||
/// B029
|
||||
pub fn except_with_empty_tuple(checker: &mut Checker, excepthandler: &Excepthandler) {
|
||||
pub(crate) fn except_with_empty_tuple(checker: &mut Checker, excepthandler: &Excepthandler) {
|
||||
let ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { type_, .. }) =
|
||||
&excepthandler.node;
|
||||
let Some(type_) = type_ else {
|
||||
|
|
|
@ -42,7 +42,10 @@ fn flatten_starred_iterables(expr: &Expr) -> Vec<&Expr> {
|
|||
}
|
||||
|
||||
/// B030
|
||||
pub fn except_with_non_exception_classes(checker: &mut Checker, excepthandler: &Excepthandler) {
|
||||
pub(crate) fn except_with_non_exception_classes(
|
||||
checker: &mut Checker,
|
||||
excepthandler: &Excepthandler,
|
||||
) {
|
||||
let ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { type_, .. }) =
|
||||
&excepthandler.node;
|
||||
let Some(type_) = type_ else {
|
||||
|
|
|
@ -19,7 +19,7 @@ impl Violation for FStringDocstring {
|
|||
}
|
||||
|
||||
/// B021
|
||||
pub fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) {
|
||||
pub(crate) fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) {
|
||||
let Some(stmt) = body.first() else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -129,7 +129,7 @@ fn is_nan_or_infinity(expr: &Expr, args: &[Expr]) -> bool {
|
|||
}
|
||||
|
||||
/// B008
|
||||
pub fn function_call_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||
pub(crate) fn function_call_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||
// Map immutable calls to (module, member) format.
|
||||
let extend_immutable_calls: Vec<CallPath> = checker
|
||||
.settings
|
||||
|
|
|
@ -235,7 +235,7 @@ impl<'a> Visitor<'a> for AssignedNamesVisitor<'a> {
|
|||
}
|
||||
|
||||
/// B023
|
||||
pub fn function_uses_loop_variable<'a>(checker: &mut Checker<'a>, node: &Node<'a>) {
|
||||
pub(crate) fn function_uses_loop_variable<'a>(checker: &mut Checker<'a>, node: &Node<'a>) {
|
||||
// Identify any "suspicious" variables. These are defined as variables that are
|
||||
// referenced in a function or lambda body, but aren't bound as arguments.
|
||||
let suspicious_variables = {
|
||||
|
|
|
@ -37,7 +37,12 @@ fn attribute(value: &Expr, attr: &str) -> Expr {
|
|||
}
|
||||
|
||||
/// B009
|
||||
pub fn getattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
||||
pub(crate) fn getattr_with_constant(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
) {
|
||||
let ExprKind::Name(ast::ExprName { id, .. } )= &func.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -62,7 +62,7 @@ fn walk_stmt(checker: &mut Checker, body: &[Stmt], f: fn(&Stmt) -> bool) {
|
|||
}
|
||||
|
||||
/// B012
|
||||
pub fn jump_statement_in_finally(checker: &mut Checker, finalbody: &[Stmt]) {
|
||||
pub(crate) fn jump_statement_in_finally(checker: &mut Checker, finalbody: &[Stmt]) {
|
||||
walk_stmt(checker, finalbody, |stmt| {
|
||||
matches!(
|
||||
stmt.node,
|
||||
|
|
|
@ -55,7 +55,7 @@ where
|
|||
}
|
||||
|
||||
/// B020
|
||||
pub fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, iter: &Expr) {
|
||||
pub(crate) fn loop_variable_overrides_iterator(checker: &mut Checker, target: &Expr, iter: &Expr) {
|
||||
let target_names = {
|
||||
let mut target_finder = NameFinder::default();
|
||||
target_finder.visit_expr(target);
|
||||
|
|
|
@ -1,53 +1,63 @@
|
|||
pub use abstract_base_class::{
|
||||
pub(crate) use abstract_base_class::{
|
||||
abstract_base_class, AbstractBaseClassWithoutAbstractMethod,
|
||||
EmptyMethodWithoutAbstractDecorator,
|
||||
};
|
||||
pub use assert_false::{assert_false, AssertFalse};
|
||||
pub use assert_raises_exception::{assert_raises_exception, AssertRaisesException};
|
||||
pub use assignment_to_os_environ::{assignment_to_os_environ, AssignmentToOsEnviron};
|
||||
pub use cached_instance_method::{cached_instance_method, CachedInstanceMethod};
|
||||
pub use cannot_raise_literal::{cannot_raise_literal, CannotRaiseLiteral};
|
||||
pub use duplicate_exceptions::{
|
||||
pub(crate) use assert_false::{assert_false, AssertFalse};
|
||||
pub(crate) use assert_raises_exception::{assert_raises_exception, AssertRaisesException};
|
||||
pub(crate) use assignment_to_os_environ::{assignment_to_os_environ, AssignmentToOsEnviron};
|
||||
pub(crate) use cached_instance_method::{cached_instance_method, CachedInstanceMethod};
|
||||
pub(crate) use cannot_raise_literal::{cannot_raise_literal, CannotRaiseLiteral};
|
||||
pub(crate) use duplicate_exceptions::{
|
||||
duplicate_exceptions, DuplicateHandlerException, DuplicateTryBlockException,
|
||||
};
|
||||
pub use except_with_empty_tuple::{except_with_empty_tuple, ExceptWithEmptyTuple};
|
||||
pub use except_with_non_exception_classes::{
|
||||
pub(crate) use except_with_empty_tuple::{except_with_empty_tuple, ExceptWithEmptyTuple};
|
||||
pub(crate) use except_with_non_exception_classes::{
|
||||
except_with_non_exception_classes, ExceptWithNonExceptionClasses,
|
||||
};
|
||||
pub use f_string_docstring::{f_string_docstring, FStringDocstring};
|
||||
pub use function_call_argument_default::{
|
||||
pub(crate) use f_string_docstring::{f_string_docstring, FStringDocstring};
|
||||
pub(crate) use function_call_argument_default::{
|
||||
function_call_argument_default, FunctionCallInDefaultArgument,
|
||||
};
|
||||
pub use function_uses_loop_variable::{function_uses_loop_variable, FunctionUsesLoopVariable};
|
||||
pub use getattr_with_constant::{getattr_with_constant, GetAttrWithConstant};
|
||||
pub use jump_statement_in_finally::{jump_statement_in_finally, JumpStatementInFinally};
|
||||
pub use loop_variable_overrides_iterator::{
|
||||
pub(crate) use function_uses_loop_variable::{
|
||||
function_uses_loop_variable, FunctionUsesLoopVariable,
|
||||
};
|
||||
pub(crate) use getattr_with_constant::{getattr_with_constant, GetAttrWithConstant};
|
||||
pub(crate) use jump_statement_in_finally::{jump_statement_in_finally, JumpStatementInFinally};
|
||||
pub(crate) use loop_variable_overrides_iterator::{
|
||||
loop_variable_overrides_iterator, LoopVariableOverridesIterator,
|
||||
};
|
||||
pub use mutable_argument_default::{mutable_argument_default, MutableArgumentDefault};
|
||||
pub use no_explicit_stacklevel::{no_explicit_stacklevel, NoExplicitStacklevel};
|
||||
pub use raise_without_from_inside_except::{
|
||||
pub(crate) use mutable_argument_default::{mutable_argument_default, MutableArgumentDefault};
|
||||
pub(crate) use no_explicit_stacklevel::{no_explicit_stacklevel, NoExplicitStacklevel};
|
||||
pub(crate) use raise_without_from_inside_except::{
|
||||
raise_without_from_inside_except, RaiseWithoutFromInsideExcept,
|
||||
};
|
||||
pub use redundant_tuple_in_exception_handler::{
|
||||
pub(crate) use redundant_tuple_in_exception_handler::{
|
||||
redundant_tuple_in_exception_handler, RedundantTupleInExceptionHandler,
|
||||
};
|
||||
pub use reuse_of_groupby_generator::{reuse_of_groupby_generator, ReuseOfGroupbyGenerator};
|
||||
pub use setattr_with_constant::{setattr_with_constant, SetAttrWithConstant};
|
||||
pub use star_arg_unpacking_after_keyword_arg::{
|
||||
pub(crate) use reuse_of_groupby_generator::{reuse_of_groupby_generator, ReuseOfGroupbyGenerator};
|
||||
pub(crate) use setattr_with_constant::{setattr_with_constant, SetAttrWithConstant};
|
||||
pub(crate) use star_arg_unpacking_after_keyword_arg::{
|
||||
star_arg_unpacking_after_keyword_arg, StarArgUnpackingAfterKeywordArg,
|
||||
};
|
||||
pub use strip_with_multi_characters::{strip_with_multi_characters, StripWithMultiCharacters};
|
||||
pub use unary_prefix_increment::{unary_prefix_increment, UnaryPrefixIncrement};
|
||||
pub use unintentional_type_annotation::{
|
||||
pub(crate) use strip_with_multi_characters::{
|
||||
strip_with_multi_characters, StripWithMultiCharacters,
|
||||
};
|
||||
pub(crate) use unary_prefix_increment::{unary_prefix_increment, UnaryPrefixIncrement};
|
||||
pub(crate) use unintentional_type_annotation::{
|
||||
unintentional_type_annotation, UnintentionalTypeAnnotation,
|
||||
};
|
||||
pub use unreliable_callable_check::{unreliable_callable_check, UnreliableCallableCheck};
|
||||
pub use unused_loop_control_variable::{unused_loop_control_variable, UnusedLoopControlVariable};
|
||||
pub use useless_comparison::{useless_comparison, UselessComparison};
|
||||
pub use useless_contextlib_suppress::{useless_contextlib_suppress, UselessContextlibSuppress};
|
||||
pub use useless_expression::{useless_expression, UselessExpression};
|
||||
pub use zip_without_explicit_strict::{zip_without_explicit_strict, ZipWithoutExplicitStrict};
|
||||
pub(crate) use unreliable_callable_check::{unreliable_callable_check, UnreliableCallableCheck};
|
||||
pub(crate) use unused_loop_control_variable::{
|
||||
unused_loop_control_variable, UnusedLoopControlVariable,
|
||||
};
|
||||
pub(crate) use useless_comparison::{useless_comparison, UselessComparison};
|
||||
pub(crate) use useless_contextlib_suppress::{
|
||||
useless_contextlib_suppress, UselessContextlibSuppress,
|
||||
};
|
||||
pub(crate) use useless_expression::{useless_expression, UselessExpression};
|
||||
pub(crate) use zip_without_explicit_strict::{
|
||||
zip_without_explicit_strict, ZipWithoutExplicitStrict,
|
||||
};
|
||||
|
||||
mod abstract_base_class;
|
||||
mod assert_false;
|
||||
|
|
|
@ -25,7 +25,7 @@ const MUTABLE_FUNCS: &[&[&str]] = &[
|
|||
&["collections", "deque"],
|
||||
];
|
||||
|
||||
pub fn is_mutable_func(checker: &Checker, func: &Expr) -> bool {
|
||||
pub(crate) fn is_mutable_func(checker: &Checker, func: &Expr) -> bool {
|
||||
checker
|
||||
.ctx
|
||||
.resolve_call_path(func)
|
||||
|
@ -50,7 +50,7 @@ fn is_mutable_expr(checker: &Checker, expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
/// B006
|
||||
pub fn mutable_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||
pub(crate) fn mutable_argument_default(checker: &mut Checker, arguments: &Arguments) {
|
||||
// Scan in reverse order to right-align zip().
|
||||
for (arg, default) in arguments
|
||||
.kwonlyargs
|
||||
|
|
|
@ -38,7 +38,7 @@ impl Violation for NoExplicitStacklevel {
|
|||
}
|
||||
|
||||
/// B028
|
||||
pub fn no_explicit_stacklevel(
|
||||
pub(crate) fn no_explicit_stacklevel(
|
||||
checker: &mut Checker,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Violation for RaiseWithoutFromInsideExcept {
|
|||
}
|
||||
|
||||
/// B904
|
||||
pub fn raise_without_from_inside_except(checker: &mut Checker, body: &[Stmt]) {
|
||||
pub(crate) fn raise_without_from_inside_except(checker: &mut Checker, body: &[Stmt]) {
|
||||
let raises = {
|
||||
let mut visitor = RaiseStatementVisitor::default();
|
||||
visitor.visit_body(body);
|
||||
|
|
|
@ -29,7 +29,10 @@ impl AlwaysAutofixableViolation for RedundantTupleInExceptionHandler {
|
|||
}
|
||||
|
||||
/// B013
|
||||
pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[Excepthandler]) {
|
||||
pub(crate) fn redundant_tuple_in_exception_handler(
|
||||
checker: &mut Checker,
|
||||
handlers: &[Excepthandler],
|
||||
) {
|
||||
for handler in handlers {
|
||||
let ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { type_: Some(type_), .. }) = &handler.node else {
|
||||
continue;
|
||||
|
|
|
@ -302,7 +302,7 @@ where
|
|||
}
|
||||
|
||||
/// B031
|
||||
pub fn reuse_of_groupby_generator(
|
||||
pub(crate) fn reuse_of_groupby_generator(
|
||||
checker: &mut Checker,
|
||||
target: &Expr,
|
||||
body: &[Stmt],
|
||||
|
|
|
@ -47,7 +47,12 @@ fn assignment(obj: &Expr, name: &str, value: &Expr, stylist: &Stylist) -> String
|
|||
}
|
||||
|
||||
/// B010
|
||||
pub fn setattr_with_constant(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
||||
pub(crate) fn setattr_with_constant(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
) {
|
||||
let ExprKind::Name(ast::ExprName { id, .. }) = &func.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Violation for StarArgUnpackingAfterKeywordArg {
|
|||
}
|
||||
|
||||
/// B026
|
||||
pub fn star_arg_unpacking_after_keyword_arg(
|
||||
pub(crate) fn star_arg_unpacking_after_keyword_arg(
|
||||
checker: &mut Checker,
|
||||
args: &[Expr],
|
||||
keywords: &[Keyword],
|
||||
|
|
|
@ -17,7 +17,12 @@ impl Violation for StripWithMultiCharacters {
|
|||
}
|
||||
|
||||
/// B005
|
||||
pub fn strip_with_multi_characters(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
||||
pub(crate) fn strip_with_multi_characters(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
) {
|
||||
let ExprKind::Attribute(ast::ExprAttribute { attr, .. }) = &func.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -35,7 +35,12 @@ impl Violation for UnaryPrefixIncrement {
|
|||
}
|
||||
|
||||
/// B002
|
||||
pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop, operand: &Expr) {
|
||||
pub(crate) fn unary_prefix_increment(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
op: &Unaryop,
|
||||
operand: &Expr,
|
||||
) {
|
||||
if !matches!(op, Unaryop::UAdd) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ impl Violation for UnintentionalTypeAnnotation {
|
|||
}
|
||||
|
||||
/// B032
|
||||
pub fn unintentional_type_annotation(
|
||||
pub(crate) fn unintentional_type_annotation(
|
||||
checker: &mut Checker,
|
||||
target: &Expr,
|
||||
value: Option<&Expr>,
|
||||
|
|
|
@ -19,7 +19,12 @@ impl Violation for UnreliableCallableCheck {
|
|||
}
|
||||
|
||||
/// B004
|
||||
pub fn unreliable_callable_check(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
||||
pub(crate) fn unreliable_callable_check(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
) {
|
||||
let ExprKind::Name(ast::ExprName { id, .. }) = &func.node else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -101,7 +101,7 @@ where
|
|||
}
|
||||
|
||||
/// B007
|
||||
pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body: &[Stmt]) {
|
||||
pub(crate) fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body: &[Stmt]) {
|
||||
let control_names = {
|
||||
let mut finder = NameFinder::new();
|
||||
finder.visit_expr(target);
|
||||
|
|
|
@ -19,7 +19,7 @@ impl Violation for UselessComparison {
|
|||
}
|
||||
|
||||
/// B015
|
||||
pub fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
||||
pub(crate) fn useless_comparison(checker: &mut Checker, expr: &Expr) {
|
||||
if matches!(expr.node, ExprKind::Compare(_)) {
|
||||
checker
|
||||
.diagnostics
|
||||
|
|
|
@ -18,7 +18,12 @@ impl Violation for UselessContextlibSuppress {
|
|||
}
|
||||
|
||||
/// B022
|
||||
pub fn useless_contextlib_suppress(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
|
||||
pub(crate) fn useless_contextlib_suppress(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
args: &[Expr],
|
||||
) {
|
||||
if args.is_empty()
|
||||
&& checker
|
||||
.ctx
|
||||
|
|
|
@ -7,7 +7,7 @@ use ruff_python_ast::helpers::contains_effect;
|
|||
use crate::checkers::ast::Checker;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Kind {
|
||||
pub(crate) enum Kind {
|
||||
Expression,
|
||||
Attribute,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ impl Violation for UselessExpression {
|
|||
}
|
||||
|
||||
/// B018
|
||||
pub fn useless_expression(checker: &mut Checker, value: &Expr) {
|
||||
pub(crate) fn useless_expression(checker: &mut Checker, value: &Expr) {
|
||||
// Ignore comparisons, as they're handled by `useless_comparison`.
|
||||
if matches!(value.node, ExprKind::Compare(_)) {
|
||||
return;
|
||||
|
|
|
@ -15,7 +15,7 @@ impl Violation for ZipWithoutExplicitStrict {
|
|||
}
|
||||
|
||||
/// B905
|
||||
pub fn zip_without_explicit_strict(
|
||||
pub(crate) fn zip_without_explicit_strict(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
|
@ -172,7 +172,7 @@ fn shadows_builtin(name: &str, ignorelist: &[String]) -> bool {
|
|||
}
|
||||
|
||||
/// A001
|
||||
pub fn builtin_variable_shadowing<T>(
|
||||
pub(crate) fn builtin_variable_shadowing<T>(
|
||||
checker: &mut Checker,
|
||||
name: &str,
|
||||
attributed: &Attributed<T>,
|
||||
|
@ -188,7 +188,7 @@ pub fn builtin_variable_shadowing<T>(
|
|||
}
|
||||
|
||||
/// A002
|
||||
pub fn builtin_argument_shadowing<T>(
|
||||
pub(crate) fn builtin_argument_shadowing<T>(
|
||||
checker: &mut Checker,
|
||||
name: &str,
|
||||
attributed: &Attributed<T>,
|
||||
|
@ -204,7 +204,7 @@ pub fn builtin_argument_shadowing<T>(
|
|||
}
|
||||
|
||||
/// A003
|
||||
pub fn builtin_attribute_shadowing<T>(
|
||||
pub(crate) fn builtin_attribute_shadowing<T>(
|
||||
checker: &mut Checker,
|
||||
name: &str,
|
||||
attributed: &Attributed<T>,
|
||||
|
|
|
@ -219,7 +219,7 @@ impl AlwaysAutofixableViolation for ProhibitedTrailingComma {
|
|||
}
|
||||
|
||||
/// COM812, COM818, COM819
|
||||
pub fn trailing_commas(
|
||||
pub(crate) fn trailing_commas(
|
||||
tokens: &[LexResult],
|
||||
locator: &Locator,
|
||||
settings: &Settings,
|
||||
|
|
|
@ -30,7 +30,7 @@ fn match_arg<'a, 'b>(call: &'a Call<'b>) -> Result<&'a Arg<'b>> {
|
|||
}
|
||||
|
||||
/// (C400) Convert `list(x for x in y)` to `[x for x in y]`.
|
||||
pub fn fix_unnecessary_generator_list(
|
||||
pub(crate) fn fix_unnecessary_generator_list(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -72,7 +72,7 @@ pub fn fix_unnecessary_generator_list(
|
|||
}
|
||||
|
||||
/// (C401) Convert `set(x for x in y)` to `{x for x in y}`.
|
||||
pub fn fix_unnecessary_generator_set(
|
||||
pub(crate) fn fix_unnecessary_generator_set(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -126,7 +126,7 @@ pub fn fix_unnecessary_generator_set(
|
|||
|
||||
/// (C402) Convert `dict((x, x) for x in range(3))` to `{x: x for x in
|
||||
/// range(3)}`.
|
||||
pub fn fix_unnecessary_generator_dict(
|
||||
pub(crate) fn fix_unnecessary_generator_dict(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -195,7 +195,7 @@ pub fn fix_unnecessary_generator_dict(
|
|||
}
|
||||
|
||||
/// (C403) Convert `set([x for x in y])` to `{x for x in y}`.
|
||||
pub fn fix_unnecessary_list_comprehension_set(
|
||||
pub(crate) fn fix_unnecessary_list_comprehension_set(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -237,7 +237,7 @@ pub fn fix_unnecessary_list_comprehension_set(
|
|||
|
||||
/// (C404) Convert `dict([(i, i) for i in range(3)])` to `{i: i for i in
|
||||
/// range(3)}`.
|
||||
pub fn fix_unnecessary_list_comprehension_dict(
|
||||
pub(crate) fn fix_unnecessary_list_comprehension_dict(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -331,7 +331,7 @@ fn drop_trailing_comma<'a>(
|
|||
}
|
||||
|
||||
/// (C405) Convert `set((1, 2))` to `{1, 2}`.
|
||||
pub fn fix_unnecessary_literal_set(
|
||||
pub(crate) fn fix_unnecessary_literal_set(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -378,7 +378,7 @@ pub fn fix_unnecessary_literal_set(
|
|||
}
|
||||
|
||||
/// (C406) Convert `dict([(1, 2)])` to `{1: 2}`.
|
||||
pub fn fix_unnecessary_literal_dict(
|
||||
pub(crate) fn fix_unnecessary_literal_dict(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -447,7 +447,7 @@ pub fn fix_unnecessary_literal_dict(
|
|||
}
|
||||
|
||||
/// (C408)
|
||||
pub fn fix_unnecessary_collection_call(
|
||||
pub(crate) fn fix_unnecessary_collection_call(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -559,7 +559,7 @@ pub fn fix_unnecessary_collection_call(
|
|||
}
|
||||
|
||||
/// (C409) Convert `tuple([1, 2])` to `tuple(1, 2)`
|
||||
pub fn fix_unnecessary_literal_within_tuple_call(
|
||||
pub(crate) fn fix_unnecessary_literal_within_tuple_call(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -614,7 +614,7 @@ pub fn fix_unnecessary_literal_within_tuple_call(
|
|||
}
|
||||
|
||||
/// (C410) Convert `list([1, 2])` to `[1, 2]`
|
||||
pub fn fix_unnecessary_literal_within_list_call(
|
||||
pub(crate) fn fix_unnecessary_literal_within_list_call(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -671,7 +671,7 @@ pub fn fix_unnecessary_literal_within_list_call(
|
|||
}
|
||||
|
||||
/// (C411) Convert `list([i * i for i in x])` to `[i * i for i in x]`.
|
||||
pub fn fix_unnecessary_list_call(
|
||||
pub(crate) fn fix_unnecessary_list_call(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -698,7 +698,7 @@ pub fn fix_unnecessary_list_call(
|
|||
/// (C413) Convert `list(sorted([2, 3, 1]))` to `sorted([2, 3, 1])`.
|
||||
/// (C413) Convert `reversed(sorted([2, 3, 1]))` to `sorted([2, 3, 1],
|
||||
/// reverse=True)`.
|
||||
pub fn fix_unnecessary_call_around_sorted(
|
||||
pub(crate) fn fix_unnecessary_call_around_sorted(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -821,7 +821,7 @@ pub fn fix_unnecessary_call_around_sorted(
|
|||
}
|
||||
|
||||
/// (C414) Convert `sorted(list(foo))` to `sorted(foo)`
|
||||
pub fn fix_unnecessary_double_cast_or_process(
|
||||
pub(crate) fn fix_unnecessary_double_cast_or_process(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -858,7 +858,7 @@ pub fn fix_unnecessary_double_cast_or_process(
|
|||
}
|
||||
|
||||
/// (C416) Convert `[i for i in x]` to `list(x)`.
|
||||
pub fn fix_unnecessary_comprehension(
|
||||
pub(crate) fn fix_unnecessary_comprehension(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -950,7 +950,7 @@ pub fn fix_unnecessary_comprehension(
|
|||
}
|
||||
|
||||
/// (C417) Convert `map(lambda x: x * 2, bar)` to `(x * 2 for x in bar)`.
|
||||
pub fn fix_unnecessary_map(
|
||||
pub(crate) fn fix_unnecessary_map(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -1114,7 +1114,7 @@ pub fn fix_unnecessary_map(
|
|||
}
|
||||
|
||||
/// (C418) Convert `dict({"a": 1})` to `{"a": 1}`
|
||||
pub fn fix_unnecessary_literal_within_dict_call(
|
||||
pub(crate) fn fix_unnecessary_literal_within_dict_call(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
@ -1138,7 +1138,7 @@ pub fn fix_unnecessary_literal_within_dict_call(
|
|||
}
|
||||
|
||||
/// (C419) Convert `[i for i in a]` into `i for i in a`
|
||||
pub fn fix_unnecessary_comprehension_any_all(
|
||||
pub(crate) fn fix_unnecessary_comprehension_any_all(
|
||||
locator: &Locator,
|
||||
stylist: &Stylist,
|
||||
expr: &rustpython_parser::ast::Expr,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{self, Expr, ExprKind, Keyword};
|
||||
|
||||
pub fn expr_name(func: &Expr) -> Option<&str> {
|
||||
pub(crate) fn expr_name(func: &Expr) -> Option<&str> {
|
||||
if let ExprKind::Name(ast::ExprName { id, .. }) = &func.node {
|
||||
Some(id)
|
||||
} else {
|
||||
|
@ -8,7 +8,7 @@ pub fn expr_name(func: &Expr) -> Option<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn exactly_one_argument_with_matching_function<'a>(
|
||||
pub(crate) fn exactly_one_argument_with_matching_function<'a>(
|
||||
name: &str,
|
||||
func: &Expr,
|
||||
args: &'a [Expr],
|
||||
|
@ -26,7 +26,7 @@ pub fn exactly_one_argument_with_matching_function<'a>(
|
|||
Some(&args[0].node)
|
||||
}
|
||||
|
||||
pub fn first_argument_with_matching_function<'a>(
|
||||
pub(crate) fn first_argument_with_matching_function<'a>(
|
||||
name: &str,
|
||||
func: &Expr,
|
||||
args: &'a [Expr],
|
||||
|
|
|
@ -1,39 +1,41 @@
|
|||
pub use unnecessary_call_around_sorted::{
|
||||
pub(crate) use unnecessary_call_around_sorted::{
|
||||
unnecessary_call_around_sorted, UnnecessaryCallAroundSorted,
|
||||
};
|
||||
pub use unnecessary_collection_call::{unnecessary_collection_call, UnnecessaryCollectionCall};
|
||||
pub use unnecessary_comprehension::{
|
||||
pub(crate) use unnecessary_collection_call::{
|
||||
unnecessary_collection_call, UnnecessaryCollectionCall,
|
||||
};
|
||||
pub(crate) use unnecessary_comprehension::{
|
||||
unnecessary_dict_comprehension, unnecessary_list_set_comprehension, UnnecessaryComprehension,
|
||||
};
|
||||
pub use unnecessary_comprehension_any_all::{
|
||||
pub(crate) use unnecessary_comprehension_any_all::{
|
||||
unnecessary_comprehension_any_all, UnnecessaryComprehensionAnyAll,
|
||||
};
|
||||
pub use unnecessary_double_cast_or_process::{
|
||||
pub(crate) use unnecessary_double_cast_or_process::{
|
||||
unnecessary_double_cast_or_process, UnnecessaryDoubleCastOrProcess,
|
||||
};
|
||||
pub use unnecessary_generator_dict::{unnecessary_generator_dict, UnnecessaryGeneratorDict};
|
||||
pub use unnecessary_generator_list::{unnecessary_generator_list, UnnecessaryGeneratorList};
|
||||
pub use unnecessary_generator_set::{unnecessary_generator_set, UnnecessaryGeneratorSet};
|
||||
pub use unnecessary_list_call::{unnecessary_list_call, UnnecessaryListCall};
|
||||
pub use unnecessary_list_comprehension_dict::{
|
||||
pub(crate) use unnecessary_generator_dict::{unnecessary_generator_dict, UnnecessaryGeneratorDict};
|
||||
pub(crate) use unnecessary_generator_list::{unnecessary_generator_list, UnnecessaryGeneratorList};
|
||||
pub(crate) use unnecessary_generator_set::{unnecessary_generator_set, UnnecessaryGeneratorSet};
|
||||
pub(crate) use unnecessary_list_call::{unnecessary_list_call, UnnecessaryListCall};
|
||||
pub(crate) use unnecessary_list_comprehension_dict::{
|
||||
unnecessary_list_comprehension_dict, UnnecessaryListComprehensionDict,
|
||||
};
|
||||
pub use unnecessary_list_comprehension_set::{
|
||||
pub(crate) use unnecessary_list_comprehension_set::{
|
||||
unnecessary_list_comprehension_set, UnnecessaryListComprehensionSet,
|
||||
};
|
||||
pub use unnecessary_literal_dict::{unnecessary_literal_dict, UnnecessaryLiteralDict};
|
||||
pub use unnecessary_literal_set::{unnecessary_literal_set, UnnecessaryLiteralSet};
|
||||
pub use unnecessary_literal_within_dict_call::{
|
||||
pub(crate) use unnecessary_literal_dict::{unnecessary_literal_dict, UnnecessaryLiteralDict};
|
||||
pub(crate) use unnecessary_literal_set::{unnecessary_literal_set, UnnecessaryLiteralSet};
|
||||
pub(crate) use unnecessary_literal_within_dict_call::{
|
||||
unnecessary_literal_within_dict_call, UnnecessaryLiteralWithinDictCall,
|
||||
};
|
||||
pub use unnecessary_literal_within_list_call::{
|
||||
pub(crate) use unnecessary_literal_within_list_call::{
|
||||
unnecessary_literal_within_list_call, UnnecessaryLiteralWithinListCall,
|
||||
};
|
||||
pub use unnecessary_literal_within_tuple_call::{
|
||||
pub(crate) use unnecessary_literal_within_tuple_call::{
|
||||
unnecessary_literal_within_tuple_call, UnnecessaryLiteralWithinTupleCall,
|
||||
};
|
||||
pub use unnecessary_map::{unnecessary_map, UnnecessaryMap};
|
||||
pub use unnecessary_subscript_reversal::{
|
||||
pub(crate) use unnecessary_map::{unnecessary_map, UnnecessaryMap};
|
||||
pub(crate) use unnecessary_subscript_reversal::{
|
||||
unnecessary_subscript_reversal, UnnecessarySubscriptReversal,
|
||||
};
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ impl AlwaysAutofixableViolation for UnnecessaryCallAroundSorted {
|
|||
}
|
||||
|
||||
/// C413
|
||||
pub fn unnecessary_call_around_sorted(
|
||||
pub(crate) fn unnecessary_call_around_sorted(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
|
@ -52,7 +52,7 @@ impl AlwaysAutofixableViolation for UnnecessaryCollectionCall {
|
|||
}
|
||||
|
||||
/// C408
|
||||
pub fn unnecessary_collection_call(
|
||||
pub(crate) fn unnecessary_collection_call(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
|
@ -75,7 +75,7 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) {
|
|||
}
|
||||
|
||||
/// C416
|
||||
pub fn unnecessary_dict_comprehension(
|
||||
pub(crate) fn unnecessary_dict_comprehension(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
key: &Expr,
|
||||
|
@ -117,7 +117,7 @@ pub fn unnecessary_dict_comprehension(
|
|||
}
|
||||
|
||||
/// C416
|
||||
pub fn unnecessary_list_set_comprehension(
|
||||
pub(crate) fn unnecessary_list_set_comprehension(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
elt: &Expr,
|
||||
|
|
|
@ -56,7 +56,7 @@ impl Violation for UnnecessaryComprehensionAnyAll {
|
|||
}
|
||||
|
||||
/// C419
|
||||
pub fn unnecessary_comprehension_any_all(
|
||||
pub(crate) fn unnecessary_comprehension_any_all(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
|
@ -64,7 +64,7 @@ impl AlwaysAutofixableViolation for UnnecessaryDoubleCastOrProcess {
|
|||
}
|
||||
|
||||
/// C414
|
||||
pub fn unnecessary_double_cast_or_process(
|
||||
pub(crate) fn unnecessary_double_cast_or_process(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
|
@ -42,7 +42,7 @@ impl AlwaysAutofixableViolation for UnnecessaryGeneratorDict {
|
|||
}
|
||||
|
||||
/// C402 (`dict((x, y) for x, y in iterable)`)
|
||||
pub fn unnecessary_generator_dict(
|
||||
pub(crate) fn unnecessary_generator_dict(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
parent: Option<&Expr>,
|
||||
|
|
|
@ -42,7 +42,7 @@ impl AlwaysAutofixableViolation for UnnecessaryGeneratorList {
|
|||
}
|
||||
|
||||
/// C400 (`list(generator)`)
|
||||
pub fn unnecessary_generator_list(
|
||||
pub(crate) fn unnecessary_generator_list(
|
||||
checker: &mut Checker,
|
||||
expr: &Expr,
|
||||
func: &Expr,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue