Skip to content

Commit e81004a

Browse files
authored
Merge pull request #403 from sapcc/add_revive_option
add option to enable revive in golangci_lint
2 parents a2d622d + 70e6d39 commit e81004a

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ linters:
172172
exclusions:
173173
generated: lax
174174
presets:
175-
- comments
176175
- common-false-positives
177176
- legacy
178177
- std-error-handling
179178
rules:
180179
- linters:
181180
- bodyclose
181+
- revive
182182
path: _test\.go
183183
# It is idiomatic Go to reuse the name 'err' with ':=' for subsequent errors.
184184
# Ref: https://go.dev/doc/effective_go#redeclaration

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ golangciLint:
252252
skipDirs:
253253
- easypg/migrate/*
254254
timeout: 3m
255+
reviveRules:
256+
- name: exported
257+
arguments:
258+
- checkPrivateReceivers
259+
- disableChecksOnConstants
255260
```
256261

257262
The `make check` and `make static-check` targets use [`golangci-lint`](https://golangci-lint.run) to lint your code.
@@ -267,6 +272,12 @@ for function signatures that `errcheck` accepts.
267272

268273
`timeout` changes the `run.timeout` option. This should only be necessary to bump when in big projects like ones that use Kubernetes.
269274

275+
`reviveRules` can be specified to activate the [revive](https://github.com/mgechev/revive) linter with only the mentioned rules.
276+
A rule must have a `name` and can optionally have `arguments`, which specify how the rule behaves.
277+
In the snippet above, the [exported](https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported)-rule is configured.
278+
It enforces comments on exported functions and types.
279+
If no `reviveRules` are specified, `revive` is not configured to be used.
280+
270281
Take a look at `go-makefile-maker`'s own [`golangci-lint` config file](./.golangci.yaml) for an up-to-date example of what the generated config would look like.
271282

272283
### `goReleaser`

internal/core/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,18 @@ type GolangConfiguration struct {
105105
SetGoModVersion bool `yaml:"setGoModVersion"`
106106
}
107107

108+
type ReviveRule struct {
109+
Name string `yaml:"name"`
110+
Arguments []string `yaml:"arguments"`
111+
}
112+
108113
// GolangciLintConfiguration appears in type Configuration.
109114
type GolangciLintConfiguration struct {
110115
CreateConfig bool `yaml:"createConfig"`
111116
ErrcheckExcludes []string `yaml:"errcheckExcludes"`
112117
SkipDirs []string `yaml:"skipDirs"`
113118
Timeout time.Duration `yaml:"timeout"`
119+
ReviveRules []ReviveRule `yaml:"reviveRules"`
114120
}
115121

116122
type GoReleaserConfiguration struct {

internal/golangcilint/golangci.yaml.tmpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ linters:
6464
- perfsprint
6565
- predeclared
6666
- rowserrcheck
67+
{{- if .ReviveRules }}
68+
- revive
69+
{{- end }}
6770
- sqlclosecheck
6871
- staticcheck
6972
- unconvert
@@ -161,6 +164,19 @@ linters:
161164
perfsprint:
162165
# modernize generates nicer fix code
163166
concat-loop: false
167+
{{- if .ReviveRules }}
168+
revive:
169+
rules:
170+
{{- range .ReviveRules }}
171+
- name: {{ .Name }}
172+
{{- if .Arguments }}
173+
arguments:
174+
{{- range .Arguments }}
175+
- {{ . }}
176+
{{- end }}
177+
{{- end }}
178+
{{- end }}
179+
{{- end }}
164180
staticcheck:
165181
dot-import-whitelist:
166182
- github.com/majewsky/gg/option
@@ -185,13 +201,13 @@ linters:
185201
exclusions:
186202
generated: lax
187203
presets:
188-
- comments
189204
- common-false-positives
190205
- legacy
191206
- std-error-handling
192207
rules:
193208
- linters:
194209
- bodyclose
210+
- revive
195211
path: _test\.go
196212
# It is idiomatic Go to reuse the name 'err' with ':=' for subsequent errors.
197213
# Ref: https://go.dev/doc/effective_go#redeclaration

internal/golangcilint/golangci_lint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ func RenderConfig(cfg core.Configuration, sr golang.ScanResult) {
3535
"ErrcheckExcludes": cfg.GolangciLint.ErrcheckExcludes,
3636
"SkipDirs": cfg.GolangciLint.SkipDirs,
3737
"Timeout": timeout,
38+
"ReviveRules": cfg.GolangciLint.ReviveRules,
3839
}))
3940
}

0 commit comments

Comments
 (0)