Skip to content
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

feature/traverse: Add an option to rely purely on ignore files for traversing directories #339

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

MA-DDN
Copy link

@MA-DDN MA-DDN commented Nov 27, 2024

What does this PR accomplish?

  • 🦚 Feature

Changes proposed by this PR:

This pr adds an option flag to change the behaviour of the traversal module to collect all relevant files except those which match an entry in a .gitignore file. Our usecase for this is to be able to ignore certain temporary Markdown files which are pulled in when building our documentation.

📜 Checklist

  • Works on the ./demo sub directory
  • Test coverage is excellent and passes
  • Documentation is thorough

@MA-DDN MA-DDN marked this pull request as ready for review November 27, 2024 14:56
Comment on lines +492 to 513
while let Some(path) = all_files.pop_front() {
let x = if let Ok(meta) = path.metadata() {
if meta.is_file() {
match path.file_name().and_then(|x| x.to_str()) {
Some(file_name) if file_name == "Cargo.toml" => Extraction::Manifest(path),
Some(file_name) if file_name.ends_with(".md") => Extraction::Markdown(path),
Some(file_name) if file_name.ends_with(".rs") => Extraction::Source(path),
_ => {
// This branch is commonly entered when ran on a non-cargo
// path.
// Potentially become mdbook aware
// <https://github.com/drahnr/cargo-spellcheck/issues/273>
log::debug!(
"Unknown file type encountered, skipping path: {}",
path.display()
);
continue;
}
}
} else {
Extraction::Missing(path)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part should become a function, it's (almost?) identical to the one in the else branch.

let mut all_files = VecDeque::<PathBuf>::with_capacity(32);

while let Some(path) = flow.pop_front() {
let files = ignore::WalkBuilder::new(path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define a closure that gives us an iterator back rather than duplicating the if and else branch logic. It's been a mess before you came, but now I can see what I've done a few years back 😰

Copy link
Owner

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With some delay, I am not opposed to the changes, yet with the added complexity some more code unification and carve outs need to be done before I'll merge this.

Sorry for the long review delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants