mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
Treat form feed as valid whitespace before a semicolon (#19343)
fixes #19310
This commit is contained in:
parent
b2501b45e0
commit
ff94fe7447
4 changed files with 18 additions and 1 deletions
5
crates/ruff_linter/resources/test/fixtures/isort/required_imports/whitespace.py
vendored
Normal file
5
crates/ruff_linter/resources/test/fixtures/isort/required_imports/whitespace.py
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# This is a regression test for https://github.com/astral-sh/ruff/issues/19310
|
||||
# there is a (potentially invisible) unicode formfeed character (000C) between "docstring" and the semicolon
|
||||
"docstring"; print(
|
||||
f"{__doc__=}",
|
||||
)
|
||||
|
|
@ -288,7 +288,7 @@ fn match_docstring_end(body: &[Stmt]) -> Option<TextSize> {
|
|||
fn match_semicolon(s: &str) -> Option<TextSize> {
|
||||
for (offset, c) in s.char_indices() {
|
||||
match c {
|
||||
' ' | '\t' => continue,
|
||||
_ if is_python_whitespace(c) => continue,
|
||||
';' => return Some(TextSize::try_from(offset).unwrap()),
|
||||
_ => break,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -801,6 +801,7 @@ mod tests {
|
|||
#[test_case(Path::new("existing_import.py"))]
|
||||
#[test_case(Path::new("multiline_docstring.py"))]
|
||||
#[test_case(Path::new("off.py"))]
|
||||
#[test_case(Path::new("whitespace.py"))]
|
||||
fn required_import(path: &Path) -> Result<()> {
|
||||
let snapshot = format!("required_import_{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/isort/mod.rs
|
||||
---
|
||||
whitespace.py:1:1: I002 [*] Missing required import: `from __future__ import annotations`
|
||||
ℹ Safe fix
|
||||
1 1 | # This is a regression test for https://github.com/astral-sh/ruff/issues/19310
|
||||
2 2 | # there is a (potentially invisible) unicode formfeed character (000C) between "docstring" and the semicolon
|
||||
3 |-"docstring"; print(
|
||||
3 |+"docstring"; from __future__ import annotations; print(
|
||||
4 4 | f"{__doc__=}",
|
||||
5 5 | )
|
||||
Loading…
Add table
Add a link
Reference in a new issue