@@ -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
@@ -215,6 +217,22 @@ fn check_impl(
215
217
shellcheck_runner ( & merge_args ( & cfg_args, & file_args_shc) ) ?;
216
218
}
217
219
220
+ if spellcheck_all || spellcheck_fix {
221
+ let config_path = root_path. join ( "typos.toml" ) ;
222
+ let mut args =
223
+ // sync target files with .github/workflows/ci.yml
224
+ vec ! [ "-c" , config_path. as_os_str( ) . to_str( ) . unwrap( ) , "./compiler" , "./library" ] ;
225
+
226
+ if spellcheck_all {
227
+ eprintln ! ( "spellcheck files" ) ;
228
+ spellcheck_runner ( & args) ?;
229
+ } else if spellcheck_fix {
230
+ eprintln ! ( "spellcheck files and fix" ) ;
231
+ args. push ( "--write-changes" ) ;
232
+ spellcheck_runner ( & args) ?;
233
+ }
234
+ }
235
+
218
236
Ok ( ( ) )
219
237
}
220
238
@@ -482,6 +500,25 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
482
500
if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
483
501
}
484
502
503
+ /// Check that spellchecker is installed then run it at the given path
504
+ fn spellcheck_runner ( args : & [ & str ] ) -> Result < ( ) , Error > {
505
+ match Command :: new ( "typos" ) . arg ( "--version" ) . status ( ) {
506
+ Ok ( _) => ( ) ,
507
+ Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
508
+ return Err ( Error :: MissingReq (
509
+ "typos" ,
510
+ "spellcheck file checks" ,
511
+ // sync version with .github/workflows/ci.yml
512
+ Some ( "install tool via `cargo install typos-cli@1.28.2`" . to_owned ( ) ) ,
513
+ ) ) ;
514
+ }
515
+ Err ( e) => return Err ( e. into ( ) ) ,
516
+ }
517
+
518
+ let status = Command :: new ( "typos" ) . args ( args) . status ( ) ?;
519
+ if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "typos" ) ) }
520
+ }
521
+
485
522
/// Check git for tracked files matching an extension
486
523
fn find_with_extension (
487
524
root_path : & Path ,
0 commit comments