Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande committed Feb 18, 2024
1 parent ee3e433 commit 1939eed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions crates/ruff_linter/src/checkers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,15 +49,13 @@ impl AlwaysFixableViolation for MissingClassNewLine {
}
}


#[derive(Copy, Clone, Debug, Default)]
enum Follows {
#[default]
Class,
Other,
}


/// Contains variables used for the linting of blank lines.
#[derive(Debug, Default)]
pub(crate) struct BlankLinesChecker {
Expand All @@ -81,7 +78,7 @@ impl BlankLinesChecker {
&logical_line,
locator,
stylist,
diagnostics
diagnostics,
);
}
}
Expand All @@ -93,11 +90,14 @@ impl BlankLinesChecker {
stylist: &Stylist,
diagnostics: &mut Vec<Diagnostic>,
) {
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()),
Expand Down

0 comments on commit 1939eed

Please sign in to comment.