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
1 change: 1 addition & 0 deletions src/checker/hunspell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ fn obtain_suggestions<'s>(
#[cfg(test)]
mod tests {
use crate::checker::dictaffix::is_valid_hunspell_dic;
use std::io::BufRead;

use super::*;

Expand Down
19 changes: 19 additions & 0 deletions src/config/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ pub struct Common {
/// argument paths, and also declared modules in rust files.
pub recursive: bool,

/// Use gitignore files to determine which files to check.
/// This flag also modifies the behaviour of the recursive flag
/// to purely recurse down directories.
#[clap(short, long)]
pub gitignore: bool,

// with fallback from config, so it has to be tri-state
#[clap(long)]
/// Execute the given subset of checkers.
Expand Down Expand Up @@ -197,6 +203,12 @@ pub enum Sub {
/// Recurse down directories and module declaration derived paths.
recursive: bool,

/// Use gitignore files to determine which files to list.
/// This flag also modifies the behaviour of the recursive flag
/// to purely recurse down directories.
#[clap(short, long)]
gitignore: bool,

#[clap(short, long)]
/// Do not check the referenced key `readme=` or default `README.md`.
skip_readme: bool,
Expand Down Expand Up @@ -536,13 +548,15 @@ impl Args {
Some(Sub::ListFiles {
ref paths,
recursive,
gitignore,
skip_readme,
}) => UnifiedArgs::Operate {
action: self.action(),
config_path,
dev_comments: false, // not relevant
skip_readme,
recursive,
gitignore,
paths: paths.clone(),
exit_code_override: 1,
},
Expand All @@ -554,6 +568,7 @@ impl Args {
dev_comments: common.dev_comments || config.dev_comments,
skip_readme: common.skip_readme || config.skip_readme,
recursive: common.recursive,
gitignore: common.gitignore,
paths: common.paths.clone(),
exit_code_override: common.code,
}
Expand All @@ -568,6 +583,7 @@ impl Args {
dev_comments: common.dev_comments || config.dev_comments,
skip_readme: common.skip_readme || config.skip_readme,
recursive: common.recursive,
gitignore: common.gitignore,
paths: common.paths.clone(),
exit_code_override: common.code,
},
Expand Down Expand Up @@ -600,6 +616,7 @@ pub enum UnifiedArgs {
dev_comments: bool,
skip_readme: bool,
recursive: bool,
gitignore: bool,
paths: Vec<PathBuf>,
exit_code_override: u8,
},
Expand Down Expand Up @@ -819,6 +836,7 @@ mod tests {
dev_comments,
skip_readme,
recursive,
gitignore,
paths,
exit_code_override,
} => {
Expand All @@ -827,6 +845,7 @@ mod tests {
assert_eq!(dev_comments, true);
assert_eq!(skip_readme, true);
assert_eq!(recursive, false);
assert_eq!(gitignore, false);
assert_eq!(paths, Vec::<PathBuf>::new());
}
);
Expand Down
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,22 @@ pub fn run(args: Args) -> Result<ExitCode> {
action,
paths,
recursive,
gitignore,
skip_readme,
config_path,
dev_comments,
exit_code_override,
} => {
log::debug!("Executing: {action:?} with {config:?} from {config_path:?}");

let documents =
traverse::extract(paths, recursive, skip_readme, dev_comments, &config)?;
let documents = traverse::extract(
paths,
recursive,
gitignore,
skip_readme,
dev_comments,
&config,
)?;

let rt = tokio::runtime::Runtime::new()?;
let finish = rt.block_on(async move { action.run(documents, config).await })?;
Expand Down
Loading