-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruff fails when a directory ends with .py #5739
Comments
@konstin is this a good first issue? |
(From my perspective, seems like a good issue, will probably require digging into how we collect the "files to lint".) |
i've confirmed it's not related to #5611, so yes it's a good first issue |
can I work on this? |
Is this the part that needs to be fixed? ruff/crates/ruff/src/resolver.rs Lines 332 to 350 in f029f8b
It looks like the else block is missing |
Testing the following change: diff --git a/crates/ruff/src/resolver.rs b/crates/ruff/src/resolver.rs
index 0ad0fa244..0d851135c 100644
--- a/crates/ruff/src/resolver.rs
+++ b/crates/ruff/src/resolver.rs
@@ -330,9 +330,12 @@ pub fn python_files_in_path(
}
if result.as_ref().map_or(true, |entry| {
+ if !(entry.file_type().map_or(false, |ft| ft.is_file())) {
+ return false;
+ }
if entry.depth() == 0 {
// Accept all files that are passed-in directly.
- entry.file_type().map_or(false, |ft| ft.is_file())
+ true
} else {
// Otherwise, check if the file is included.
let path = entry.path(); Result:
|
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Fixes #5739 ## Test Plan <!-- How was it tested? --> Manually tested: ```sh $ tree dir dir ├── dir.py │ └── file.py └── file.py 1 directory, 2 files $ cargo run -p ruff_cli -- check dir --no-cache Finished dev [unoptimized + debuginfo] target(s) in 0.08s Running `target/debug/ruff check dir --no-cache` dir/dir.py/file.py:1:7: F821 Undefined name `a` dir/file.py:1:7: F821 Undefined name `a` Found 2 errors. ``` Is a unit test needed?
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Fixes astral-sh#5739 ## Test Plan <!-- How was it tested? --> Manually tested: ```sh $ tree dir dir ├── dir.py │ └── file.py └── file.py 1 directory, 2 files $ cargo run -p ruff_cli -- check dir --no-cache Finished dev [unoptimized + debuginfo] target(s) in 0.08s Running `target/debug/ruff check dir --no-cache` dir/dir.py/file.py:1:7: F821 Undefined name `a` dir/file.py:1:7: F821 Undefined name `a` Found 2 errors. ``` Is a unit test needed?
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Fixes #5739 ## Test Plan <!-- How was it tested? --> Manually tested: ```sh $ tree dir dir ├── dir.py │ └── file.py └── file.py 1 directory, 2 files $ cargo run -p ruff_cli -- check dir --no-cache Finished dev [unoptimized + debuginfo] target(s) in 0.08s Running `target/debug/ruff check dir --no-cache` dir/dir.py/file.py:1:7: F821 Undefined name `a` dir/file.py:1:7: F821 Undefined name `a` Found 2 errors. ``` Is a unit test needed?
Ruff gets confused when a directory is named like a python file (ends with
.py
):The text was updated successfully, but these errors were encountered: