Skip to content

Commit

Permalink
Use slices for logical line tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Apr 20, 2023
1 parent 51b52b0 commit ce32f1d
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 259 deletions.
10 changes: 5 additions & 5 deletions crates/ruff/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub fn check_logical_lines(
for line in &LogicalLines::from_tokens(tokens, locator) {
if line.flags().contains(TokenFlags::OPERATOR) {
space_around_operator(&line, &mut context);
whitespace_around_named_parameter_equals(&line.tokens(), &mut context);
missing_whitespace_around_operator(&line.tokens(), &mut context);
whitespace_around_named_parameter_equals(&line, &mut context);
missing_whitespace_around_operator(&line, &mut context);
missing_whitespace(&line, should_fix_missing_whitespace, &mut context);
}

Expand All @@ -73,16 +73,16 @@ pub fn check_logical_lines(
}
if line.flags().contains(TokenFlags::KEYWORD) {
whitespace_around_keywords(&line, &mut context);
missing_whitespace_after_keyword(&line.tokens(), &mut context);
missing_whitespace_after_keyword(&line, &mut context);
}

if line.flags().contains(TokenFlags::COMMENT) {
whitespace_before_comment(&line.tokens(), locator, prev_line.is_none(), &mut context);
whitespace_before_comment(&line, locator, prev_line.is_none(), &mut context);
}

if line.flags().contains(TokenFlags::BRACKET) {
whitespace_before_parameters(
&line.tokens(),
&line,
should_fix_whitespace_before_parameters,
&mut context,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use itertools::Itertools;
use ruff_text_size::TextRange;

use crate::checkers::logical_lines::LogicalLinesContext;
use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;
use ruff_diagnostics::Violation;
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::token_kind::TokenKind;

use super::LogicalLineTokens;

#[violation]
pub struct MissingWhitespaceAfterKeyword;

Expand All @@ -20,10 +19,10 @@ impl Violation for MissingWhitespaceAfterKeyword {

/// E275
pub(crate) fn missing_whitespace_after_keyword(
tokens: &LogicalLineTokens,
line: &LogicalLine,
context: &mut LogicalLinesContext,
) {
for (tok0, tok1) in tokens.iter().tuple_windows() {
for (tok0, tok1) in line.tokens().iter().tuple_windows() {
let tok0_kind = tok0.kind();
let tok1_kind = tok1.kind();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::token_kind::TokenKind;
use ruff_text_size::{TextRange, TextSize};

use crate::rules::pycodestyle::rules::logical_lines::LogicalLineTokens;
use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;

// E225
#[violation]
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Violation for MissingWhitespaceAroundModuloOperator {
/// E225, E226, E227, E228
#[allow(clippy::if_same_then_else)]
pub(crate) fn missing_whitespace_around_operator(
tokens: &LogicalLineTokens,
line: &LogicalLine,
context: &mut LogicalLinesContext,
) {
#[derive(Copy, Clone, Eq, PartialEq)]
Expand All @@ -70,7 +70,7 @@ pub(crate) fn missing_whitespace_around_operator(
let mut prev_type: TokenKind = TokenKind::EndOfFile;
let mut prev_end = TextSize::default();

for token in tokens {
for token in line.tokens() {
let kind = token.kind();

if kind.is_skip_comment() {
Expand Down
Loading

0 comments on commit ce32f1d

Please sign in to comment.