Skip to content

Commit

Permalink
feat: add --all-files command
Browse files Browse the repository at this point in the history
  • Loading branch information
suo committed May 11, 2022
1 parent fdcf936 commit 3d64ad3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{ensure, Context, Result};
use log::debug;
use regex::Regex;

pub fn get_paths_from_cmd(paths_cmd: String) -> Result<Vec<AbsPath>> {
pub fn get_paths_from_cmd(paths_cmd: &str) -> Result<Vec<AbsPath>> {
debug!("Running paths_cmd: {}", paths_cmd);
let output = Command::new("sh")
.arg("-c")
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub enum PathsOpt {
/// The user didn't specify any paths, so we'll automatically determine
/// which paths to check.
Auto,
AllFiles,
PathsFile(AbsPath),
PathsCmd(String),
Paths(Vec<String>),
Expand Down Expand Up @@ -175,9 +176,10 @@ pub fn do_lint(
};
get_changed_files(&git_root, relative_to.as_deref())?
}
PathsOpt::PathsCmd(paths_cmd) => get_paths_from_cmd(paths_cmd)?,
PathsOpt::PathsCmd(paths_cmd) => get_paths_from_cmd(&paths_cmd)?,
PathsOpt::Paths(paths) => get_paths_from_input(paths)?,
PathsOpt::PathsFile(file) => get_paths_from_file(file)?,
PathsOpt::AllFiles => get_paths_from_cmd("git grep -Il .")?,
};

// Sort and unique the files so we pass a consistent ordering to linters
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ struct Args {
#[clap(long, arg_enum, default_value_t = RenderOpt::Default, global=true)]
output: RenderOpt,

/// Paths to lint. lintrunner will still respect the inclusions and
#[clap(subcommand)]
cmd: Option<SubCommand>,

/// Paths to lint. lintrunner will still respect the inclusions and
/// exclusions defined in .lintrunner.toml; manually specifying a path will
/// not override them.
#[clap(conflicts_with_all = &["paths-cmd", "paths-from"], global = true)]
Expand All @@ -92,6 +92,10 @@ struct Args {
/// If set, output json to the provided path as well as the terminal.
#[clap(long, global = true)]
tee_json: Option<String>,

/// Run lintrunner on all files in the repo. This could take a while!
#[clap(long, conflicts_with_all=&["paths", "paths-cmd", "paths-from", "revision", "merge-base-with"], global = true)]
all_files: bool,
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -211,6 +215,8 @@ fn do_main() -> Result<i32> {
PathsOpt::PathsCmd(paths_cmd)
} else if !args.paths.is_empty() {
PathsOpt::Paths(args.paths)
} else if args.all_files {
PathsOpt::AllFiles
} else {
PathsOpt::Auto
};
Expand Down

0 comments on commit 3d64ad3

Please sign in to comment.