mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +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
|
@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Any, ClassVar
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
|
|
||||||
|
from ....import unknown
|
||||||
from ..protocol import commands, definitions, responses
|
from ..protocol import commands, definitions, responses
|
||||||
from ..server import example
|
from ..server import example
|
||||||
from .. import server
|
from .. import server
|
||||||
|
|
|
@ -94,6 +94,10 @@ fn fix_banned_relative_import(
|
||||||
) -> Option<Fix> {
|
) -> Option<Fix> {
|
||||||
// Only fix is the module path is known.
|
// Only fix is the module path is known.
|
||||||
if let Some(mut parts) = module_path.cloned() {
|
if let Some(mut parts) = module_path.cloned() {
|
||||||
|
if *level? >= parts.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove relative level from module path.
|
// Remove relative level from module path.
|
||||||
for _ in 0..*level? {
|
for _ in 0..*level? {
|
||||||
parts.pop();
|
parts.pop();
|
||||||
|
|
|
@ -10,50 +10,25 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 5
|
row: 5
|
||||||
column: 55
|
column: 23
|
||||||
fix:
|
fix: ~
|
||||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
|
||||||
location:
|
|
||||||
row: 5
|
|
||||||
column: 0
|
|
||||||
end_location:
|
|
||||||
row: 5
|
|
||||||
column: 55
|
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
RelativeImports:
|
RelativeImports:
|
||||||
strictness: parents
|
strictness: parents
|
||||||
location:
|
location:
|
||||||
row: 5
|
row: 6
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 5
|
row: 6
|
||||||
column: 55
|
column: 55
|
||||||
fix:
|
fix:
|
||||||
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
content: "from my_package.sublib.protocol import commands, definitions, responses"
|
||||||
location:
|
location:
|
||||||
row: 5
|
row: 6
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 5
|
row: 6
|
||||||
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
|
|
||||||
column: 55
|
column: 55
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
|
@ -64,32 +39,68 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 6
|
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
|
column: 28
|
||||||
fix:
|
fix:
|
||||||
content: from my_package.sublib.server import example
|
content: from my_package.sublib.server import example
|
||||||
location:
|
location:
|
||||||
row: 6
|
row: 7
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 6
|
row: 7
|
||||||
column: 28
|
column: 28
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
RelativeImports:
|
RelativeImports:
|
||||||
strictness: parents
|
strictness: parents
|
||||||
location:
|
location:
|
||||||
row: 7
|
row: 8
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 7
|
row: 8
|
||||||
column: 21
|
column: 21
|
||||||
fix:
|
fix:
|
||||||
content: from my_package.sublib import server
|
content: from my_package.sublib import server
|
||||||
location:
|
location:
|
||||||
row: 7
|
row: 8
|
||||||
column: 0
|
column: 0
|
||||||
end_location:
|
end_location:
|
||||||
row: 7
|
row: 8
|
||||||
column: 21
|
column: 21
|
||||||
parent: ~
|
parent: ~
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue