Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ functions.
<!-- `> bash ./supported-programs.sh` -->

<!-- BEGIN mdsh -->
`treefmt-nix` currently supports 115 formatters:
`treefmt-nix` currently supports 116 formatters:

* [actionlint](programs/actionlint.nix)
* [aiken](programs/aiken.nix)
Expand Down Expand Up @@ -266,6 +266,7 @@ functions.
* [gofmt](programs/gofmt.nix)
* [gofumpt](programs/gofumpt.nix)
* [goimports](programs/goimports.nix)
* [golangci-lint](programs/golangci-lint.nix)
* [golines](programs/golines.nix)
* [google-java-format](programs/google-java-format.nix)
* [hclfmt](programs/hclfmt.nix)
Expand Down
6 changes: 6 additions & 0 deletions examples/formatter-golangci-lint.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example generated by ../examples.sh
[formatter.golangci-lint]
command = "golangci-lint"
excludes = ["vendor/*"]
includes = ["*.go"]
options = ["run", "--fix"]
182 changes: 182 additions & 0 deletions programs/golangci-lint.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
config,
lib,
mkFormatterModule,
...
}:
let
cfg = config.programs.golangci-lint;
in
{
meta.maintainers = [ "Dauliac" ];

imports = [
(mkFormatterModule {
name = "golangci-lint";
package = "golangci-lint";
args = [
"run"
"--fix"
];
includes = [ "*.go" ];
excludes = [ "vendor/*" ];
})
];

options.programs.golangci-lint = {
configFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = ".golangci.yml";
description = "Path to golangci-lint configuration file";
};

noConfig = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Don't read any configuration file";
};

enableLinters = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [
"govet"
"errcheck"
"staticcheck"
];
description = "Enable specific linters";
};

disableLinters = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "typecheck" ];
description = "Disable specific linters";
};

enableOnly = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [
"govet"
"gofmt"
];
description = "Override configuration to run only specific linter(s)";
};

timeout = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "5m";
description = "Timeout for total work (e.g., '5m', '1h', '10s')";
};

concurrency = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 4;
description = "Number of CPUs to use (auto-configured by default)";
};

buildTags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [
"integration"
"e2e"
];
description = "Build tags to use during analysis";
};

tests = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Analyze test files";
};

maxIssuesPerLinter = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 50;
description = "Maximum issues per linter (default: 50)";
};

maxSameIssues = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
example = 3;
description = "Maximum count of same issues (default: 3)";
};

newFromRev = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "HEAD~1";
description = "Show only new issues created after git revision REV";
};

fastOnly = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Run only fast linters from enabled linters set";
};

verbose = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable verbose output";
};
};

config = lib.mkIf cfg.enable {
settings.formatter.golangci-lint = {
command = "${cfg.package}/bin/golangci-lint";
options =
(lib.optionals (cfg.configFile != null) [
"--config"
cfg.configFile
])
++ (lib.optionals cfg.noConfig [ "--no-config" ])
++ (lib.optionals (cfg.enableLinters != [ ]) [
"--enable"
(lib.concatStringsSep "," cfg.enableLinters)
])
++ (lib.optionals (cfg.disableLinters != [ ]) [
"--disable"
(lib.concatStringsSep "," cfg.disableLinters)
])
++ (lib.optionals (cfg.enableOnly != [ ]) [
"--enable-only"
(lib.concatStringsSep "," cfg.enableOnly)
])
++ (lib.optionals (cfg.timeout != null) [
"--timeout"
cfg.timeout
])
++ (lib.optionals (cfg.concurrency != null) [
"--concurrency"
(toString cfg.concurrency)
])
++ (lib.optionals (cfg.buildTags != [ ]) [
"--build-tags"
(lib.concatStringsSep "," cfg.buildTags)
])
++ (lib.optionals (cfg.maxIssuesPerLinter != null) [
"--max-issues-per-linter"
(toString cfg.maxIssuesPerLinter)
])
++ (lib.optionals (cfg.maxSameIssues != null) [
"--max-same-issues"
(toString cfg.maxSameIssues)
])
++ (lib.optionals (cfg.newFromRev != null) [
"--new-from-rev"
cfg.newFromRev
])
++ (lib.optional (!cfg.tests) "--skip-files-test")
++ (lib.optional cfg.fastOnly "--fast")
++ (lib.optional cfg.verbose "--verbose");
};
};
}