diff --git a/crates/ruff/resources/test/fixtures/isort/required_imports/multiline_docstring.py b/crates/ruff/resources/test/fixtures/isort/required_imports/multiline_docstring.py new file mode 100644 index 0000000000..38428bcba9 --- /dev/null +++ b/crates/ruff/resources/test/fixtures/isort/required_imports/multiline_docstring.py @@ -0,0 +1,4 @@ +"""a +b""" +# b +import os diff --git a/crates/ruff/src/rules/isort/helpers.rs b/crates/ruff/src/rules/isort/helpers.rs index f6eec87544..671253fe75 100644 --- a/crates/ruff/src/rules/isort/helpers.rs +++ b/crates/ruff/src/rules/isort/helpers.rs @@ -110,7 +110,7 @@ pub fn find_splice_location(body: &[Stmt], locator: &Locator) -> Location { // Find the first token that isn't a comment or whitespace. let contents = locator.skip(splice); - for (.., tok, end) in lexer::make_tokenizer(contents).flatten() { + for (.., tok, end) in lexer::make_tokenizer_located(contents, splice).flatten() { if matches!(tok, Tok::Comment(..) | Tok::Newline) { splice = end; } else { diff --git a/crates/ruff/src/rules/isort/mod.rs b/crates/ruff/src/rules/isort/mod.rs index ba6463c708..943bb6bf94 100644 --- a/crates/ruff/src/rules/isort/mod.rs +++ b/crates/ruff/src/rules/isort/mod.rs @@ -620,6 +620,7 @@ mod tests { #[test_case(Path::new("docstring.py"))] #[test_case(Path::new("docstring_only.py"))] + #[test_case(Path::new("multiline_docstring.py"))] #[test_case(Path::new("empty.py"))] fn required_import(path: &Path) -> Result<()> { let snapshot = format!("required_import_{}", path.to_string_lossy()); diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap new file mode 100644 index 0000000000..77ea497dff --- /dev/null +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap @@ -0,0 +1,24 @@ +--- +source: crates/ruff/src/rules/isort/mod.rs +expression: diagnostics +--- +- kind: + MissingRequiredImport: from __future__ import annotations + location: + row: 1 + column: 0 + end_location: + row: 1 + column: 0 + fix: + content: + - "" + - from __future__ import annotations + location: + row: 3 + column: 3 + end_location: + row: 3 + column: 3 + parent: ~ +