@@ -72,6 +72,8 @@ fn check_impl(
72
72
let shell_lint = lint_args. contains ( & "shell:lint" ) || shell_all;
73
73
let cpp_all = lint_args. contains ( & "cpp" ) ;
74
74
let cpp_fmt = lint_args. contains ( & "cpp:fmt" ) || cpp_all;
75
+ let spellcheck_all = lint_args. contains ( & "spellcheck" ) ;
76
+ let spellcheck_fix = lint_args. contains ( & "spellcheck:fix" ) ;
75
77
76
78
let mut py_path = None ;
77
79
@@ -224,6 +226,22 @@ fn check_impl(
224
226
shellcheck_runner ( & merge_args ( & cfg_args, & file_args_shc) ) ?;
225
227
}
226
228
229
+ if spellcheck_all || spellcheck_fix {
230
+ let config_path = root_path. join ( "typos.toml" ) ;
231
+ let mut args =
232
+ // sync target files with .github/workflows/ci.yml
233
+ vec ! [ "-c" , config_path. as_os_str( ) . to_str( ) . unwrap( ) , "./compiler" , "./library" ] ;
234
+
235
+ if spellcheck_all {
236
+ eprintln ! ( "spellcheck files" ) ;
237
+ spellcheck_runner ( & args) ?;
238
+ } else if spellcheck_fix {
239
+ eprintln ! ( "spellcheck files and fix" ) ;
240
+ args. push ( "--write-changes" ) ;
241
+ spellcheck_runner ( & args) ?;
242
+ }
243
+ }
244
+
227
245
Ok ( ( ) )
228
246
}
229
247
@@ -491,6 +509,25 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
491
509
if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
492
510
}
493
511
512
+ /// Check that spellchecker is installed then run it at the given path
513
+ fn spellcheck_runner ( args : & [ & str ] ) -> Result < ( ) , Error > {
514
+ match Command :: new ( "typos" ) . arg ( "--version" ) . status ( ) {
515
+ Ok ( _) => ( ) ,
516
+ Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
517
+ return Err ( Error :: MissingReq (
518
+ "typos" ,
519
+ "spellcheck file checks" ,
520
+ // sync version with .github/workflows/ci.yml
521
+ Some ( "install tool via `cargo install typos-cli@1.28.2`" . to_owned ( ) ) ,
522
+ ) ) ;
523
+ }
524
+ Err ( e) => return Err ( e. into ( ) ) ,
525
+ }
526
+
527
+ let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
528
+ if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
529
+ }
530
+
494
531
/// Check git for tracked files matching an extension
495
532
fn find_with_extension (
496
533
root_path : & Path ,
0 commit comments