#![doc = include_str!("../README.md")]
use anyhow::Result;
use bpaf::Bpaf;
pub use lintel_validate::Reporter;
#[derive(Debug, Clone, Bpaf)]
#[bpaf(generate(check_args_inner))]
pub struct CheckArgs {
#[bpaf(long("fix"), switch)]
pub fix: bool,
#[bpaf(external(lintel_validate::validate_args))]
pub validate: lintel_validate::ValidateArgs,
}
pub fn check_args() -> impl bpaf::Parser<CheckArgs> {
check_args_inner()
}
pub async fn run(args: &mut CheckArgs, reporter: &mut dyn Reporter) -> Result<bool> {
let original_globs = args.validate.globs.clone();
let original_exclude = args.validate.exclude.clone();
let had_validation_errors = lintel_validate::run(&mut args.validate, reporter).await?;
if args.fix {
let fixed = lintel_format::fix_format(&original_globs, &original_exclude)?;
if fixed > 0 {
eprintln!("Fixed formatting in {fixed} file(s).");
}
Ok(had_validation_errors)
} else {
let format_diagnostics = lintel_format::check_format(&original_globs, &original_exclude)?;
let had_format_errors = !format_diagnostics.is_empty();
for diag in format_diagnostics {
eprintln!("{:?}", miette::Report::new(diag));
}
Ok(had_validation_errors || had_format_errors)
}
}