vdev/commands/check/
fmt.rs

1use anyhow::Result;
2
3use crate::{app, commands::fmt::PRETTIER_EXTENSIONS, utils::git::git_ls_files};
4
5/// Check that all files are formatted properly
6#[derive(clap::Args, Debug)]
7#[command()]
8pub struct Cli {}
9
10impl Cli {
11    pub fn exec(self) -> Result<()> {
12        info!("Checking style (trailing spaces, line endings)...");
13        app::exec("scripts/check-style.sh", ["--all"], true)?;
14
15        info!("Checking Rust formatting...");
16        app::exec("cargo", ["fmt", "--", "--check"], true)?;
17
18        for ext in PRETTIER_EXTENSIONS {
19            let files = git_ls_files(Some(ext))?;
20            if files.is_empty() {
21                continue;
22            }
23            info!("Checking prettier formatting for {ext} files...");
24            let args: Vec<&str> = ["--ignore-path", ".prettierignore", "--check"]
25                .into_iter()
26                .chain(files.iter().map(String::as_str))
27                .collect();
28            app::exec("prettier", &args, true)?;
29        }
30
31        Ok(())
32    }
33}