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