@@ -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
@@ -244,6 +246,22 @@ fn check_impl(
244
246
shellcheck_runner ( & merge_args ( & cfg_args, & file_args_shc) ) ?;
245
247
}
246
248
249
+ if spellcheck_all || spellcheck_fix {
250
+ let config_path = root_path. join ( "typos.toml" ) ;
251
+ let mut args =
252
+ // sync target files with .github/workflows/ci.yml
253
+ vec ! [ "-c" , config_path. as_os_str( ) . to_str( ) . unwrap( ) , "./compiler" , "./library" ] ;
254
+
255
+ if spellcheck_all {
256
+ eprintln ! ( "spellcheck files" ) ;
257
+ spellcheck_runner ( & args) ?;
258
+ } else if spellcheck_fix {
259
+ eprintln ! ( "spellcheck files and fix" ) ;
260
+ args. push ( "--write-changes" ) ;
261
+ spellcheck_runner ( & args) ?;
262
+ }
263
+ }
264
+
247
265
Ok ( ( ) )
248
266
}
249
267
@@ -453,6 +471,25 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
453
471
if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
454
472
}
455
473
474
+ /// Check that spellchecker is installed then run it at the given path
475
+ fn spellcheck_runner ( args : & [ & str ] ) -> Result < ( ) , Error > {
476
+ match Command :: new ( "typos" ) . arg ( "--version" ) . status ( ) {
477
+ Ok ( _) => ( ) ,
478
+ Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
479
+ return Err ( Error :: MissingReq (
480
+ "typos" ,
481
+ "spellcheck file checks" ,
482
+ // sync version with .github/workflows/ci.yml
483
+ Some ( "install tool via `cargo install typos-cli@1.28.2`" . to_owned ( ) ) ,
484
+ ) ) ;
485
+ }
486
+ Err ( e) => return Err ( e. into ( ) ) ,
487
+ }
488
+
489
+ let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
490
+ if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
491
+ }
492
+
456
493
/// Check git for tracked files matching an extension
457
494
fn find_with_extension (
458
495
root_path : & Path ,
0 commit comments