Skip to content

Commit ff94fe7

Browse files
authored
Treat form feed as valid whitespace before a semicolon (#19343)
fixes #19310
1 parent b2501b4 commit ff94fe7

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This is a regression test for https://github.com/astral-sh/ruff/issues/19310
2+
# there is a (potentially invisible) unicode formfeed character (000C) between "docstring" and the semicolon
3+
"docstring" ; print(
4+
f"{__doc__=}",
5+
)

crates/ruff_linter/src/importer/insertion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn match_docstring_end(body: &[Stmt]) -> Option<TextSize> {
288288
fn match_semicolon(s: &str) -> Option<TextSize> {
289289
for (offset, c) in s.char_indices() {
290290
match c {
291-
' ' | '\t' => continue,
291+
_ if is_python_whitespace(c) => continue,
292292
';' => return Some(TextSize::try_from(offset).unwrap()),
293293
_ => break,
294294
}

crates/ruff_linter/src/rules/isort/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ mod tests {
801801
#[test_case(Path::new("existing_import.py"))]
802802
#[test_case(Path::new("multiline_docstring.py"))]
803803
#[test_case(Path::new("off.py"))]
804+
#[test_case(Path::new("whitespace.py"))]
804805
fn required_import(path: &Path) -> Result<()> {
805806
let snapshot = format!("required_import_{}", path.to_string_lossy());
806807
let diagnostics = test_path(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/ruff_linter/src/rules/isort/mod.rs
3+
---
4+
whitespace.py:1:1: I002 [*] Missing required import: `from __future__ import annotations`
5+
Safe fix
6+
1 1 | # This is a regression test for https://github.com/astral-sh/ruff/issues/19310
7+
2 2 | # there is a (potentially invisible) unicode formfeed character (000C) between "docstring" and the semicolon
8+
3 |-"docstring" ; print(
9+
3 |+"docstring" ; from __future__ import annotations; print(
10+
4 4 | f"{__doc__=}",
11+
5 5 | )

0 commit comments

Comments
 (0)