mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Abort when unable to fix relative imports past module root (#3319)
This commit is contained in:
parent
4de3882088
commit
a03fa93c3a
3 changed files with 54 additions and 38 deletions
|
@ -1,7 +1,8 @@
|
|||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
|
||||
import attrs
|
||||
|
||||
from ....import unknown
|
||||
from ..protocol import commands, definitions, responses
|
||||
from ..server import example
|
||||
from .. import server
|
||||
|
|
|
@ -94,6 +94,10 @@ fn fix_banned_relative_import(
|
|||
) -> Option<Fix> {
|
||||
// Only fix is the module path is known.
|
||||
if let Some(mut parts) = module_path.cloned() {
|
||||
if *level? >= parts.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Remove relative level from module path.
|
||||
for _ in 0..*level? {
|
||||
parts.pop();
|
||||
|
|
|
@ -10,50 +10,25 @@ expression: diagnostics
|
|||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 55
|
||||
fix:
|
||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||
location:
|
||||
row: 5
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 55
|
||||
column: 23
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
RelativeImports:
|
||||
strictness: parents
|
||||
location:
|
||||
row: 5
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
row: 6
|
||||
column: 55
|
||||
fix:
|
||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||
location:
|
||||
row: 5
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 55
|
||||
parent: ~
|
||||
- kind:
|
||||
RelativeImports:
|
||||
strictness: parents
|
||||
location:
|
||||
row: 5
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
column: 55
|
||||
fix:
|
||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||
location:
|
||||
row: 5
|
||||
column: 0
|
||||
end_location:
|
||||
row: 5
|
||||
row: 6
|
||||
column: 55
|
||||
parent: ~
|
||||
- kind:
|
||||
|
@ -64,32 +39,68 @@ expression: diagnostics
|
|||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 55
|
||||
fix:
|
||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||
location:
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 55
|
||||
parent: ~
|
||||
- kind:
|
||||
RelativeImports:
|
||||
strictness: parents
|
||||
location:
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 55
|
||||
fix:
|
||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||
location:
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 55
|
||||
parent: ~
|
||||
- kind:
|
||||
RelativeImports:
|
||||
strictness: parents
|
||||
location:
|
||||
row: 7
|
||||
column: 0
|
||||
end_location:
|
||||
row: 7
|
||||
column: 28
|
||||
fix:
|
||||
content: from my_package.sublib.server import example
|
||||
location:
|
||||
row: 6
|
||||
row: 7
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
row: 7
|
||||
column: 28
|
||||
parent: ~
|
||||
- kind:
|
||||
RelativeImports:
|
||||
strictness: parents
|
||||
location:
|
||||
row: 7
|
||||
row: 8
|
||||
column: 0
|
||||
end_location:
|
||||
row: 7
|
||||
row: 8
|
||||
column: 21
|
||||
fix:
|
||||
content: from my_package.sublib import server
|
||||
location:
|
||||
row: 7
|
||||
row: 8
|
||||
column: 0
|
||||
end_location:
|
||||
row: 7
|
||||
row: 8
|
||||
column: 21
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue