Skip to content

Commit

Permalink
Merge pull request #929 from epage/sort
Browse files Browse the repository at this point in the history
feat(cli): Add a --sort flag
  • Loading branch information
epage authored Feb 8, 2024
2 parents 53a7a51 + eb99975 commit 4c248c8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/typos-cli/src/bin/typos-cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub(crate) struct Args {
#[arg(short = 'j', long = "threads", default_value = "0")]
pub(crate) threads: usize,

/// Sort results
#[arg(long)]
pub(crate) sort: bool,

/// Respect excluded files even for paths passed explicitly.
#[arg(long, help_heading = None)]
pub(crate) force_exclude: bool,
Expand Down
11 changes: 9 additions & 2 deletions crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,25 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
let walk_policy = engine.walk(&cwd);

let threads = if path.is_file() { 1 } else { args.threads };
let threads = if path.is_file() || args.sort {
1
} else {
args.threads
};
let single_threaded = threads == 1;

let mut walk = ignore::WalkBuilder::new(path);
walk.threads(args.threads)
walk.threads(threads)
.skip_stdout(true)
.hidden(walk_policy.ignore_hidden())
.ignore(walk_policy.ignore_dot())
.git_global(walk_policy.ignore_global())
.git_ignore(walk_policy.ignore_vcs())
.git_exclude(walk_policy.ignore_vcs())
.parents(walk_policy.ignore_parent());
if args.sort {
walk.sort_by_file_name(|a, b| a.cmp(b));
}
if !walk_policy.extend_exclude.is_empty() {
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
for pattern in walk_policy.extend_exclude.iter() {
Expand Down
1 change: 1 addition & 0 deletions crates/typos-cli/tests/cmd/config-disallowed.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin.name = "typos"
args = "--sort"
status.code = 2
stdin = ""
stdout = """
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/extend-ignore-re.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin.name = "typos"
args = "-j1"
args = "--sort"
stdin = ""
stdout = """
error: `hello` should be `goodbye`
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/file-list-stdin.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin.name = "typos"
args = "--file-list -"
args = "--sort --file-list -"
stdin = """
b.fail
d.fail
Expand Down
1 change: 1 addition & 0 deletions crates/typos-cli/tests/cmd/help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Arguments:
Options:
--file-list <FILE_LIST> Read the list of newline separated paths from file or stdin (if `-`)
-j, --threads <THREADS> The approximate number of threads to use [default: 0]
--sort Sort results
--force-exclude Respect excluded files even for paths passed explicitly
-h, --help Print help
-V, --version Print version
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/ignore-line.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin.name = "typos"
stdin = ""
stdin = "--sort"
stdout = """
error: `hello` should be `goodbye`
--> ./file.ignore:1:1
Expand Down

0 comments on commit 4c248c8

Please sign in to comment.