@@ -72,6 +72,8 @@ fn check_impl(
7272 let shell_lint = lint_args. contains ( & "shell:lint" ) || shell_all;
7373 let cpp_all = lint_args. contains ( & "cpp" ) ;
7474 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" ) ;
7577
7678 let mut py_path = None ;
7779
@@ -244,6 +246,22 @@ fn check_impl(
244246 shellcheck_runner ( & merge_args ( & cfg_args, & file_args_shc) ) ?;
245247 }
246248
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+
247265 Ok ( ( ) )
248266}
249267
@@ -453,6 +471,25 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
453471 if status. success ( ) { Ok ( ( ) ) } else { Err ( Error :: FailedCheck ( "shellcheck" ) ) }
454472}
455473
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 [email protected] `" . 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+
456493/// Check git for tracked files matching an extension
457494fn find_with_extension (
458495 root_path : & Path ,
0 commit comments