Skip to content

Commit

Permalink
Ignore directories when collecting files to lint (#5775)
Browse files Browse the repository at this point in the history
<!--
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?
  • Loading branch information
harupy authored and konstin committed Jul 19, 2023
1 parent a77c0fc commit bf168bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/ruff/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,12 @@ pub fn python_files_in_path(
}

if result.as_ref().map_or(true, |entry| {
if entry.depth() == 0 {
// Ignore directories
if entry.file_type().map_or(true, |ft| ft.is_dir()) {
false
} else 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();
Expand Down

0 comments on commit bf168bd

Please sign in to comment.