treefmt-nix
treefmt-nix copied to clipboard
request: ESLint support
(Originally requested in upstream: https://github.com/numtide/treefmt/discussions/537)
Would be awesome to have eslint integration - especially with the new formatter rules: https://eslint.style/
I use https://github.com/antfu/eslint-config for most of my JS projects 👍
A simple example:
[formatter.eslint]
command = "eslint"
options = ["--fix", "--quiet"]
includes = [ "*.js", "*.jsx", "*.ts", "*.tsx" ] # But I'm not sure what to put here, as eslint is able to format MANY files 🤔
excludes = []
It's a work project so I can't show you the whole flake, but here's the relevant part of my custom formatter config for ESLint, somewhat complicated to handle the fact that I'm using a monorepo with different configurations in different directories.
treefmt.config = {
settings = {
formatter = {
"eslint" = {
command = lib.getExe pkgs.bash;
options = [
"-euc"
''
cd "$(dirname "$1")"
${lib.getExe' pkgs.eslint "eslint"} --fix --quiet "$(basename "$1")"
''
"--"
];
includes = [
"*.js"
"*.mjs"
"*.cjs"
"*.jsx"
"*.mjsx"
"*.ts"
"*.tsx"
"*.mtsx"
];
excludes = [];
};
};
};
};