Skip to content

Commit

Permalink
E274: allow tab indentation before keyword (#9099)
Browse files Browse the repository at this point in the history
## Summary

E274 currently flags any keyword at the start of a line indented with
tabs. This turns out to be due to a bug in `Whitespace::trailing` that
never considers any whitespace containing a tab as indentation.

## Test Plan

Added a simple test case.
  • Loading branch information
sciyoshi committed Dec 11, 2023
1 parent f452bf8 commit 1026ece
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 3 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E27.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ def f():
if (a and
b):
pass
#: Okay
def f():
return 1
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,16 @@ impl Whitespace {
}
}

if has_tabs {
if len == content.text_len() {
// All whitespace up to the start of the line -> Indent
(Self::None, TextSize::default())
} else if has_tabs {
(Self::Tab, len)
} else {
match count {
0 => (Self::None, TextSize::default()),
1 => (Self::Single, len),
_ => {
if len == content.text_len() {
// All whitespace up to the start of the line -> Indent
(Self::None, TextSize::default())
} else {
(Self::Many, len)
}
}
_ => (Self::Many, len),
}
}
}
Expand Down

0 comments on commit 1026ece

Please sign in to comment.