mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Enforce most pedantic lints on CI (#878)
This commit is contained in:
parent
10dcd5fd0a
commit
bdd32c0850
42 changed files with 169 additions and 105 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
@ -82,7 +82,7 @@ jobs:
|
|||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
- run: cargo clippy --workspace --all-targets --all-features -- -D warnings
|
||||
- run: cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::pedantic
|
||||
|
||||
cargo_test:
|
||||
name: "cargo test"
|
||||
|
|
|
@ -10,7 +10,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
b.iter(|| {
|
||||
let rope = Rope::from_str(black_box(&contents));
|
||||
rope.line_to_char(black_box(4));
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ pub fn convert(
|
|||
match parser::parse_files_to_codes_mapping(value.as_ref()) {
|
||||
Ok(per_file_ignores) => {
|
||||
options.per_file_ignores =
|
||||
Some(parser::collect_per_file_ignores(per_file_ignores))
|
||||
Some(parser::collect_per_file_ignores(per_file_ignores));
|
||||
}
|
||||
Err(e) => eprintln!("Unable to parse '{key}' property: {e}"),
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ pub fn convert(
|
|||
"ban-relative-imports" | "ban_relative_imports" => match value.trim() {
|
||||
"true" => flake8_tidy_imports.ban_relative_imports = Some(Strictness::All),
|
||||
"parents" => {
|
||||
flake8_tidy_imports.ban_relative_imports = Some(Strictness::Parents)
|
||||
flake8_tidy_imports.ban_relative_imports = Some(Strictness::Parents);
|
||||
}
|
||||
_ => eprintln!("Unexpected '{key}' value: {value}"),
|
||||
},
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
|
||||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
pub mod converter;
|
||||
mod parser;
|
||||
|
|
|
@ -1,4 +1,16 @@
|
|||
//! Utility to generate Ruff's pyproject.toml section from a Flake8 INI file.
|
||||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
pub mod generate_check_code_prefix;
|
||||
pub mod generate_rules_table;
|
||||
pub mod generate_source_code;
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use ruff_dev::{
|
||||
|
|
|
@ -11,7 +11,7 @@ pub fn extract_all_names(stmt: &Stmt, scope: &Scope) -> Vec<String> {
|
|||
..
|
||||
} = &elt.node
|
||||
{
|
||||
names.push(value.to_string())
|
||||
names.push(value.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub fn extract_all_names(stmt: &Stmt, scope: &Scope) -> Vec<String> {
|
|||
} {
|
||||
match &value.node {
|
||||
ExprKind::List { elts, .. } | ExprKind::Tuple { elts, .. } => {
|
||||
add_to_names(&mut names, elts)
|
||||
add_to_names(&mut names, elts);
|
||||
}
|
||||
ExprKind::BinOp { left, right, .. } => {
|
||||
let mut current_left = left;
|
||||
|
|
|
@ -249,7 +249,7 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) {
|
|||
visitor.visit_stmt(stmt);
|
||||
}
|
||||
for excepthandler in handlers {
|
||||
visitor.visit_excepthandler(excepthandler)
|
||||
visitor.visit_excepthandler(excepthandler);
|
||||
}
|
||||
for stmt in orelse {
|
||||
visitor.visit_stmt(stmt);
|
||||
|
@ -447,7 +447,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
|
|||
pub fn walk_constant<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, constant: &'a Constant) {
|
||||
if let Constant::Tuple(constants) = constant {
|
||||
for constant in constants {
|
||||
visitor.visit_constant(constant)
|
||||
visitor.visit_constant(constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@ fn apply_fixes<'a>(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use crate::autofix::fixer::apply_fixes;
|
||||
|
@ -108,18 +107,16 @@ mod tests {
|
|||
use crate::SourceCodeLocator;
|
||||
|
||||
#[test]
|
||||
fn empty_file() -> Result<()> {
|
||||
fn empty_file() {
|
||||
let fixes = vec![];
|
||||
let locator = SourceCodeLocator::new(r#""#);
|
||||
let (contents, fixed) = apply_fixes(fixes.iter(), &locator);
|
||||
assert_eq!(contents, "");
|
||||
assert_eq!(fixed, 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_single_replacement() -> Result<()> {
|
||||
fn apply_single_replacement() {
|
||||
let fixes = vec![Fix {
|
||||
patch: Patch {
|
||||
content: "Bar".to_string(),
|
||||
|
@ -144,12 +141,10 @@ class A(Bar):
|
|||
.trim(),
|
||||
);
|
||||
assert_eq!(fixed, 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_single_removal() -> Result<()> {
|
||||
fn apply_single_removal() {
|
||||
let fixes = vec![Fix {
|
||||
patch: Patch {
|
||||
content: String::new(),
|
||||
|
@ -174,12 +169,10 @@ class A:
|
|||
.trim()
|
||||
);
|
||||
assert_eq!(fixed, 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_double_removal() -> Result<()> {
|
||||
fn apply_double_removal() {
|
||||
let fixes = vec![
|
||||
Fix {
|
||||
patch: Patch {
|
||||
|
@ -214,12 +207,10 @@ class A:
|
|||
.trim()
|
||||
);
|
||||
assert_eq!(fixed, 2);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignore_overlapping_fixes() -> Result<()> {
|
||||
fn ignore_overlapping_fixes() {
|
||||
let fixes = vec![
|
||||
Fix {
|
||||
patch: Patch {
|
||||
|
@ -253,7 +244,5 @@ class A:
|
|||
.trim(),
|
||||
);
|
||||
assert_eq!(fixed, 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,6 +178,6 @@ pub fn set(
|
|||
cache_key(path, settings, autofix),
|
||||
&bincode::serialize(&check_result).unwrap(),
|
||||
) {
|
||||
error!("Failed to write to cache: {e:?}")
|
||||
error!("Failed to write to cache: {e:?}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -534,20 +534,20 @@ where
|
|||
self.check_builtin_shadowing(name, Range::from_located(stmt), false);
|
||||
|
||||
for expr in bases {
|
||||
self.visit_expr(expr)
|
||||
self.visit_expr(expr);
|
||||
}
|
||||
for keyword in keywords {
|
||||
self.visit_keyword(keyword)
|
||||
self.visit_keyword(keyword);
|
||||
}
|
||||
for expr in decorator_list {
|
||||
self.visit_expr(expr)
|
||||
self.visit_expr(expr);
|
||||
}
|
||||
self.push_scope(Scope::new(ScopeKind::Class(ClassScope {
|
||||
name,
|
||||
bases,
|
||||
keywords,
|
||||
decorator_list,
|
||||
})))
|
||||
})));
|
||||
}
|
||||
StmtKind::Import { names } => {
|
||||
if self.settings.enabled.contains(&CheckCode::E402) {
|
||||
|
@ -576,7 +576,7 @@ where
|
|||
used: None,
|
||||
range: Range::from_located(stmt),
|
||||
},
|
||||
)
|
||||
);
|
||||
} else {
|
||||
if let Some(asname) = &alias.node.asname {
|
||||
self.check_builtin_shadowing(asname, Range::from_located(stmt), false);
|
||||
|
@ -616,7 +616,7 @@ where
|
|||
},
|
||||
range: Range::from_located(stmt),
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(asname) = &alias.node.asname {
|
||||
|
@ -692,7 +692,7 @@ where
|
|||
.iter()
|
||||
.filter(|alias| alias.node.asname.is_none())
|
||||
.map(|alias| alias.node.name.as_str()),
|
||||
)
|
||||
);
|
||||
}
|
||||
for alias in names {
|
||||
if let Some(asname) = &alias.node.asname {
|
||||
|
@ -835,7 +835,7 @@ where
|
|||
},
|
||||
range: Range::from_located(stmt),
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if self.settings.enabled.contains(&CheckCode::I252) {
|
||||
|
@ -979,7 +979,7 @@ where
|
|||
StmtKind::Assign { targets, value, .. } => {
|
||||
if self.settings.enabled.contains(&CheckCode::E731) {
|
||||
if let [target] = &targets[..] {
|
||||
pycodestyle::plugins::do_not_assign_lambda(self, target, value, stmt)
|
||||
pycodestyle::plugins::do_not_assign_lambda(self, target, value, stmt);
|
||||
}
|
||||
}
|
||||
if self.settings.enabled.contains(&CheckCode::U001) {
|
||||
|
@ -1016,7 +1016,7 @@ where
|
|||
StmtKind::Delete { .. } => {}
|
||||
StmtKind::Expr { value, .. } => {
|
||||
if self.settings.enabled.contains(&CheckCode::B015) {
|
||||
flake8_bugbear::plugins::useless_comparison(self, value)
|
||||
flake8_bugbear::plugins::useless_comparison(self, value);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -1081,7 +1081,7 @@ where
|
|||
}
|
||||
self.except_handlers.pop();
|
||||
for excepthandler in handlers {
|
||||
self.visit_excepthandler(excepthandler)
|
||||
self.visit_excepthandler(excepthandler);
|
||||
}
|
||||
for stmt in orelse {
|
||||
self.visit_stmt(stmt);
|
||||
|
@ -1620,7 +1620,7 @@ where
|
|||
comparators,
|
||||
check_none_comparisons,
|
||||
check_true_false_comparisons,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if self.settings.enabled.contains(&CheckCode::F632) {
|
||||
|
@ -1717,7 +1717,7 @@ where
|
|||
for expr in &args.defaults {
|
||||
self.visit_expr(expr);
|
||||
}
|
||||
self.push_scope(Scope::new(ScopeKind::Lambda))
|
||||
self.push_scope(Scope::new(ScopeKind::Lambda));
|
||||
}
|
||||
ExprKind::ListComp { elt, generators } | ExprKind::SetComp { elt, generators } => {
|
||||
if self.settings.enabled.contains(&CheckCode::C416) {
|
||||
|
@ -1732,10 +1732,10 @@ where
|
|||
self.add_check(check);
|
||||
};
|
||||
}
|
||||
self.push_scope(Scope::new(ScopeKind::Generator))
|
||||
self.push_scope(Scope::new(ScopeKind::Generator));
|
||||
}
|
||||
ExprKind::GeneratorExp { .. } | ExprKind::DictComp { .. } => {
|
||||
self.push_scope(Scope::new(ScopeKind::Generator))
|
||||
self.push_scope(Scope::new(ScopeKind::Generator));
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
@ -1894,7 +1894,7 @@ where
|
|||
error!(
|
||||
"Found non-ExprKind::Tuple argument to PEP 593 \
|
||||
Annotation."
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2014,10 +2014,10 @@ where
|
|||
.extend(pyflakes::checks::duplicate_arguments(arguments));
|
||||
}
|
||||
if self.settings.enabled.contains(&CheckCode::B006) {
|
||||
flake8_bugbear::plugins::mutable_argument_default(self, arguments)
|
||||
flake8_bugbear::plugins::mutable_argument_default(self, arguments);
|
||||
}
|
||||
if self.settings.enabled.contains(&CheckCode::B008) {
|
||||
flake8_bugbear::plugins::function_call_argument_default(self, arguments)
|
||||
flake8_bugbear::plugins::function_call_argument_default(self, arguments);
|
||||
}
|
||||
|
||||
// flake8-boolean-trap
|
||||
|
@ -2310,7 +2310,7 @@ impl<'a> Checker<'a> {
|
|||
self.add_check(Check::new(
|
||||
CheckKind::UndefinedName(id.clone()),
|
||||
Range::from_located(expr),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2339,20 +2339,22 @@ impl<'a> Checker<'a> {
|
|||
.get(id)
|
||||
.map_or(false, |binding| matches!(binding.kind, BindingKind::Global))
|
||||
{
|
||||
pep8_naming::plugins::non_lowercase_variable_in_function(self, expr, parent, id)
|
||||
pep8_naming::plugins::non_lowercase_variable_in_function(
|
||||
self, expr, parent, id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.settings.enabled.contains(&CheckCode::N815) {
|
||||
if matches!(self.current_scope().kind, ScopeKind::Class(..)) {
|
||||
pep8_naming::plugins::mixed_case_variable_in_class_scope(self, expr, parent, id)
|
||||
pep8_naming::plugins::mixed_case_variable_in_class_scope(self, expr, parent, id);
|
||||
}
|
||||
}
|
||||
|
||||
if self.settings.enabled.contains(&CheckCode::N816) {
|
||||
if matches!(self.current_scope().kind, ScopeKind::Module) {
|
||||
pep8_naming::plugins::mixed_case_variable_in_global_scope(self, expr, parent, id)
|
||||
pep8_naming::plugins::mixed_case_variable_in_global_scope(self, expr, parent, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2448,7 +2450,7 @@ impl<'a> Checker<'a> {
|
|||
self.add_check(Check::new(
|
||||
CheckKind::UndefinedName(id.to_string()),
|
||||
Range::from_located(expr),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ pub fn check_lines(
|
|||
match noqa {
|
||||
(Directive::All(..), matches) => {
|
||||
matches.push(check.kind.code().as_ref());
|
||||
ignored.push(index)
|
||||
ignored.push(index);
|
||||
}
|
||||
(Directive::Codes(.., codes), matches) => {
|
||||
if codes.contains(&check.kind.code().as_ref()) {
|
||||
|
|
|
@ -2155,13 +2155,12 @@ impl Check {
|
|||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::Result;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::checks::CheckCode;
|
||||
|
||||
#[test]
|
||||
fn check_code_serialization() -> Result<()> {
|
||||
fn check_code_serialization() {
|
||||
for check_code in CheckCode::iter() {
|
||||
assert!(
|
||||
CheckCode::from_str(check_code.as_ref()).is_ok(),
|
||||
|
@ -2169,6 +2168,5 @@ mod tests {
|
|||
check_code
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ impl SourceGenerator {
|
|||
});
|
||||
self.p("= ");
|
||||
self.unparse_expr(value, precedence::EXPR);
|
||||
})
|
||||
});
|
||||
}
|
||||
StmtKind::AnnAssign {
|
||||
target,
|
||||
|
@ -273,7 +273,7 @@ impl SourceGenerator {
|
|||
self.p(" = ");
|
||||
self.unparse_expr(value, precedence::EXPR);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
StmtKind::For {
|
||||
target,
|
||||
|
@ -440,7 +440,7 @@ impl SourceGenerator {
|
|||
self.p(", ");
|
||||
self.unparse_expr(msg, precedence::TEST);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
StmtKind::Import { names } => {
|
||||
statement!({
|
||||
|
@ -471,7 +471,7 @@ impl SourceGenerator {
|
|||
self.p_delim(&mut first, ", ");
|
||||
self.unparse_alias(alias);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
StmtKind::Global { names } => {
|
||||
statement!({
|
||||
|
@ -566,14 +566,14 @@ impl SourceGenerator {
|
|||
self.p_delim(&mut first, op);
|
||||
self.unparse_expr(val, prec + 1);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::NamedExpr { target, value } => {
|
||||
group_if!(precedence::TUPLE, {
|
||||
self.unparse_expr(target, precedence::ATOM);
|
||||
self.p(" := ");
|
||||
self.unparse_expr(value, precedence::ATOM);
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::BinOp { left, op, right } => {
|
||||
let rassoc = matches!(op, Operator::Pow);
|
||||
|
@ -599,7 +599,7 @@ impl SourceGenerator {
|
|||
self.unparse_expr(left, prec + u8::from(rassoc));
|
||||
self.p(op);
|
||||
self.unparse_expr(right, prec + u8::from(!rassoc));
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::UnaryOp { op, operand } => {
|
||||
let (op, prec) = opprec!(
|
||||
|
@ -614,7 +614,7 @@ impl SourceGenerator {
|
|||
group_if!(prec, {
|
||||
self.p(op);
|
||||
self.unparse_expr(operand, prec);
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::Lambda { args, body } => {
|
||||
group_if!(precedence::TEST, {
|
||||
|
@ -622,7 +622,7 @@ impl SourceGenerator {
|
|||
self.p(if npos > 0 { "lambda " } else { "lambda" });
|
||||
self.unparse_args(args);
|
||||
write!(self, ": {}", **body);
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::IfExp { test, body, orelse } => {
|
||||
group_if!(precedence::TEST, {
|
||||
|
@ -631,7 +631,7 @@ impl SourceGenerator {
|
|||
self.unparse_expr(test, precedence::TEST + 1);
|
||||
self.p(" else ");
|
||||
self.unparse_expr(orelse, precedence::TEST);
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::Dict { keys, values } => {
|
||||
self.p("{");
|
||||
|
@ -694,7 +694,7 @@ impl SourceGenerator {
|
|||
group_if!(precedence::AWAIT, {
|
||||
self.p("await ");
|
||||
self.unparse_expr(value, precedence::ATOM);
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::Yield { value } => {
|
||||
if let Some(value) = value {
|
||||
|
@ -730,7 +730,7 @@ impl SourceGenerator {
|
|||
self.p(op);
|
||||
self.unparse_expr(cmp, new_lvl);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
ExprKind::Call {
|
||||
func,
|
||||
|
@ -813,7 +813,7 @@ impl SourceGenerator {
|
|||
.iter()
|
||||
.any(|expr| matches!(expr.node, ExprKind::Starred { .. }))
|
||||
{
|
||||
lvl += 1
|
||||
lvl += 1;
|
||||
}
|
||||
}
|
||||
self.p("[");
|
||||
|
@ -845,7 +845,7 @@ impl SourceGenerator {
|
|||
self.unparse_expr(elt, precedence::TEST);
|
||||
}
|
||||
self.p_if(elts.len() == 1, ",");
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
ExprKind::Slice { lower, upper, step } => {
|
||||
|
@ -962,7 +962,7 @@ impl SourceGenerator {
|
|||
match &expr.node {
|
||||
ExprKind::Constant { value, .. } => {
|
||||
if let Constant::Str(s) = value {
|
||||
self.unparse_fstring_str(s)
|
||||
self.unparse_fstring_str(s);
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ pub fn extract_isort_exclusions(lxr: &[LexResult], locator: &SourceCodeLocator)
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use nohash_hasher::IntMap;
|
||||
use rustpython_parser::lexer;
|
||||
use rustpython_parser::lexer::LexResult;
|
||||
|
|
|
@ -65,7 +65,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.add_check(check);
|
||||
|
|
|
@ -60,9 +60,9 @@ where
|
|||
self.checks.push((
|
||||
CheckKind::FunctionCallArgumentDefault(compose_call_path(expr)),
|
||||
Range::from_located(expr),
|
||||
))
|
||||
));
|
||||
}
|
||||
visitor::walk_expr(self, expr)
|
||||
visitor::walk_expr(self, expr);
|
||||
}
|
||||
ExprKind::Lambda { .. } => {}
|
||||
_ => visitor::walk_expr(self, expr),
|
||||
|
|
|
@ -78,7 +78,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E
|
|||
}
|
||||
}
|
||||
}
|
||||
checker.add_check(check)
|
||||
checker.add_check(check);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ fn assignment(obj: &Expr, name: &str, value: &Expr) -> Result<String> {
|
|||
);
|
||||
let mut generator = SourceGenerator::new();
|
||||
generator.unparse_stmt(&stmt);
|
||||
generator.generate().map_err(|e| e.into())
|
||||
generator.generate().map_err(std::convert::Into::into)
|
||||
}
|
||||
|
||||
/// B010
|
||||
|
|
|
@ -12,7 +12,7 @@ pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop,
|
|||
checker.add_check(Check::new(
|
||||
CheckKind::UnaryPrefixIncrement,
|
||||
Range::from_located(expr),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body:
|
|||
format!("_{name}"),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
checker.add_check(check);
|
||||
}
|
||||
|
|
|
@ -722,7 +722,7 @@ pub fn fix_unnecessary_call_around_sorted(
|
|||
rpar: inner_call.rpar.clone(),
|
||||
whitespace_after_func: inner_call.whitespace_after_func.clone(),
|
||||
whitespace_before_args: inner_call.whitespace_before_args.clone(),
|
||||
}))
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -766,7 +766,7 @@ pub fn fix_unnecessary_comprehension(
|
|||
rpar: vec![],
|
||||
whitespace_after_func: ParenthesizableWhitespace::default(),
|
||||
whitespace_before_args: ParenthesizableWhitespace::default(),
|
||||
}))
|
||||
}));
|
||||
}
|
||||
Expression::SetComp(inner) => {
|
||||
body.value = Expression::Call(Box::new(Call {
|
||||
|
@ -788,7 +788,7 @@ pub fn fix_unnecessary_comprehension(
|
|||
rpar: vec![],
|
||||
whitespace_after_func: ParenthesizableWhitespace::default(),
|
||||
whitespace_before_args: ParenthesizableWhitespace::default(),
|
||||
}))
|
||||
}));
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!(
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn print_call(checker: &mut Checker, expr: &Expr, func: &Expr) {
|
|||
if fix.patch.content.is_empty() || fix.patch.content == "pass" {
|
||||
checker.deletions.insert(context.defined_by);
|
||||
}
|
||||
check.amend(fix)
|
||||
check.amend(fix);
|
||||
}
|
||||
Err(e) => error!("Failed to remove print call: {}", e),
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ fn annotate_imports<'a>(
|
|||
asname: alias.node.asname.as_ref(),
|
||||
atop: alias_atop,
|
||||
inline: alias_inline,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
annotated.push(AnnotatedImport::ImportFrom {
|
||||
|
|
|
@ -142,7 +142,7 @@ where
|
|||
finalbody,
|
||||
} => {
|
||||
for excepthandler in handlers {
|
||||
self.visit_excepthandler(excepthandler)
|
||||
self.visit_excepthandler(excepthandler);
|
||||
}
|
||||
|
||||
for stmt in body {
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -1,4 +1,15 @@
|
|||
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
|
||||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ pub(crate) fn check_path(
|
|||
location: parse_error.location,
|
||||
end_location: parse_error.location,
|
||||
},
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn set_up_logging(level: &LogLevel) -> Result<()> {
|
|||
record.target(),
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
));
|
||||
})
|
||||
.level(level.level_filter())
|
||||
.chain(std::io::stdout())
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -1,3 +1,16 @@
|
|||
#![allow(
|
||||
clippy::collapsible_else_if,
|
||||
clippy::collapsible_if,
|
||||
clippy::implicit_hasher,
|
||||
clippy::match_same_arms,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::must_use_candidate,
|
||||
clippy::similar_names,
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use std::io::{self, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitCode;
|
||||
|
|
|
@ -120,6 +120,7 @@ fn add_noqa_inner(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use nohash_hasher::IntMap;
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<'a> Printer<'a> {
|
|||
})
|
||||
.collect::<Vec<_>>()
|
||||
)?
|
||||
)
|
||||
);
|
||||
}
|
||||
SerializationFormat::Text => {
|
||||
if self.log_level >= &LogLevel::Default {
|
||||
|
@ -79,19 +79,19 @@ impl<'a> Printer<'a> {
|
|||
"Found {} error(s) ({} fixed).",
|
||||
diagnostics.messages.len(),
|
||||
diagnostics.fixed,
|
||||
)
|
||||
);
|
||||
} else if !diagnostics.messages.is_empty() {
|
||||
println!("Found {} error(s).", diagnostics.messages.len())
|
||||
println!("Found {} error(s).", diagnostics.messages.len());
|
||||
}
|
||||
}
|
||||
|
||||
for message in &diagnostics.messages {
|
||||
println!("{message}")
|
||||
println!("{message}");
|
||||
}
|
||||
|
||||
if self.log_level >= &LogLevel::Default {
|
||||
if num_fixable > 0 {
|
||||
println!("{num_fixable} potentially fixable with the --fix option.")
|
||||
println!("{num_fixable} potentially fixable with the --fix option.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ impl<'a> Printer<'a> {
|
|||
println!();
|
||||
}
|
||||
for message in &diagnostics.messages {
|
||||
println!("{message}")
|
||||
println!("{message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ pub fn invalid_escape_sequence(
|
|||
location,
|
||||
end_location,
|
||||
},
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1190,7 +1190,7 @@ fn common_section(
|
|||
docstring.location.row() + context.original_index,
|
||||
section_name_start + section_name_length,
|
||||
),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.add_check(check);
|
||||
|
@ -1284,7 +1284,7 @@ fn common_section(
|
|||
Location::new(docstring.location.row() + context.original_index, 0),
|
||||
));
|
||||
}
|
||||
checker.add_check(check)
|
||||
checker.add_check(check);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ fn args_section(checker: &mut Checker, definition: &Definition, context: &Sectio
|
|||
},
|
||||
)
|
||||
.collect(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
fn parameters_section(checker: &mut Checker, definition: &Definition, context: &SectionContext) {
|
||||
|
@ -1458,7 +1458,7 @@ fn numpy_section(checker: &mut Checker, definition: &Definition, context: &Secti
|
|||
));
|
||||
}
|
||||
}
|
||||
checker.add_check(check)
|
||||
checker.add_check(check);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ pub fn repeated_keys(
|
|||
checks.push(Check::new(
|
||||
CheckKind::MultiValueRepeatedKeyLiteral,
|
||||
Range::from_located(k2),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
(Some(DictionaryKey::Variable(v1)), Some(DictionaryKey::Variable(v2))) => {
|
||||
|
@ -172,7 +172,7 @@ pub fn repeated_keys(
|
|||
checks.push(Check::new(
|
||||
CheckKind::MultiValueRepeatedKeyVariable((*v2).to_string()),
|
||||
Range::from_located(k2),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) {
|
|||
"NotImplementedError".to_string(),
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
checker.add_check(check);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ fn create_check(
|
|||
content,
|
||||
mode_param.location,
|
||||
mode_param.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
} else {
|
||||
match create_remove_param_fix(locator, expr, mode_param) {
|
||||
Ok(fix) => check.amend(fix),
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp
|
|||
check.amend(fix);
|
||||
}
|
||||
}
|
||||
checker.add_check(check)
|
||||
checker.add_check(check);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn replace_with_bytes_literal(
|
|||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
check
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.add_check(check);
|
||||
|
@ -91,7 +91,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
content,
|
||||
expr.location,
|
||||
expr.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn useless_metaclass_type(checker: &mut Checker, stmt: &Stmt, value: &Expr,
|
|||
if fix.patch.content.is_empty() || fix.patch.content == "pass" {
|
||||
checker.deletions.insert(context.defined_by);
|
||||
}
|
||||
check.amend(fix)
|
||||
check.amend(fix);
|
||||
}
|
||||
Err(e) => error!("Failed to fix remove metaclass type: {}", e),
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ pub fn convert_exit_to_sys_exit(checker: &mut Checker, func: &Expr) {
|
|||
content,
|
||||
func.location,
|
||||
func.end_location.unwrap(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.add_check(check);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue