Skip to content

Commit

Permalink
Per review
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo authored and MichaReiser committed Nov 27, 2024
1 parent 972c3a7 commit b3dc296
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@

path_path = Path('.')
os.listdir(path_path)


if os.listdir("dir"):
...

if "file" in os.listdir("dir"):
...
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ PTH208.py:16:1: PTH208 Use `pathlib.Path.iterdir()` instead.
16 | os.listdir(path_path)
| ^^^^^^^^^^ PTH208
|

PTH208.py:19:4: PTH208 Use `pathlib.Path.iterdir()` instead.
|
19 | if os.listdir("dir"):
| ^^^^^^^^^^ PTH208
20 | ...
|

PTH208.py:22:14: PTH208 Use `pathlib.Path.iterdir()` instead.
|
20 | ...
21 |
22 | if "file" in os.listdir("dir"):
| ^^^^^^^^^^ PTH208
23 | ...
|
12 changes: 12 additions & 0 deletions crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,12 @@ impl Violation for PyPath {
/// p = "."
/// for d in os.listdir(p):
/// ...
///
/// if os.listdir(p):
/// ...
///
/// if "file" in os.listdir(p):
/// ...
/// ```
///
/// Use instead:
Expand All @@ -1126,6 +1132,12 @@ impl Violation for PyPath {
/// p = Path(".")
/// for d in p.iterdir():
/// ...
///
/// if any(p.iterdir()):
/// ...
///
/// if (p / "file").exists():
/// ...
/// ```
#[violation]
pub struct OsListdir;
Expand Down

0 comments on commit b3dc296

Please sign in to comment.