New formatter: Add golangci-lint support
treefmt-nix currently doesn't support golangci-lint, a popular and comprehensive Go linter. Go developers have to use separate tools or less comprehensive linters.
Proposed Solution
Add programs/golangci-lint.nix with comprehensive configuration options, following patterns from typos.nix and prettier.nix:
enableLinters/disableLinters: Control which linters to runconfigFile: Path to custom config filetimeout: Set analysis timeoutconcurrency: Configure CPU usagebuildTags: Specify build tagstests: Control test file analysisfastOnly: Run only fast linters
Implementation
I can implement this new formatter with:
- Full golangci-lint CLI option support
- Follows established treefmt-nix patterns
- Comprehensive configuration options
- Auto-fixing capabilities (
--fixflag)
This would allow users to configure golangci-lint declaratively:
programs.golangci-lint = {
enable = true;
enableLinters = [ "govet" "errcheck" "staticcheck" ];
timeout = "5m";
tests = false;
};
As treefmt invokes golangci-lint with the individual files to be linted / formatted, I run into errors like this:
level=error msg="[linters_context] typechecking error: named files must all be in one directory; have api-key-service/docs and api-key-service/gen-token"
Perhaps there should be an option to ignore the files passed by treefmt and just lint on ... (which is Go's notation for a recursive tree starting from .)?
When wrapping the golangci-lint formatter in a custom script that uses ... as the argument to the golangci-lint binary, I run into the following error:
Error: parallel golangci-lint is running
The command is terminated due to an error: parallel golangci-lint is running
treefmt seems to make the assumption that running its formatters in parallel is safe, which golangci-lint doesn't like.
treefmtseems to make the assumption that running its formatters in parallel is safe, whichgolangci-lintdoesn't like.
golangci-lint doesn't comply with the treefmt spec: https://treefmt.com/formatters-spec/
golangci-lint doesn't comply with the treefmt spec: https://treefmt.com/formatters-spec/
Yeah. I wonder why it's been added then :D