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

Code before:
                            }
                        } else {
                            tracing::debug!("{}", entry.path());
                            // 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 || force_exclude {
                                let match_mode = if entry.depth() == 0 && force_exclude {
                                    GlobFilterCheckMode::Adhoc
                                } else {
                                    GlobFilterCheckMode::TopDown
                                };
                                match filter
                                    .is_file_included(entry.path(), match_mode)
                                {
                                    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::Skip;
                                        }
                                    }
                                    IncludeResult::Excluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it is excluded by a default or `src.exclude` pattern.",
                                            path=entry.path()
                                        );
                                        return WalkState::Skip;
                                    }
                                    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::Skip;
                                    }
                                }
                            }

                            // If this returns `Err`, then the file was deleted between now and when the walk callback was called.
                            // We can ignore this.
                            if let Ok(file) = system_path_to_file(&*db, entry.path()) {
                                files.lock().unwrap().push(file);
                            }

Review comment (suggestion):
This is not necessary because you can't walk a file but it feels more accurate to return skip in those instances.

Code after:
                            }
                        } 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 || force_exclude {
                                let match_mode = if entry.depth() == 0 && force_exclude {
                                    GlobFilterCheckMode::Adhoc
                                } else {
                                    GlobFilterCheckMode::TopDown
                                };
                                match filter
                                    .is_file_included(entry.path(), match_mode)
                                {
                                    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::Skip;
                                        }
                                    }
                                    IncludeResult::Excluded => {
                                        tracing::debug!(
                                            "Ignoring file `{path}` because it is excluded by a default or `src.exclude` pattern.",
                                            path=entry.path()
                                        );
                                        return WalkState::Skip;
                                    }
                                    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::Skip;
                                    }
                                }
                            }

                            // If this returns `Err`, then the file was deleted between now and when the walk callback was called.
                            // We can ignore this.
                            if let Ok(file) = system_path_to_file(&*db, entry.path()) {
                                files.lock().unwrap().push(file);
                            }
                        }