From ad80305210d4d6dd2444d66b439b75acf2096e0b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Feb 2024 16:03:03 -0600 Subject: [PATCH 1/2] fix(cli): Actually run single-threaded --- crates/typos-cli/src/bin/typos-cli/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index 629e66698..bcaaf1880 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -225,7 +225,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult { 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()) From eb99975267fd41dfc3118a870dd4944ff7c58ac7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Feb 2024 16:06:19 -0600 Subject: [PATCH 2/2] feat(cli): Add a --sort flag --- crates/typos-cli/src/bin/typos-cli/args.rs | 4 ++++ crates/typos-cli/src/bin/typos-cli/main.rs | 9 ++++++++- crates/typos-cli/tests/cmd/config-disallowed.toml | 1 + crates/typos-cli/tests/cmd/extend-ignore-re.toml | 2 +- crates/typos-cli/tests/cmd/file-list-stdin.toml | 2 +- crates/typos-cli/tests/cmd/help.toml | 1 + crates/typos-cli/tests/cmd/ignore-line.toml | 2 +- 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/typos-cli/src/bin/typos-cli/args.rs b/crates/typos-cli/src/bin/typos-cli/args.rs index 37a1a04aa..2b93086c5 100644 --- a/crates/typos-cli/src/bin/typos-cli/args.rs +++ b/crates/typos-cli/src/bin/typos-cli/args.rs @@ -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, diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index bcaaf1880..fbf505a12 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -221,7 +221,11 @@ 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); @@ -233,6 +237,9 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult { .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() { diff --git a/crates/typos-cli/tests/cmd/config-disallowed.toml b/crates/typos-cli/tests/cmd/config-disallowed.toml index 318561110..68dfec32c 100644 --- a/crates/typos-cli/tests/cmd/config-disallowed.toml +++ b/crates/typos-cli/tests/cmd/config-disallowed.toml @@ -1,4 +1,5 @@ bin.name = "typos" +args = "--sort" status.code = 2 stdin = "" stdout = """ diff --git a/crates/typos-cli/tests/cmd/extend-ignore-re.toml b/crates/typos-cli/tests/cmd/extend-ignore-re.toml index f025d7cdd..74c74079b 100644 --- a/crates/typos-cli/tests/cmd/extend-ignore-re.toml +++ b/crates/typos-cli/tests/cmd/extend-ignore-re.toml @@ -1,5 +1,5 @@ bin.name = "typos" -args = "-j1" +args = "--sort" stdin = "" stdout = """ error: `hello` should be `goodbye` diff --git a/crates/typos-cli/tests/cmd/file-list-stdin.toml b/crates/typos-cli/tests/cmd/file-list-stdin.toml index 108965f96..aaad0e1e0 100644 --- a/crates/typos-cli/tests/cmd/file-list-stdin.toml +++ b/crates/typos-cli/tests/cmd/file-list-stdin.toml @@ -1,5 +1,5 @@ bin.name = "typos" -args = "--file-list -" +args = "--sort --file-list -" stdin = """ b.fail d.fail diff --git a/crates/typos-cli/tests/cmd/help.toml b/crates/typos-cli/tests/cmd/help.toml index 25d4cee42..c680b5423 100644 --- a/crates/typos-cli/tests/cmd/help.toml +++ b/crates/typos-cli/tests/cmd/help.toml @@ -11,6 +11,7 @@ Arguments: Options: --file-list Read the list of newline separated paths from file or stdin (if `-`) -j, --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 diff --git a/crates/typos-cli/tests/cmd/ignore-line.toml b/crates/typos-cli/tests/cmd/ignore-line.toml index 715b2d52d..7a5eae202 100644 --- a/crates/typos-cli/tests/cmd/ignore-line.toml +++ b/crates/typos-cli/tests/cmd/ignore-line.toml @@ -1,5 +1,5 @@ bin.name = "typos" -stdin = "" +stdin = "--sort" stdout = """ error: `hello` should be `goodbye` --> ./file.ignore:1:1