From 5c6753e69ebda5ec796bcc32dc33cbe857817847 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 15 Jan 2023 02:32:36 -0500 Subject: [PATCH] Remove some Clippy allows (#1888) --- ruff_cli/src/main.rs | 4 ++-- ruff_cli/src/printer.rs | 3 +-- src/ast/helpers.rs | 3 +-- src/autofix/helpers.rs | 6 +++--- src/autofix/mod.rs | 2 +- src/flake8_to_ruff/converter.rs | 3 +-- src/linter.rs | 4 ++-- src/registry.rs | 13 ++++++------- src/rules/flake8_pytest_style/mod.rs | 2 +- src/rules/flake8_pytest_style/rules/parametrize.rs | 8 ++++---- src/rules/flake8_pytest_style/types.rs | 5 ++--- src/rules/isort/helpers.rs | 8 ++------ src/rules/pydocstyle/settings.rs | 3 +-- src/rules/pyupgrade/fixes.rs | 2 +- src/settings/pyproject.rs | 2 +- src/source_code/locator.rs | 6 ++---- 16 files changed, 31 insertions(+), 43 deletions(-) diff --git a/ruff_cli/src/main.rs b/ruff_cli/src/main.rs index 201bc49a64..50d2823c7b 100644 --- a/ruff_cli/src/main.rs +++ b/ruff_cli/src/main.rs @@ -200,7 +200,7 @@ pub fn main() -> Result { } // Perform an initial run instantly. - printer.clear_screen()?; + Printer::clear_screen()?; printer.write_to_user("Starting linter in watch mode...\n"); let messages = commands::run( @@ -230,7 +230,7 @@ pub fn main() -> Result { .unwrap_or_default() }); if py_changed { - printer.clear_screen()?; + Printer::clear_screen()?; printer.write_to_user("File change detected...\n"); let messages = commands::run( diff --git a/ruff_cli/src/printer.rs b/ruff_cli/src/printer.rs index d63b70a4e4..d7d25cfe21 100644 --- a/ruff_cli/src/printer.rs +++ b/ruff_cli/src/printer.rs @@ -303,8 +303,7 @@ impl<'a> Printer<'a> { } } - #[allow(clippy::unused_self)] - pub fn clear_screen(&self) -> Result<()> { + pub fn clear_screen() -> Result<()> { #[cfg(not(target_family = "wasm"))] clearscreen::clear()?; Ok(()) diff --git a/src/ast/helpers.rs b/src/ast/helpers.rs index e030b2caba..21be4bce03 100644 --- a/src/ast/helpers.rs +++ b/src/ast/helpers.rs @@ -426,7 +426,7 @@ pub fn match_trailing_content(stmt: &Stmt, locator: &Locator) -> bool { /// Return the number of trailing empty lines following a statement. pub fn count_trailing_lines(stmt: &Stmt, locator: &Locator) -> usize { let suffix = - locator.slice_source_code_at(&Location::new(stmt.end_location.unwrap().row() + 1, 0)); + locator.slice_source_code_at(Location::new(stmt.end_location.unwrap().row() + 1, 0)); suffix .lines() .take_while(|line| line.trim().is_empty()) @@ -697,7 +697,6 @@ impl<'a> SimpleCallArgs<'a> { } /// Get the number of positional and keyword arguments used. - #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.args.len() + self.kwargs.len() } diff --git a/src/autofix/helpers.rs b/src/autofix/helpers.rs index e513398502..b6381dbe33 100644 --- a/src/autofix/helpers.rs +++ b/src/autofix/helpers.rs @@ -79,7 +79,7 @@ fn is_lone_child(child: &Stmt, parent: &Stmt, deleted: &[&Stmt]) -> Result /// Return the location of a trailing semicolon following a `Stmt`, if it's part /// of a multi-statement line. fn trailing_semicolon(stmt: &Stmt, locator: &Locator) -> Option { - let contents = locator.slice_source_code_at(&stmt.end_location.unwrap()); + let contents = locator.slice_source_code_at(stmt.end_location.unwrap()); for (row, line) in LinesWithTrailingNewline::from(&contents).enumerate() { let trimmed = line.trim(); if trimmed.starts_with(';') { @@ -102,7 +102,7 @@ fn trailing_semicolon(stmt: &Stmt, locator: &Locator) -> Option { /// Find the next valid break for a `Stmt` after a semicolon. fn next_stmt_break(semicolon: Location, locator: &Locator) -> Location { let start_location = Location::new(semicolon.row(), semicolon.column() + 1); - let contents = locator.slice_source_code_at(&start_location); + let contents = locator.slice_source_code_at(start_location); for (row, line) in LinesWithTrailingNewline::from(&contents).enumerate() { let trimmed = line.trim(); // Skip past any continuations. @@ -134,7 +134,7 @@ fn next_stmt_break(semicolon: Location, locator: &Locator) -> Location { /// Return `true` if a `Stmt` occurs at the end of a file. fn is_end_of_file(stmt: &Stmt, locator: &Locator) -> bool { - let contents = locator.slice_source_code_at(&stmt.end_location.unwrap()); + let contents = locator.slice_source_code_at(stmt.end_location.unwrap()); contents.is_empty() } diff --git a/src/autofix/mod.rs b/src/autofix/mod.rs index 3f70689213..9a02b3278e 100644 --- a/src/autofix/mod.rs +++ b/src/autofix/mod.rs @@ -66,7 +66,7 @@ fn apply_fixes<'a>( } // Add the remaining content. - let slice = locator.slice_source_code_at(&last_pos); + let slice = locator.slice_source_code_at(last_pos); output.append(&slice); (Cow::from(output.finish()), num_fixed) diff --git a/src/flake8_to_ruff/converter.rs b/src/flake8_to_ruff/converter.rs index 0a20532a57..1c2b5bbf19 100644 --- a/src/flake8_to_ruff/converter.rs +++ b/src/flake8_to_ruff/converter.rs @@ -21,7 +21,6 @@ use crate::settings::options::Options; use crate::settings::pyproject::Pyproject; use crate::warn_user; -#[allow(clippy::unnecessary_wraps)] pub fn convert( config: &HashMap>>, black: Option<&Black>, @@ -272,7 +271,7 @@ pub fn convert( match value.trim() { "csv" => { flake8_pytest_style.parametrize_names_type = - Some(ParametrizeNameType::CSV); + Some(ParametrizeNameType::Csv); } "tuple" => { flake8_pytest_style.parametrize_names_type = diff --git a/src/linter.rs b/src/linter.rs index 458acea5df..1a38d53f2a 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -66,7 +66,7 @@ pub fn check_path( let use_ast = settings .enabled .iter() - .any(|rule_code| matches!(rule_code.lint_source(), LintSource::AST)); + .any(|rule_code| matches!(rule_code.lint_source(), LintSource::Ast)); let use_imports = !directives.isort.skip_file && settings .enabled @@ -142,7 +142,7 @@ pub fn check_path( || settings .enabled .iter() - .any(|rule_code| matches!(rule_code.lint_source(), LintSource::NoQA)) + .any(|rule_code| matches!(rule_code.lint_source(), LintSource::NoQa)) { check_noqa( &mut diagnostics, diff --git a/src/registry.rs b/src/registry.rs index 3456da7796..51467ce9b7 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -694,14 +694,13 @@ impl RuleOrigin { } } -#[allow(clippy::upper_case_acronyms)] pub enum LintSource { - AST, - FileSystem, + Ast, + Io, Lines, Tokens, Imports, - NoQA, + NoQa, } impl RuleCode { @@ -709,7 +708,7 @@ impl RuleCode { /// physical lines). pub fn lint_source(&self) -> &'static LintSource { match self { - RuleCode::RUF100 => &LintSource::NoQA, + RuleCode::RUF100 => &LintSource::NoQa, RuleCode::E501 | RuleCode::W292 | RuleCode::W505 @@ -727,9 +726,9 @@ impl RuleCode { | RuleCode::RUF001 | RuleCode::RUF002 | RuleCode::RUF003 => &LintSource::Tokens, - RuleCode::E902 => &LintSource::FileSystem, + RuleCode::E902 => &LintSource::Io, RuleCode::I001 | RuleCode::I002 => &LintSource::Imports, - _ => &LintSource::AST, + _ => &LintSource::Ast, } } } diff --git a/src/rules/flake8_pytest_style/mod.rs b/src/rules/flake8_pytest_style/mod.rs index 2edbb2956e..71d10af286 100644 --- a/src/rules/flake8_pytest_style/mod.rs +++ b/src/rules/flake8_pytest_style/mod.rs @@ -35,7 +35,7 @@ mod tests { RuleCode::PT006, Path::new("PT006.py"), Settings { - parametrize_names_type: types::ParametrizeNameType::CSV, + parametrize_names_type: types::ParametrizeNameType::Csv, ..Settings::default() }, "PT006_csv"; diff --git a/src/rules/flake8_pytest_style/rules/parametrize.rs b/src/rules/flake8_pytest_style/rules/parametrize.rs index 75ed15a79e..45b1af50c9 100644 --- a/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -139,7 +139,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } checker.diagnostics.push(diagnostic); } - types::ParametrizeNameType::CSV => {} + types::ParametrizeNameType::Csv => {} } } } @@ -173,7 +173,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } checker.diagnostics.push(diagnostic); } - types::ParametrizeNameType::CSV => { + types::ParametrizeNameType::Csv => { let mut diagnostic = Diagnostic::new( violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), @@ -222,7 +222,7 @@ fn check_names(checker: &mut Checker, expr: &Expr) { } checker.diagnostics.push(diagnostic); } - types::ParametrizeNameType::CSV => { + types::ParametrizeNameType::Csv => { let mut diagnostic = Diagnostic::new( violations::ParametrizeNamesWrongType(names_type), Range::from_located(expr), @@ -279,7 +279,7 @@ fn check_values(checker: &mut Checker, expr: &Expr) { fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) { let mut diagnostic = Diagnostic::new( - violations::ParametrizeNamesWrongType(types::ParametrizeNameType::CSV), + violations::ParametrizeNamesWrongType(types::ParametrizeNameType::Csv), Range::from_located(expr), ); diff --git a/src/rules/flake8_pytest_style/types.rs b/src/rules/flake8_pytest_style/types.rs index 7ef8ec7da1..0b5aa044c7 100644 --- a/src/rules/flake8_pytest_style/types.rs +++ b/src/rules/flake8_pytest_style/types.rs @@ -4,10 +4,9 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[allow(clippy::upper_case_acronyms)] pub enum ParametrizeNameType { #[serde(rename = "csv")] - CSV, + Csv, #[serde(rename = "tuple")] Tuple, #[serde(rename = "list")] @@ -23,7 +22,7 @@ impl Default for ParametrizeNameType { impl Display for ParametrizeNameType { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - Self::CSV => write!(f, "csv"), + Self::Csv => write!(f, "csv"), Self::Tuple => write!(f, "tuple"), Self::List => write!(f, "list"), } diff --git a/src/rules/isort/helpers.rs b/src/rules/isort/helpers.rs index da93c8cd8c..ebe09bd962 100644 --- a/src/rules/isort/helpers.rs +++ b/src/rules/isort/helpers.rs @@ -63,11 +63,7 @@ pub fn has_comment_break(stmt: &Stmt, locator: &Locator) -> bool { // # Direct comment. // def f(): pass let mut seen_blank = false; - for line in locator - .slice_source_code_until(&stmt.location) - .lines() - .rev() - { + for line in locator.slice_source_code_until(stmt.location).lines().rev() { let line = line.trim(); if seen_blank { if line.starts_with('#') { @@ -113,7 +109,7 @@ pub fn find_splice_location(body: &[Stmt], locator: &Locator) -> Location { let mut splice = match_docstring_end(body).unwrap_or_default(); // Find the first token that isn't a comment or whitespace. - let contents = locator.slice_source_code_at(&splice); + let contents = locator.slice_source_code_at(splice); for (.., tok, end) in lexer::make_tokenizer(&contents).flatten() { if matches!(tok, Tok::Comment(..) | Tok::Newline) { splice = end; diff --git a/src/rules/pydocstyle/settings.rs b/src/rules/pydocstyle/settings.rs index 16292d4098..27c4668bd1 100644 --- a/src/rules/pydocstyle/settings.rs +++ b/src/rules/pydocstyle/settings.rs @@ -18,8 +18,7 @@ pub enum Convention { } impl Convention { - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn codes(&self) -> &'static [RuleCodePrefix] { + pub fn codes(self) -> &'static [RuleCodePrefix] { match self { Convention::Google => &[ // All errors except D203, D204, D213, D215, D400, D401, D404, D406, D407, D408, diff --git a/src/rules/pyupgrade/fixes.rs b/src/rules/pyupgrade/fixes.rs index 89a843d9c8..22a4c03da0 100644 --- a/src/rules/pyupgrade/fixes.rs +++ b/src/rules/pyupgrade/fixes.rs @@ -17,7 +17,7 @@ pub fn remove_class_def_base( bases: &[Expr], keywords: &[Keyword], ) -> Option { - let contents = locator.slice_source_code_at(&stmt_at); + let contents = locator.slice_source_code_at(stmt_at); // Case 1: `object` is the only base. if bases.len() == 1 && keywords.is_empty() { diff --git a/src/settings/pyproject.rs b/src/settings/pyproject.rs index 98700e1609..7d1aeab9e6 100644 --- a/src/settings/pyproject.rs +++ b/src/settings/pyproject.rs @@ -550,7 +550,7 @@ other-attribute = 1 flake8_pytest_style: Some(flake8_pytest_style::settings::Options { fixture_parentheses: Some(false), parametrize_names_type: Some( - flake8_pytest_style::types::ParametrizeNameType::CSV + flake8_pytest_style::types::ParametrizeNameType::Csv ), parametrize_values_type: Some( flake8_pytest_style::types::ParametrizeValuesType::Tuple, diff --git a/src/source_code/locator.rs b/src/source_code/locator.rs index 949b16976c..e93c0f7cf3 100644 --- a/src/source_code/locator.rs +++ b/src/source_code/locator.rs @@ -25,15 +25,13 @@ impl<'a> Locator<'a> { self.rope.get_or_init(|| Rope::from_str(self.contents)) } - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn slice_source_code_at(&self, location: &Location) -> Cow<'_, str> { + pub fn slice_source_code_at(&self, location: Location) -> Cow<'_, str> { let rope = self.get_or_init_rope(); let offset = rope.line_to_char(location.row() - 1) + location.column(); Cow::from(rope.slice(offset..)) } - #[allow(clippy::trivially_copy_pass_by_ref)] - pub fn slice_source_code_until(&self, location: &Location) -> Cow<'_, str> { + pub fn slice_source_code_until(&self, location: Location) -> Cow<'_, str> { let rope = self.get_or_init_rope(); let offset = rope.line_to_char(location.row() - 1) + location.column(); Cow::from(rope.slice(..offset))