From a4e5e3205fce46f00456d7a7b015bd1140a7abe8 Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Tue, 18 Jul 2023 10:25:43 +0900 Subject: [PATCH] Ignore directories when collecting files to lint (#5775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #5739 ## Test Plan 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? --- crates/ruff/src/resolver.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ruff/src/resolver.rs b/crates/ruff/src/resolver.rs index 0ad0fa244e..ccbd7ecc31 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.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();