Skip to content

Commit

Permalink
add additional linter & dotimportwhitelist
Browse files Browse the repository at this point in the history
New config field additionalLinters to add linters for specific needs
New config field dotImportWhitelist to exclude specific libraries from dot import linter
  • Loading branch information
IvoGoman committed Sep 20, 2023
1 parent febbc44 commit eecead4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ golangciLint:
- (*net/http.Client).Do
skipDirs:
- easypg/migrate/*
additionalLinters:
- ginkgolinter
dotImportWhitelist:
- github.com/onsi/ginkgo/v2
```

The `make check` and `make static-check` targets use [`golangci-lint`](https://golangci-lint.run) to lint your code.
Expand All @@ -237,6 +241,10 @@ and a list of functions to be excluded from `errcheck` linter in `errcheckExclud
Refer to [`errcheck`'s README](https://github.com/kisielk/errcheck#excluding-functions) for info on the format
for function signatures that `errcheck` accepts.

With `additionalLinters` you can add a list of extra linters to be enabled in the generated config file. The list of available linters can be found [here](https://golangci-lint.run/usage/linters/).

With `dotImportWhitelist` it is possible to exclude libraries that are usually dot imported such as Ginkgo and Gomega from the `stylecheck` linter. The list expects the full import path of the library.

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.

### `goreleaser`
Expand Down
8 changes: 5 additions & 3 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ type GolangConfiguration struct {

// GolangciLintConfiguration appears in type Configuration.
type GolangciLintConfiguration struct {
CreateConfig bool `yaml:"createConfig"`
ErrcheckExcludes []string `yaml:"errcheckExcludes"`
SkipDirs []string `yaml:"skipDirs"`
CreateConfig bool `yaml:"createConfig"`
ErrcheckExcludes []string `yaml:"errcheckExcludes"`
SkipDirs []string `yaml:"skipDirs"`
AdditionalLinters []string `yaml:"additionalLinters"`
DotImportWhitelist []string `yaml:"dotImportWhitelist"`
}

type GoreleaserConfiguration struct {
Expand Down
18 changes: 18 additions & 0 deletions internal/golangcilint/golangci_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ linters-settings:
- unnecessaryDefer
- weakCond
- yodaStyleExpr
{{- if .DotImportWhitelist }}
stylecheck:
{{- if .DotImportWhitelist }}
dot-import-whitelist:
{{- range .DotImportWhitelist }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
goimports:
# Put local imports after 3rd-party packages.
local-prefixes: {{ .ModulePath }}
Expand Down Expand Up @@ -175,6 +184,11 @@ linters:
- unused
- usestdlibvars
- whitespace
{{- if .AdditionalLinters }}
{{- range .AdditionalLinters }}
- {{ . }}
{{- end }}
{{- end }}
`, "\t", " "))))

type configTmplData struct {
Expand All @@ -183,6 +197,8 @@ type configTmplData struct {
MisspellIgnoreWords []string
ErrcheckExcludes []string
SkipDirs []string
DotImportWhitelist []string
AdditionalLinters []string
}

func RenderConfig(cfg core.GolangciLintConfiguration, vendoring bool, modulePath string, misspellIgnoreWords []string) {
Expand All @@ -199,6 +215,8 @@ func RenderConfig(cfg core.GolangciLintConfiguration, vendoring bool, modulePath
MisspellIgnoreWords: misspellIgnoreWords,
ErrcheckExcludes: cfg.ErrcheckExcludes,
SkipDirs: cfg.SkipDirs,
DotImportWhitelist: cfg.DotImportWhitelist,
AdditionalLinters: cfg.AdditionalLinters,
}))
fmt.Fprintln(f) // empty line at end

Expand Down

0 comments on commit eecead4

Please sign in to comment.