sane-fmt 0.18.1

Opinionated code formatter for TypeScript and JavaScript
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::{fs, io, path::Path};

/// Overwrite unformatted file if `--write` is present.
pub type Act = fn(&Path, &str) -> io::Result<()>;

/// Lookup a function that may write unformatted file.
/// * If `--write` is present, the returning function would overwrite
///   unformatted files with formatted content.
/// * Otherwise, the returning function would do nothing
pub fn get(write: bool) -> Act {
    if write {
        |path, content| fs::write(path, content)
    } else {
        |_, _| Ok(())
    }
}