setup CI and tidy to use typos for spellchecking and fix few typos

This commit is contained in:
klensy 2024-12-07 13:51:08 +03:00
parent f51c9870ba
commit c76d032f01
129 changed files with 326 additions and 175 deletions

View file

@ -104,7 +104,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.tcx.sess.source_map().lookup_char_pos(BytePos(offset.bytes().try_into().unwrap()));
let name = fn_instance.to_string();
let filename = lo.file.name.prefer_remapped_unconditionaly().to_string();
let filename = lo.file.name.prefer_remapped_unconditionally().to_string();
interp_ok((fn_instance, lo, name, filename))
}

View file

@ -72,6 +72,8 @@ fn check_impl(
let shell_lint = lint_args.contains(&"shell:lint") || shell_all;
let cpp_all = lint_args.contains(&"cpp");
let cpp_fmt = lint_args.contains(&"cpp:fmt") || cpp_all;
let spellcheck_all = lint_args.contains(&"spellcheck");
let spellcheck_fix = lint_args.contains(&"spellcheck:fix");
let mut py_path = None;
@ -224,6 +226,27 @@ fn check_impl(
shellcheck_runner(&merge_args(&cfg_args, &file_args_shc))?;
}
if spellcheck_all || spellcheck_fix {
let config_path = root_path.join("typos.toml");
// sync target files with .github/workflows/spellcheck.yml
let mut args = vec![
"-c",
config_path.as_os_str().to_str().unwrap(),
"./compiler",
"./library",
"./src/bootstrap",
"./src/librustdoc",
];
if spellcheck_all {
eprintln!("spellcheck files");
} else if spellcheck_fix {
eprintln!("spellcheck files and fix");
args.push("--write-changes");
}
spellcheck_runner(&args)?;
}
Ok(())
}
@ -491,6 +514,36 @@ fn shellcheck_runner(args: &[&OsStr]) -> Result<(), Error> {
if status.success() { Ok(()) } else { Err(Error::FailedCheck("shellcheck")) }
}
/// Check that spellchecker is installed then run it at the given path
fn spellcheck_runner(args: &[&str]) -> Result<(), Error> {
// sync version with .github/workflows/spellcheck.yml
let expected_version = "typos-cli 1.34.0";
match Command::new("typos").arg("--version").output() {
Ok(o) => {
let stdout = String::from_utf8_lossy(&o.stdout);
if stdout.trim() != expected_version {
return Err(Error::Version {
program: "typos",
required: expected_version,
installed: stdout.trim().to_string(),
});
}
}
Err(e) if e.kind() == io::ErrorKind::NotFound => {
return Err(Error::MissingReq(
"typos",
"spellcheck file checks",
// sync version with .github/workflows/spellcheck.yml
Some("install tool via `cargo install typos-cli@1.34.0`".to_owned()),
));
}
Err(e) => return Err(e.into()),
}
let status = Command::new("typos").args(args).status()?;
if status.success() { Ok(()) } else { Err(Error::FailedCheck("typos")) }
}
/// Check git for tracked files matching an extension
fn find_with_extension(
root_path: &Path,