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