Enforce most pedantic lints on CI (#878)

This commit is contained in:
Charlie Marsh 2022-11-22 18:55:57 -05:00 committed by GitHub
parent 10dcd5fd0a
commit bdd32c0850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 169 additions and 105 deletions

View file

@ -82,7 +82,7 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build- ${{ runner.os }}-build-
${{ runner.os }}- ${{ 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: cargo_test:
name: "cargo test" name: "cargo test"

View file

@ -10,7 +10,7 @@ fn criterion_benchmark(c: &mut Criterion) {
b.iter(|| { b.iter(|| {
let rope = Rope::from_str(black_box(&contents)); let rope = Rope::from_str(black_box(&contents));
rope.line_to_char(black_box(4)); rope.line_to_char(black_box(4));
}) });
}); });
} }

View file

@ -110,7 +110,7 @@ pub fn convert(
match parser::parse_files_to_codes_mapping(value.as_ref()) { match parser::parse_files_to_codes_mapping(value.as_ref()) {
Ok(per_file_ignores) => { Ok(per_file_ignores) => {
options.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}"), 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() { "ban-relative-imports" | "ban_relative_imports" => match value.trim() {
"true" => flake8_tidy_imports.ban_relative_imports = Some(Strictness::All), "true" => flake8_tidy_imports.ban_relative_imports = Some(Strictness::All),
"parents" => { "parents" => {
flake8_tidy_imports.ban_relative_imports = Some(Strictness::Parents) flake8_tidy_imports.ban_relative_imports = Some(Strictness::Parents);
} }
_ => eprintln!("Unexpected '{key}' value: {value}"), _ => eprintln!("Unexpected '{key}' value: {value}"),
}, },

View file

@ -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; pub mod converter;
mod parser; mod parser;

View file

@ -1,4 +1,16 @@
//! Utility to generate Ruff's pyproject.toml section from a Flake8 INI file. //! 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; use std::path::PathBuf;

View file

@ -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_check_code_prefix;
pub mod generate_rules_table; pub mod generate_rules_table;
pub mod generate_source_code; pub mod generate_source_code;

View file

@ -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 anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use ruff_dev::{ use ruff_dev::{

View file

@ -11,7 +11,7 @@ pub fn extract_all_names(stmt: &Stmt, scope: &Scope) -> Vec<String> {
.. ..
} = &elt.node } = &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 { match &value.node {
ExprKind::List { elts, .. } | ExprKind::Tuple { elts, .. } => { ExprKind::List { elts, .. } | ExprKind::Tuple { elts, .. } => {
add_to_names(&mut names, elts) add_to_names(&mut names, elts);
} }
ExprKind::BinOp { left, right, .. } => { ExprKind::BinOp { left, right, .. } => {
let mut current_left = left; let mut current_left = left;

View file

@ -249,7 +249,7 @@ pub fn walk_stmt<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, stmt: &'a Stmt) {
visitor.visit_stmt(stmt); visitor.visit_stmt(stmt);
} }
for excepthandler in handlers { for excepthandler in handlers {
visitor.visit_excepthandler(excepthandler) visitor.visit_excepthandler(excepthandler);
} }
for stmt in orelse { for stmt in orelse {
visitor.visit_stmt(stmt); 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) { pub fn walk_constant<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, constant: &'a Constant) {
if let Constant::Tuple(constants) = constant { if let Constant::Tuple(constants) = constant {
for constant in constants { for constant in constants {
visitor.visit_constant(constant) visitor.visit_constant(constant);
} }
} }
} }

View file

@ -100,7 +100,6 @@ fn apply_fixes<'a>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use anyhow::Result;
use rustpython_parser::ast::Location; use rustpython_parser::ast::Location;
use crate::autofix::fixer::apply_fixes; use crate::autofix::fixer::apply_fixes;
@ -108,18 +107,16 @@ mod tests {
use crate::SourceCodeLocator; use crate::SourceCodeLocator;
#[test] #[test]
fn empty_file() -> Result<()> { fn empty_file() {
let fixes = vec![]; let fixes = vec![];
let locator = SourceCodeLocator::new(r#""#); let locator = SourceCodeLocator::new(r#""#);
let (contents, fixed) = apply_fixes(fixes.iter(), &locator); let (contents, fixed) = apply_fixes(fixes.iter(), &locator);
assert_eq!(contents, ""); assert_eq!(contents, "");
assert_eq!(fixed, 0); assert_eq!(fixed, 0);
Ok(())
} }
#[test] #[test]
fn apply_single_replacement() -> Result<()> { fn apply_single_replacement() {
let fixes = vec![Fix { let fixes = vec![Fix {
patch: Patch { patch: Patch {
content: "Bar".to_string(), content: "Bar".to_string(),
@ -144,12 +141,10 @@ class A(Bar):
.trim(), .trim(),
); );
assert_eq!(fixed, 1); assert_eq!(fixed, 1);
Ok(())
} }
#[test] #[test]
fn apply_single_removal() -> Result<()> { fn apply_single_removal() {
let fixes = vec![Fix { let fixes = vec![Fix {
patch: Patch { patch: Patch {
content: String::new(), content: String::new(),
@ -174,12 +169,10 @@ class A:
.trim() .trim()
); );
assert_eq!(fixed, 1); assert_eq!(fixed, 1);
Ok(())
} }
#[test] #[test]
fn apply_double_removal() -> Result<()> { fn apply_double_removal() {
let fixes = vec![ let fixes = vec![
Fix { Fix {
patch: Patch { patch: Patch {
@ -214,12 +207,10 @@ class A:
.trim() .trim()
); );
assert_eq!(fixed, 2); assert_eq!(fixed, 2);
Ok(())
} }
#[test] #[test]
fn ignore_overlapping_fixes() -> Result<()> { fn ignore_overlapping_fixes() {
let fixes = vec![ let fixes = vec![
Fix { Fix {
patch: Patch { patch: Patch {
@ -253,7 +244,5 @@ class A:
.trim(), .trim(),
); );
assert_eq!(fixed, 1); assert_eq!(fixed, 1);
Ok(())
} }
} }

View file

@ -178,6 +178,6 @@ pub fn set(
cache_key(path, settings, autofix), cache_key(path, settings, autofix),
&bincode::serialize(&check_result).unwrap(), &bincode::serialize(&check_result).unwrap(),
) { ) {
error!("Failed to write to cache: {e:?}") error!("Failed to write to cache: {e:?}");
} }
} }

View file

@ -534,20 +534,20 @@ where
self.check_builtin_shadowing(name, Range::from_located(stmt), false); self.check_builtin_shadowing(name, Range::from_located(stmt), false);
for expr in bases { for expr in bases {
self.visit_expr(expr) self.visit_expr(expr);
} }
for keyword in keywords { for keyword in keywords {
self.visit_keyword(keyword) self.visit_keyword(keyword);
} }
for expr in decorator_list { for expr in decorator_list {
self.visit_expr(expr) self.visit_expr(expr);
} }
self.push_scope(Scope::new(ScopeKind::Class(ClassScope { self.push_scope(Scope::new(ScopeKind::Class(ClassScope {
name, name,
bases, bases,
keywords, keywords,
decorator_list, decorator_list,
}))) })));
} }
StmtKind::Import { names } => { StmtKind::Import { names } => {
if self.settings.enabled.contains(&CheckCode::E402) { if self.settings.enabled.contains(&CheckCode::E402) {
@ -576,7 +576,7 @@ where
used: None, used: None,
range: Range::from_located(stmt), range: Range::from_located(stmt),
}, },
) );
} else { } else {
if let Some(asname) = &alias.node.asname { if let Some(asname) = &alias.node.asname {
self.check_builtin_shadowing(asname, Range::from_located(stmt), false); self.check_builtin_shadowing(asname, Range::from_located(stmt), false);
@ -616,7 +616,7 @@ where
}, },
range: Range::from_located(stmt), range: Range::from_located(stmt),
}, },
) );
} }
if let Some(asname) = &alias.node.asname { if let Some(asname) = &alias.node.asname {
@ -692,7 +692,7 @@ where
.iter() .iter()
.filter(|alias| alias.node.asname.is_none()) .filter(|alias| alias.node.asname.is_none())
.map(|alias| alias.node.name.as_str()), .map(|alias| alias.node.name.as_str()),
) );
} }
for alias in names { for alias in names {
if let Some(asname) = &alias.node.asname { if let Some(asname) = &alias.node.asname {
@ -835,7 +835,7 @@ where
}, },
range: Range::from_located(stmt), range: Range::from_located(stmt),
}, },
) );
} }
if self.settings.enabled.contains(&CheckCode::I252) { if self.settings.enabled.contains(&CheckCode::I252) {
@ -979,7 +979,7 @@ where
StmtKind::Assign { targets, value, .. } => { StmtKind::Assign { targets, value, .. } => {
if self.settings.enabled.contains(&CheckCode::E731) { if self.settings.enabled.contains(&CheckCode::E731) {
if let [target] = &targets[..] { 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) { if self.settings.enabled.contains(&CheckCode::U001) {
@ -1016,7 +1016,7 @@ where
StmtKind::Delete { .. } => {} StmtKind::Delete { .. } => {}
StmtKind::Expr { value, .. } => { StmtKind::Expr { value, .. } => {
if self.settings.enabled.contains(&CheckCode::B015) { 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(); self.except_handlers.pop();
for excepthandler in handlers { for excepthandler in handlers {
self.visit_excepthandler(excepthandler) self.visit_excepthandler(excepthandler);
} }
for stmt in orelse { for stmt in orelse {
self.visit_stmt(stmt); self.visit_stmt(stmt);
@ -1620,7 +1620,7 @@ where
comparators, comparators,
check_none_comparisons, check_none_comparisons,
check_true_false_comparisons, check_true_false_comparisons,
) );
} }
if self.settings.enabled.contains(&CheckCode::F632) { if self.settings.enabled.contains(&CheckCode::F632) {
@ -1717,7 +1717,7 @@ where
for expr in &args.defaults { for expr in &args.defaults {
self.visit_expr(expr); 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 } => { ExprKind::ListComp { elt, generators } | ExprKind::SetComp { elt, generators } => {
if self.settings.enabled.contains(&CheckCode::C416) { if self.settings.enabled.contains(&CheckCode::C416) {
@ -1732,10 +1732,10 @@ where
self.add_check(check); self.add_check(check);
}; };
} }
self.push_scope(Scope::new(ScopeKind::Generator)) self.push_scope(Scope::new(ScopeKind::Generator));
} }
ExprKind::GeneratorExp { .. } | ExprKind::DictComp { .. } => { ExprKind::GeneratorExp { .. } | ExprKind::DictComp { .. } => {
self.push_scope(Scope::new(ScopeKind::Generator)) self.push_scope(Scope::new(ScopeKind::Generator));
} }
_ => {} _ => {}
}; };
@ -1894,7 +1894,7 @@ where
error!( error!(
"Found non-ExprKind::Tuple argument to PEP 593 \ "Found non-ExprKind::Tuple argument to PEP 593 \
Annotation." Annotation."
) );
} }
} }
} }
@ -2014,10 +2014,10 @@ where
.extend(pyflakes::checks::duplicate_arguments(arguments)); .extend(pyflakes::checks::duplicate_arguments(arguments));
} }
if self.settings.enabled.contains(&CheckCode::B006) { 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) { 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 // flake8-boolean-trap
@ -2310,7 +2310,7 @@ impl<'a> Checker<'a> {
self.add_check(Check::new( self.add_check(Check::new(
CheckKind::UndefinedName(id.clone()), CheckKind::UndefinedName(id.clone()),
Range::from_located(expr), Range::from_located(expr),
)) ));
} }
} }
} }
@ -2339,20 +2339,22 @@ impl<'a> Checker<'a> {
.get(id) .get(id)
.map_or(false, |binding| matches!(binding.kind, BindingKind::Global)) .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 self.settings.enabled.contains(&CheckCode::N815) {
if matches!(self.current_scope().kind, ScopeKind::Class(..)) { 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 self.settings.enabled.contains(&CheckCode::N816) {
if matches!(self.current_scope().kind, ScopeKind::Module) { 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( self.add_check(Check::new(
CheckKind::UndefinedName(id.to_string()), CheckKind::UndefinedName(id.to_string()),
Range::from_located(expr), Range::from_located(expr),
)) ));
} }
} }
} }

View file

@ -101,7 +101,7 @@ pub fn check_lines(
match noqa { match noqa {
(Directive::All(..), matches) => { (Directive::All(..), matches) => {
matches.push(check.kind.code().as_ref()); matches.push(check.kind.code().as_ref());
ignored.push(index) ignored.push(index);
} }
(Directive::Codes(.., codes), matches) => { (Directive::Codes(.., codes), matches) => {
if codes.contains(&check.kind.code().as_ref()) { if codes.contains(&check.kind.code().as_ref()) {

View file

@ -2155,13 +2155,12 @@ impl Check {
mod tests { mod tests {
use std::str::FromStr; use std::str::FromStr;
use anyhow::Result;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use crate::checks::CheckCode; use crate::checks::CheckCode;
#[test] #[test]
fn check_code_serialization() -> Result<()> { fn check_code_serialization() {
for check_code in CheckCode::iter() { for check_code in CheckCode::iter() {
assert!( assert!(
CheckCode::from_str(check_code.as_ref()).is_ok(), CheckCode::from_str(check_code.as_ref()).is_ok(),
@ -2169,6 +2168,5 @@ mod tests {
check_code check_code
); );
} }
Ok(())
} }
} }

View file

@ -254,7 +254,7 @@ impl SourceGenerator {
}); });
self.p("= "); self.p("= ");
self.unparse_expr(value, precedence::EXPR); self.unparse_expr(value, precedence::EXPR);
}) });
} }
StmtKind::AnnAssign { StmtKind::AnnAssign {
target, target,
@ -273,7 +273,7 @@ impl SourceGenerator {
self.p(" = "); self.p(" = ");
self.unparse_expr(value, precedence::EXPR); self.unparse_expr(value, precedence::EXPR);
} }
}) });
} }
StmtKind::For { StmtKind::For {
target, target,
@ -440,7 +440,7 @@ impl SourceGenerator {
self.p(", "); self.p(", ");
self.unparse_expr(msg, precedence::TEST); self.unparse_expr(msg, precedence::TEST);
} }
}) });
} }
StmtKind::Import { names } => { StmtKind::Import { names } => {
statement!({ statement!({
@ -471,7 +471,7 @@ impl SourceGenerator {
self.p_delim(&mut first, ", "); self.p_delim(&mut first, ", ");
self.unparse_alias(alias); self.unparse_alias(alias);
} }
}) });
} }
StmtKind::Global { names } => { StmtKind::Global { names } => {
statement!({ statement!({
@ -566,14 +566,14 @@ impl SourceGenerator {
self.p_delim(&mut first, op); self.p_delim(&mut first, op);
self.unparse_expr(val, prec + 1); self.unparse_expr(val, prec + 1);
} }
}) });
} }
ExprKind::NamedExpr { target, value } => { ExprKind::NamedExpr { target, value } => {
group_if!(precedence::TUPLE, { group_if!(precedence::TUPLE, {
self.unparse_expr(target, precedence::ATOM); self.unparse_expr(target, precedence::ATOM);
self.p(" := "); self.p(" := ");
self.unparse_expr(value, precedence::ATOM); self.unparse_expr(value, precedence::ATOM);
}) });
} }
ExprKind::BinOp { left, op, right } => { ExprKind::BinOp { left, op, right } => {
let rassoc = matches!(op, Operator::Pow); let rassoc = matches!(op, Operator::Pow);
@ -599,7 +599,7 @@ impl SourceGenerator {
self.unparse_expr(left, prec + u8::from(rassoc)); self.unparse_expr(left, prec + u8::from(rassoc));
self.p(op); self.p(op);
self.unparse_expr(right, prec + u8::from(!rassoc)); self.unparse_expr(right, prec + u8::from(!rassoc));
}) });
} }
ExprKind::UnaryOp { op, operand } => { ExprKind::UnaryOp { op, operand } => {
let (op, prec) = opprec!( let (op, prec) = opprec!(
@ -614,7 +614,7 @@ impl SourceGenerator {
group_if!(prec, { group_if!(prec, {
self.p(op); self.p(op);
self.unparse_expr(operand, prec); self.unparse_expr(operand, prec);
}) });
} }
ExprKind::Lambda { args, body } => { ExprKind::Lambda { args, body } => {
group_if!(precedence::TEST, { group_if!(precedence::TEST, {
@ -622,7 +622,7 @@ impl SourceGenerator {
self.p(if npos > 0 { "lambda " } else { "lambda" }); self.p(if npos > 0 { "lambda " } else { "lambda" });
self.unparse_args(args); self.unparse_args(args);
write!(self, ": {}", **body); write!(self, ": {}", **body);
}) });
} }
ExprKind::IfExp { test, body, orelse } => { ExprKind::IfExp { test, body, orelse } => {
group_if!(precedence::TEST, { group_if!(precedence::TEST, {
@ -631,7 +631,7 @@ impl SourceGenerator {
self.unparse_expr(test, precedence::TEST + 1); self.unparse_expr(test, precedence::TEST + 1);
self.p(" else "); self.p(" else ");
self.unparse_expr(orelse, precedence::TEST); self.unparse_expr(orelse, precedence::TEST);
}) });
} }
ExprKind::Dict { keys, values } => { ExprKind::Dict { keys, values } => {
self.p("{"); self.p("{");
@ -694,7 +694,7 @@ impl SourceGenerator {
group_if!(precedence::AWAIT, { group_if!(precedence::AWAIT, {
self.p("await "); self.p("await ");
self.unparse_expr(value, precedence::ATOM); self.unparse_expr(value, precedence::ATOM);
}) });
} }
ExprKind::Yield { value } => { ExprKind::Yield { value } => {
if let Some(value) = value { if let Some(value) = value {
@ -730,7 +730,7 @@ impl SourceGenerator {
self.p(op); self.p(op);
self.unparse_expr(cmp, new_lvl); self.unparse_expr(cmp, new_lvl);
} }
}) });
} }
ExprKind::Call { ExprKind::Call {
func, func,
@ -813,7 +813,7 @@ impl SourceGenerator {
.iter() .iter()
.any(|expr| matches!(expr.node, ExprKind::Starred { .. })) .any(|expr| matches!(expr.node, ExprKind::Starred { .. }))
{ {
lvl += 1 lvl += 1;
} }
} }
self.p("["); self.p("[");
@ -845,7 +845,7 @@ impl SourceGenerator {
self.unparse_expr(elt, precedence::TEST); self.unparse_expr(elt, precedence::TEST);
} }
self.p_if(elts.len() == 1, ","); self.p_if(elts.len() == 1, ",");
}) });
} }
} }
ExprKind::Slice { lower, upper, step } => { ExprKind::Slice { lower, upper, step } => {
@ -962,7 +962,7 @@ impl SourceGenerator {
match &expr.node { match &expr.node {
ExprKind::Constant { value, .. } => { ExprKind::Constant { value, .. } => {
if let Constant::Str(s) = value { if let Constant::Str(s) = value {
self.unparse_fstring_str(s) self.unparse_fstring_str(s);
} else { } else {
unreachable!() unreachable!()
} }

View file

@ -113,6 +113,7 @@ pub fn extract_isort_exclusions(lxr: &[LexResult], locator: &SourceCodeLocator)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use nohash_hasher::IntMap; use nohash_hasher::IntMap;
use rustpython_parser::lexer; use rustpython_parser::lexer;
use rustpython_parser::lexer::LexResult; use rustpython_parser::lexer::LexResult;

View file

@ -65,7 +65,7 @@ fn duplicate_handler_exceptions<'a>(
content, content,
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
} }
checker.add_check(check); checker.add_check(check);

View file

@ -60,9 +60,9 @@ where
self.checks.push(( self.checks.push((
CheckKind::FunctionCallArgumentDefault(compose_call_path(expr)), CheckKind::FunctionCallArgumentDefault(compose_call_path(expr)),
Range::from_located(expr), Range::from_located(expr),
)) ));
} }
visitor::walk_expr(self, expr) visitor::walk_expr(self, expr);
} }
ExprKind::Lambda { .. } => {} ExprKind::Lambda { .. } => {}
_ => visitor::walk_expr(self, expr), _ => visitor::walk_expr(self, expr),

View file

@ -78,7 +78,7 @@ pub fn redundant_tuple_in_exception_handler(checker: &mut Checker, handlers: &[E
} }
} }
} }
checker.add_check(check) checker.add_check(check);
} }
} }
} }

View file

@ -30,7 +30,7 @@ fn assignment(obj: &Expr, name: &str, value: &Expr) -> Result<String> {
); );
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
generator.unparse_stmt(&stmt); generator.unparse_stmt(&stmt);
generator.generate().map_err(|e| e.into()) generator.generate().map_err(std::convert::Into::into)
} }
/// B010 /// B010

View file

@ -12,7 +12,7 @@ pub fn unary_prefix_increment(checker: &mut Checker, expr: &Expr, op: &Unaryop,
checker.add_check(Check::new( checker.add_check(Check::new(
CheckKind::UnaryPrefixIncrement, CheckKind::UnaryPrefixIncrement,
Range::from_located(expr), Range::from_located(expr),
)) ));
} }
} }
} }

View file

@ -71,7 +71,7 @@ pub fn unused_loop_control_variable(checker: &mut Checker, target: &Expr, body:
format!("_{name}"), format!("_{name}"),
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
checker.add_check(check); checker.add_check(check);
} }

View file

@ -722,7 +722,7 @@ pub fn fix_unnecessary_call_around_sorted(
rpar: inner_call.rpar.clone(), rpar: inner_call.rpar.clone(),
whitespace_after_func: inner_call.whitespace_after_func.clone(), whitespace_after_func: inner_call.whitespace_after_func.clone(),
whitespace_before_args: inner_call.whitespace_before_args.clone(), whitespace_before_args: inner_call.whitespace_before_args.clone(),
})) }));
} }
} }
@ -766,7 +766,7 @@ pub fn fix_unnecessary_comprehension(
rpar: vec![], rpar: vec![],
whitespace_after_func: ParenthesizableWhitespace::default(), whitespace_after_func: ParenthesizableWhitespace::default(),
whitespace_before_args: ParenthesizableWhitespace::default(), whitespace_before_args: ParenthesizableWhitespace::default(),
})) }));
} }
Expression::SetComp(inner) => { Expression::SetComp(inner) => {
body.value = Expression::Call(Box::new(Call { body.value = Expression::Call(Box::new(Call {
@ -788,7 +788,7 @@ pub fn fix_unnecessary_comprehension(
rpar: vec![], rpar: vec![],
whitespace_after_func: ParenthesizableWhitespace::default(), whitespace_after_func: ParenthesizableWhitespace::default(),
whitespace_before_args: ParenthesizableWhitespace::default(), whitespace_before_args: ParenthesizableWhitespace::default(),
})) }));
} }
_ => { _ => {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(

View file

@ -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" { if fix.patch.content.is_empty() || fix.patch.content == "pass" {
checker.deletions.insert(context.defined_by); checker.deletions.insert(context.defined_by);
} }
check.amend(fix) check.amend(fix);
} }
Err(e) => error!("Failed to remove print call: {}", e), Err(e) => error!("Failed to remove print call: {}", e),
} }

View file

@ -128,7 +128,7 @@ fn annotate_imports<'a>(
asname: alias.node.asname.as_ref(), asname: alias.node.asname.as_ref(),
atop: alias_atop, atop: alias_atop,
inline: alias_inline, inline: alias_inline,
}) });
} }
annotated.push(AnnotatedImport::ImportFrom { annotated.push(AnnotatedImport::ImportFrom {

View file

@ -142,7 +142,7 @@ where
finalbody, finalbody,
} => { } => {
for excepthandler in handlers { for excepthandler in handlers {
self.visit_excepthandler(excepthandler) self.visit_excepthandler(excepthandler);
} }
for stmt in body { for stmt in body {

View file

@ -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; use std::path::Path;

View file

@ -100,7 +100,7 @@ pub(crate) fn check_path(
location: parse_error.location, location: parse_error.location,
end_location: parse_error.location, end_location: parse_error.location,
}, },
)) ));
} }
} }
} }

View file

@ -53,7 +53,7 @@ pub fn set_up_logging(level: &LogLevel) -> Result<()> {
record.target(), record.target(),
record.level(), record.level(),
message message
)) ));
}) })
.level(level.level_filter()) .level(level.level_filter())
.chain(std::io::stdout()) .chain(std::io::stdout())

View file

@ -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::io::{self, Read};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::ExitCode; use std::process::ExitCode;

View file

@ -120,6 +120,7 @@ fn add_noqa_inner(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use nohash_hasher::IntMap; use nohash_hasher::IntMap;
use rustpython_parser::ast::Location; use rustpython_parser::ast::Location;

View file

@ -70,7 +70,7 @@ impl<'a> Printer<'a> {
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
)? )?
) );
} }
SerializationFormat::Text => { SerializationFormat::Text => {
if self.log_level >= &LogLevel::Default { if self.log_level >= &LogLevel::Default {
@ -79,19 +79,19 @@ impl<'a> Printer<'a> {
"Found {} error(s) ({} fixed).", "Found {} error(s) ({} fixed).",
diagnostics.messages.len(), diagnostics.messages.len(),
diagnostics.fixed, diagnostics.fixed,
) );
} else if !diagnostics.messages.is_empty() { } 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 { for message in &diagnostics.messages {
println!("{message}") println!("{message}");
} }
if self.log_level >= &LogLevel::Default { if self.log_level >= &LogLevel::Default {
if num_fixable > 0 { 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!(); println!();
} }
for message in &diagnostics.messages { for message in &diagnostics.messages {
println!("{message}") println!("{message}");
} }
} }

View file

@ -157,7 +157,7 @@ pub fn invalid_escape_sequence(
location, location,
end_location, end_location,
}, },
)) ));
} }
} }
} }

View file

@ -1190,7 +1190,7 @@ fn common_section(
docstring.location.row() + context.original_index, docstring.location.row() + context.original_index,
section_name_start + section_name_length, section_name_start + section_name_length,
), ),
)) ));
} }
} }
checker.add_check(check); checker.add_check(check);
@ -1284,7 +1284,7 @@ fn common_section(
Location::new(docstring.location.row() + context.original_index, 0), 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(), .collect(),
) );
} }
fn parameters_section(checker: &mut Checker, definition: &Definition, context: &SectionContext) { 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);
} }
} }

View file

@ -164,7 +164,7 @@ pub fn repeated_keys(
checks.push(Check::new( checks.push(Check::new(
CheckKind::MultiValueRepeatedKeyLiteral, CheckKind::MultiValueRepeatedKeyLiteral,
Range::from_located(k2), Range::from_located(k2),
)) ));
} }
} }
(Some(DictionaryKey::Variable(v1)), Some(DictionaryKey::Variable(v2))) => { (Some(DictionaryKey::Variable(v1)), Some(DictionaryKey::Variable(v2))) => {
@ -172,7 +172,7 @@ pub fn repeated_keys(
checks.push(Check::new( checks.push(Check::new(
CheckKind::MultiValueRepeatedKeyVariable((*v2).to_string()), CheckKind::MultiValueRepeatedKeyVariable((*v2).to_string()),
Range::from_located(k2), Range::from_located(k2),
)) ));
} }
} }
_ => {} _ => {}

View file

@ -33,7 +33,7 @@ pub fn raise_not_implemented(checker: &mut Checker, expr: &Expr) {
"NotImplementedError".to_string(), "NotImplementedError".to_string(),
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
checker.add_check(check); checker.add_check(check);
} }

View file

@ -81,7 +81,7 @@ fn create_check(
content, content,
mode_param.location, mode_param.location,
mode_param.end_location.unwrap(), mode_param.end_location.unwrap(),
)) ));
} else { } else {
match create_remove_param_fix(locator, expr, mode_param) { match create_remove_param_fix(locator, expr, mode_param) {
Ok(fix) => check.amend(fix), Ok(fix) => check.amend(fix),

View file

@ -22,7 +22,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp
check.amend(fix); check.amend(fix);
} }
} }
checker.add_check(check) checker.add_check(check);
} }
} }
} }

View file

@ -96,7 +96,7 @@ fn replace_with_bytes_literal(
content, content,
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
check check
} }

View file

@ -72,7 +72,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
content, content,
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
} }
checker.add_check(check); checker.add_check(check);
@ -91,7 +91,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
content, content,
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)) ));
} }
} }
_ => { _ => {

View file

@ -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" { if fix.patch.content.is_empty() || fix.patch.content == "pass" {
checker.deletions.insert(context.defined_by); checker.deletions.insert(context.defined_by);
} }
check.amend(fix) check.amend(fix);
} }
Err(e) => error!("Failed to fix remove metaclass type: {}", e), Err(e) => error!("Failed to fix remove metaclass type: {}", e),
} }

View file

@ -82,7 +82,7 @@ pub fn convert_exit_to_sys_exit(checker: &mut Checker, func: &Expr) {
content, content,
func.location, func.location,
func.end_location.unwrap(), func.end_location.unwrap(),
)) ));
} }
} }
checker.add_check(check); checker.add_check(check);