Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: ESLint support #321

Open
tennox opened this issue Mar 11, 2025 · 2 comments
Open

request: ESLint support #321

tennox opened this issue Mar 11, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@tennox
Copy link

tennox commented Mar 11, 2025

(Originally requested in upstream: numtide/treefmt#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 👍

@tennox tennox added the enhancement New feature or request label Mar 11, 2025
@tennox
Copy link
Author

tennox commented Mar 18, 2025

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 = []

@typedrat
Copy link

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 = [];
      };
    };
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants