specta_typescript/
formatter.rs

1use std::{io, path::Path, process::Command};
2
3use crate::typescript::FormatterFn;
4
5/// Format the specified file using [ESLint](https://eslint.org).
6pub fn eslint(file: &Path) -> io::Result<()> {
7    Command::new("eslint")
8        .arg("--fix")
9        .arg(file)
10        .output()
11        .map(|_| ())
12        .map_err(|e| io::Error::new(io::ErrorKind::Other, e))
13}
14
15// Assert that the function signature matches the expected type.
16const _: FormatterFn = eslint;
17
18/// Format the specified file using [Prettier](https://prettier.io).
19pub fn prettier(file: &Path) -> io::Result<()> {
20    Command::new("prettier")
21        .arg("--write")
22        .arg(file)
23        .output()
24        .map(|_| ())
25        .map_err(|e| io::Error::new(io::ErrorKind::Other, e))
26}
27
28// Assert that the function signature matches the expected type.
29const _: FormatterFn = prettier;
30
31/// Format the specified file using [Biome](https://prettier.io).
32pub fn biome(file: &Path) -> io::Result<()> {
33    Command::new("biome")
34        .arg("format")
35        .arg(file)
36        .output()
37        .map(|_| ())
38        .map_err(|e| io::Error::new(io::ErrorKind::Other, e))
39}
40
41// Assert that the function signature matches the expected type.
42const _: FormatterFn = biome;