forked from numtide/treefmt-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgolangci-lint.nix
More file actions
182 lines (166 loc) · 4.65 KB
/
Copy pathgolangci-lint.nix
File metadata and controls
182 lines (166 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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");
};
};
}