-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-use-pathlib
] Catch redundant joins in PTH201
and avoid sy…
…ntax errors (#15177) ## Summary Resolves #10453, resolves #15165. ## Test Plan `cargo nextest run` and `cargo insta test`.
- Loading branch information
1 parent
d349217
commit 901b7dd
Showing
4 changed files
with
440 additions
and
69 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH201.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,70 @@ | ||
from pathlib import Path, PurePath | ||
from pathlib import Path as pth | ||
|
||
|
||
# match | ||
_ = Path(".") | ||
_ = pth(".") | ||
_ = PurePath(".") | ||
_ = Path("") | ||
|
||
Path('', ) | ||
|
||
Path( | ||
'', | ||
) | ||
|
||
Path( # Comment before argument | ||
'', | ||
) | ||
|
||
Path( | ||
'', # EOL comment | ||
) | ||
|
||
Path( | ||
'' # Comment in the middle of implicitly concatenated string | ||
".", | ||
) | ||
|
||
Path( | ||
'' # Comment before comma | ||
, | ||
) | ||
|
||
Path( | ||
'', | ||
) / "bare" | ||
|
||
Path( # Comment before argument | ||
'', | ||
) / ("parenthesized") | ||
|
||
Path( | ||
'', # EOL comment | ||
) / ( ("double parenthesized" ) ) | ||
|
||
( Path( | ||
'' # Comment in the middle of implicitly concatenated string | ||
".", | ||
) )/ (("parenthesized path call") | ||
# Comment between closing parentheses | ||
) | ||
|
||
Path( | ||
'' # Comment before comma | ||
, | ||
) / "multiple" / ( | ||
"frag" # Comment | ||
'ment' | ||
) | ||
|
||
|
||
# no match | ||
_ = Path() | ||
print(".") | ||
Path("file.txt") | ||
Path(".", "folder") | ||
PurePath(".", "folder") | ||
|
||
Path() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.