From 1939eeda162f673b396dd1865f7dc2b2af9fa304 Mon Sep 17 00:00:00 2001 From: augustelalande Date: Sun, 18 Feb 2024 18:41:08 -0500 Subject: [PATCH] linting --- crates/ruff_linter/src/checkers/tokens.rs | 5 +++-- .../rules/missing_class_newline.rs | 22 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/ruff_linter/src/checkers/tokens.rs b/crates/ruff_linter/src/checkers/tokens.rs index 1a0e273bbd178..4e0c174a54f21 100644 --- a/crates/ruff_linter/src/checkers/tokens.rs +++ b/crates/ruff_linter/src/checkers/tokens.rs @@ -15,8 +15,9 @@ use crate::directives::TodoComment; use crate::registry::{AsRule, Rule}; use crate::rules::pycodestyle::rules::BlankLinesChecker; use crate::rules::{ - eradicate, flake8_class_newline, flake8_commas, flake8_executable, flake8_fixme, flake8_implicit_str_concat, - flake8_pyi, flake8_quotes, flake8_todos, pycodestyle, pygrep_hooks, pylint, pyupgrade, ruff, + eradicate, flake8_class_newline, flake8_commas, flake8_executable, flake8_fixme, + flake8_implicit_str_concat, flake8_pyi, flake8_quotes, flake8_todos, pycodestyle, pygrep_hooks, + pylint, pyupgrade, ruff, }; use crate::settings::LinterSettings; diff --git a/crates/ruff_linter/src/rules/flake8_class_newline/rules/missing_class_newline.rs b/crates/ruff_linter/src/rules/flake8_class_newline/rules/missing_class_newline.rs index adf263f13b4b6..fe5b9f42ae7b8 100644 --- a/crates/ruff_linter/src/rules/flake8_class_newline/rules/missing_class_newline.rs +++ b/crates/ruff_linter/src/rules/flake8_class_newline/rules/missing_class_newline.rs @@ -5,11 +5,10 @@ use ruff_diagnostics::Fix; use ruff_macros::{derive_message_formats, violation}; use ruff_python_codegen::Stylist; use ruff_python_parser::lexer::LexResult; -use ruff_source_file::{Locator}; +use ruff_source_file::Locator; use crate::line_width::IndentWidth; -use crate::rules::pycodestyle::rules::{ - LogicalLineInfo, LogicalLineKind, LinePreprocessor}; +use crate::rules::pycodestyle::rules::{LinePreprocessor, LogicalLineInfo, LogicalLineKind}; /// ## What it does /// Checks for a missing blank line between a class definition and its first method. @@ -50,7 +49,6 @@ impl AlwaysFixableViolation for MissingClassNewLine { } } - #[derive(Copy, Clone, Debug, Default)] enum Follows { #[default] @@ -58,7 +56,6 @@ enum Follows { Other, } - /// Contains variables used for the linting of blank lines. #[derive(Debug, Default)] pub(crate) struct BlankLinesChecker { @@ -81,7 +78,7 @@ impl BlankLinesChecker { &logical_line, locator, stylist, - diagnostics + diagnostics, ); } } @@ -93,11 +90,14 @@ impl BlankLinesChecker { stylist: &Stylist, diagnostics: &mut Vec, ) { - if (matches!(self.follows, Follows::Class) && matches!(line.kind, LogicalLineKind::Function | LogicalLineKind::Decorator) && line.preceding_blank_lines == 0) { - let mut diagnostic = Diagnostic::new( - MissingClassNewLine, - line.first_token_range - ); + if (matches!(self.follows, Follows::Class) + && matches!( + line.kind, + LogicalLineKind::Function | LogicalLineKind::Decorator + ) + && line.preceding_blank_lines == 0) + { + let mut diagnostic = Diagnostic::new(MissingClassNewLine, line.first_token_range); diagnostic.set_fix(Fix::safe_edit(Edit::insertion( stylist.line_ending().to_string(), locator.line_start(line.first_token_range.start()),