mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[isort
] Handle multiple continuation lines after module docstring (I002
) (#19818)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## Summary Fixes #19815 --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
This commit is contained in:
parent
2e1d6623cd
commit
f0e9c1d8f9
5 changed files with 46 additions and 3 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
"""Hello, world!"""\
|
||||||
|
\
|
||||||
|
|
||||||
|
x = 1; y = 2
|
|
@ -63,9 +63,9 @@ impl<'a> Insertion<'a> {
|
||||||
return Insertion::inline(" ", location.add(offset).add(TextSize::of(';')), ";");
|
return Insertion::inline(" ", location.add(offset).add(TextSize::of(';')), ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the first token after the docstring is a continuation character (i.e. "\"), advance
|
// While the first token after the docstring is a continuation character (i.e. "\"), advance
|
||||||
// an additional row to prevent inserting in the same logical line.
|
// additional rows to prevent inserting in the same logical line.
|
||||||
if match_continuation(locator.after(location)).is_some() {
|
while match_continuation(locator.after(location)).is_some() {
|
||||||
location = locator.full_line_end(location);
|
location = locator.full_line_end(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,6 +379,17 @@ mod tests {
|
||||||
Insertion::own_line("", TextSize::from(22), "\n")
|
Insertion::own_line("", TextSize::from(22), "\n")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let contents = r#"
|
||||||
|
"""Hello, world!"""\
|
||||||
|
\
|
||||||
|
|
||||||
|
"#
|
||||||
|
.trim_start();
|
||||||
|
assert_eq!(
|
||||||
|
insert(contents)?,
|
||||||
|
Insertion::own_line("", TextSize::from(24), "\n")
|
||||||
|
);
|
||||||
|
|
||||||
let contents = r"
|
let contents = r"
|
||||||
x = 1
|
x = 1
|
||||||
"
|
"
|
||||||
|
|
|
@ -797,6 +797,7 @@ mod tests {
|
||||||
#[test_case(Path::new("docstring_followed_by_continuation.py"))]
|
#[test_case(Path::new("docstring_followed_by_continuation.py"))]
|
||||||
#[test_case(Path::new("docstring_only.py"))]
|
#[test_case(Path::new("docstring_only.py"))]
|
||||||
#[test_case(Path::new("docstring_with_continuation.py"))]
|
#[test_case(Path::new("docstring_with_continuation.py"))]
|
||||||
|
#[test_case(Path::new("docstring_with_multiple_continuations.py"))]
|
||||||
#[test_case(Path::new("docstring_with_semicolon.py"))]
|
#[test_case(Path::new("docstring_with_semicolon.py"))]
|
||||||
#[test_case(Path::new("empty.py"))]
|
#[test_case(Path::new("empty.py"))]
|
||||||
#[test_case(Path::new("existing_import.py"))]
|
#[test_case(Path::new("existing_import.py"))]
|
||||||
|
@ -832,6 +833,7 @@ mod tests {
|
||||||
#[test_case(Path::new("docstring_followed_by_continuation.py"))]
|
#[test_case(Path::new("docstring_followed_by_continuation.py"))]
|
||||||
#[test_case(Path::new("docstring_only.py"))]
|
#[test_case(Path::new("docstring_only.py"))]
|
||||||
#[test_case(Path::new("docstring_with_continuation.py"))]
|
#[test_case(Path::new("docstring_with_continuation.py"))]
|
||||||
|
#[test_case(Path::new("docstring_with_multiple_continuations.py"))]
|
||||||
#[test_case(Path::new("docstring_with_semicolon.py"))]
|
#[test_case(Path::new("docstring_with_semicolon.py"))]
|
||||||
#[test_case(Path::new("empty.py"))]
|
#[test_case(Path::new("empty.py"))]
|
||||||
#[test_case(Path::new("existing_import.py"))]
|
#[test_case(Path::new("existing_import.py"))]
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff_linter/src/rules/isort/mod.rs
|
||||||
|
---
|
||||||
|
I002 [*] Missing required import: `from __future__ import annotations`
|
||||||
|
--> docstring_with_multiple_continuations.py:1:1
|
||||||
|
help: Insert required import: `from __future__ import annotations`
|
||||||
|
|
||||||
|
ℹ Safe fix
|
||||||
|
1 1 | """Hello, world!"""\
|
||||||
|
2 2 | \
|
||||||
|
3 3 |
|
||||||
|
4 |+from __future__ import annotations
|
||||||
|
4 5 | x = 1; y = 2
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff_linter/src/rules/isort/mod.rs
|
||||||
|
---
|
||||||
|
I002 [*] Missing required import: `from __future__ import annotations as _annotations`
|
||||||
|
--> docstring_with_multiple_continuations.py:1:1
|
||||||
|
help: Insert required import: `from __future__ import annotations as _annotations`
|
||||||
|
|
||||||
|
ℹ Safe fix
|
||||||
|
1 1 | """Hello, world!"""\
|
||||||
|
2 2 | \
|
||||||
|
3 3 |
|
||||||
|
4 |+from __future__ import annotations as _annotations
|
||||||
|
4 5 | x = 1; y = 2
|
Loading…
Add table
Add a link
Reference in a new issue