Repository: astral-sh/ruff
File: crates/ty_project/src/walk.rs (Rust)

Code before:
                                        WalkState::Skip
                                    },
                                    IncludeResult::NotIncluded => {
                                        tracing::debug!(
                                            "Skipping directory `{path}` because it doesn't match any `src.include` pattern or path specified on the CLI",
                                            path=entry.path()
                                        );
                                        WalkState::Skip
                                    },
                                };
                            }
                        } else {
                            // Ignore any non python files to avoid creating too many entries in `Files`.
                            // Unless the file is explicitly passed, we then always assume it's a python file.
                            let source_type = entry.path().extension().and_then(PySourceType::try_from_extension).or_else(|| {
                                if entry.depth() == 0 {
                                    Some(PySourceType::Python)
                                } else {
                                    db.system().source_type(entry.path())
                                }
                            });

                            if source_type.is_none()
                            {
                                return WalkState::Continue;
                            }

                            // For all files, except the ones that were explicitly passed to the walker (CLI),
                            // check if they're included in the project.
                            if entry.depth() > 0 || self.force_exclude {
                                match filter
                                    .is_file_included(entry.path(), GlobFilterCheckMode::TopDown)
                                {
                                    IncludeResult::Included => {},
                                    IncludeResult::Excluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it is excluded by a default or `src.exclude` pattern.",
                                            path=entry.path()
                                        );
                                        return WalkState::Continue;
                                    },
                                    IncludeResult::NotIncluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it doesn't match any `src.include` pattern or path specified on the CLI.",
                                            path=entry.path()
                                        );
                                        return WalkState::Continue;
                                    },
                                }
                            }


Review comment (suggestion):
Suspicious of the `entry.depth() == 0` check given we're inside `if entry.depth() > 0 || self.force_exclude {`. Don't know the code well enough to say if it still makes sense.

Code after:
                                        tracing::debug!(
                                            "Skipping directory '{path}' because it is excluded by a default or `src.exclude` pattern",
                                            path=entry.path()
                                        );
                                        WalkState::Skip
                                    }
                                    IncludeResult::NotIncluded => {
                                        tracing::debug!(
                                            "Skipping directory `{path}` because it doesn't match any `src.include` pattern or path specified on the CLI",
                                            path=entry.path()
                                        );
                                        WalkState::Skip
                                    }
                                };
                            }
                        } else {
                            // For all files, except the ones that were explicitly passed to the walker (CLI),
                            // check if they're included in the project.
                            if entry.depth() > 0 || self.force_exclude {
                                match filter
                                    .is_file_included(entry.path(), GlobFilterCheckMode::TopDown)
                                {
                                    IncludeResult::Included { literal_match } => {
                                        // Ignore any non python files to avoid creating too many entries in `Files`.
                                        // Unless the file is explicitly passed on the CLI or a literal match in the `include`, we then always assume it's a file ty can analyze
                                        let source_type = if literal_match == Some(true) || entry.depth() == 0 {
                                            Some(PySourceType::Python)
                                        } else {
                                            entry.path().extension().and_then(PySourceType::try_from_extension).or_else(|| db.system().source_type(entry.path()))
                                        };


                                        if source_type.is_none()
                                        {
                                            return WalkState::Continue;
                                        }
                                    }
                                    IncludeResult::Excluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it is excluded by a default or `src.exclude` pattern.",
                                            path=entry.path()
                                        );
                                        return WalkState::Continue;
                                    }
                                    IncludeResult::NotIncluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it doesn't match any `src.include` pattern or path specified on the CLI.",
                                            path=entry.path()
                                        );
                                        return WalkState::Continue;
                                    }