mirror of https://github.com/astral-sh/ruff
Raise `PTH201` for `Path("")` (#6095)
This commit is contained in:
parent
77396c6f92
commit
99127243f4
|
|
@ -5,6 +5,7 @@ from pathlib import Path as pth
|
||||||
_ = Path(".")
|
_ = Path(".")
|
||||||
_ = pth(".")
|
_ = pth(".")
|
||||||
_ = PurePath(".")
|
_ = PurePath(".")
|
||||||
|
_ = Path("")
|
||||||
|
|
||||||
# no match
|
# no match
|
||||||
_ = Path()
|
_ = Path()
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,11 @@ pub(crate) fn path_constructor_current_directory(checker: &mut Checker, expr: &E
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if value != "." {
|
if matches!(value.as_str(), "" | ".") {
|
||||||
return;
|
let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
|
||||||
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
|
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(*range)));
|
||||||
|
}
|
||||||
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
|
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
|
||||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(*range)));
|
|
||||||
}
|
|
||||||
checker.diagnostics.push(diagnostic);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ PTH201.py:5:10: PTH201 [*] Do not pass the current directory explicitly to `Path
|
||||||
5 |+_ = Path()
|
5 |+_ = Path()
|
||||||
6 6 | _ = pth(".")
|
6 6 | _ = pth(".")
|
||||||
7 7 | _ = PurePath(".")
|
7 7 | _ = PurePath(".")
|
||||||
8 8 |
|
8 8 | _ = Path("")
|
||||||
|
|
||||||
PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
||||||
|
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
||||||
6 | _ = pth(".")
|
6 | _ = pth(".")
|
||||||
| ^^^ PTH201
|
| ^^^ PTH201
|
||||||
7 | _ = PurePath(".")
|
7 | _ = PurePath(".")
|
||||||
|
8 | _ = Path("")
|
||||||
|
|
|
|
||||||
= help: Remove the current directory argument
|
= help: Remove the current directory argument
|
||||||
|
|
||||||
|
|
@ -38,8 +39,8 @@ PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
||||||
6 |-_ = pth(".")
|
6 |-_ = pth(".")
|
||||||
6 |+_ = pth()
|
6 |+_ = pth()
|
||||||
7 7 | _ = PurePath(".")
|
7 7 | _ = PurePath(".")
|
||||||
8 8 |
|
8 8 | _ = Path("")
|
||||||
9 9 | # no match
|
9 9 |
|
||||||
|
|
||||||
PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
||||||
|
|
|
|
||||||
|
|
@ -47,8 +48,7 @@ PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path
|
||||||
6 | _ = pth(".")
|
6 | _ = pth(".")
|
||||||
7 | _ = PurePath(".")
|
7 | _ = PurePath(".")
|
||||||
| ^^^ PTH201
|
| ^^^ PTH201
|
||||||
8 |
|
8 | _ = Path("")
|
||||||
9 | # no match
|
|
||||||
|
|
|
|
||||||
= help: Remove the current directory argument
|
= help: Remove the current directory argument
|
||||||
|
|
||||||
|
|
@ -58,8 +58,29 @@ PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path
|
||||||
6 6 | _ = pth(".")
|
6 6 | _ = pth(".")
|
||||||
7 |-_ = PurePath(".")
|
7 |-_ = PurePath(".")
|
||||||
7 |+_ = PurePath()
|
7 |+_ = PurePath()
|
||||||
8 8 |
|
8 8 | _ = Path("")
|
||||||
9 9 | # no match
|
9 9 |
|
||||||
10 10 | _ = Path()
|
10 10 | # no match
|
||||||
|
|
||||||
|
PTH201.py:8:10: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
||||||
|
|
|
||||||
|
6 | _ = pth(".")
|
||||||
|
7 | _ = PurePath(".")
|
||||||
|
8 | _ = Path("")
|
||||||
|
| ^^ PTH201
|
||||||
|
9 |
|
||||||
|
10 | # no match
|
||||||
|
|
|
||||||
|
= help: Remove the current directory argument
|
||||||
|
|
||||||
|
ℹ Fix
|
||||||
|
5 5 | _ = Path(".")
|
||||||
|
6 6 | _ = pth(".")
|
||||||
|
7 7 | _ = PurePath(".")
|
||||||
|
8 |-_ = Path("")
|
||||||
|
8 |+_ = Path()
|
||||||
|
9 9 |
|
||||||
|
10 10 | # no match
|
||||||
|
11 11 | _ = Path()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue