Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- cyclop
- decorder
- depguard
- docenv
- dogsled
- dupl
- dupword
Expand Down Expand Up @@ -138,6 +139,7 @@ linters:
- cyclop
- decorder
- depguard
- docenv
- dogsled
- dupl
- dupword
Expand Down Expand Up @@ -394,6 +396,11 @@ linters-settings:
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package

docenv:
# Set custom env tag name.
# Default: env
tag-name: env

dogsled:
# Checks assignments with too many blank identifiers.
# Default: 2
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ require (
github.com/ettle/strcase v0.2.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/g4s8/envdoc v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-toolsmith/astcast v1.1.0 // indirect
github.com/go-toolsmith/astcopy v1.1.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var defaultLintersSettings = LintersSettings{
DisableDecOrderCheck: true,
DisableInitFuncFirstCheck: true,
},
Docenv: DocenvSettings{
TagName: "env",
},
Dogsled: DogsledSettings{
MaxBlankIdentifiers: 2,
},
Expand Down Expand Up @@ -206,6 +209,7 @@ type LintersSettings struct {
Cyclop Cyclop
Decorder DecorderSettings
Depguard DepGuardSettings
Docenv DocenvSettings
Dogsled DogsledSettings
Dupl DuplSettings
DupWord DupWordSettings
Expand Down Expand Up @@ -355,6 +359,10 @@ type DecorderSettings struct {
DisableInitFuncFirstCheck bool `mapstructure:"disable-init-func-first-check"`
}

type DocenvSettings struct {
TagName string `mapstructure:"tag-name"`
}

type DogsledSettings struct {
MaxBlankIdentifiers int `mapstructure:"max-blank-identifiers"`
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/golinters/docenv/docenv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package docenv

import (
"github.com/g4s8/envdoc/linter"

"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func New(cfg *config.DocenvSettings) *goanalysis.Linter {
opts := []linter.Option{linter.WithNoComments()}
if cfg != nil {
opts = append(opts, linter.WithEnvName(cfg.TagName))
}

a := linter.NewAnlyzer(false, opts...)
return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
11 changes: 11 additions & 0 deletions pkg/golinters/docenv/docenv_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package docenv

import (
"testing"

"github.com/golangci/golangci-lint/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
14 changes: 14 additions & 0 deletions pkg/golinters/docenv/testdata/docenv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//golangcitest:args -Edocenv
package testdata

type Config struct {
// Host name.
Host string `env:"HOST"`

// Port number.
Port int `env:"PORT"`

Undocumented string `env:"UNDOCUMENTED"` // want "field `Undocumented` with `env` tag should have a documentation comment"

NotEnv string
}
15 changes: 15 additions & 0 deletions pkg/golinters/docenv/testdata/docenv_custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Edocenv
//golangcitest:config_path testdata/docenv_custom.yml
package testdata

type Config struct {
// Host name.
Host string `foo:"HOST"`

// Port number.
Port int `foo:"PORT"`

Undocumented string `foo:"UNDOCUMENTED"` // want "field `Undocumented` with `foo` tag should have a documentation comment"

NotEnv string
}
3 changes: 3 additions & 0 deletions pkg/golinters/docenv/testdata/docenv_custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
docenv:
tag-name: foo
6 changes: 6 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/golangci/golangci-lint/pkg/golinters/cyclop"
"github.com/golangci/golangci-lint/pkg/golinters/decorder"
"github.com/golangci/golangci-lint/pkg/golinters/depguard"
"github.com/golangci/golangci-lint/pkg/golinters/docenv"
"github.com/golangci/golangci-lint/pkg/golinters/dogsled"
"github.com/golangci/golangci-lint/pkg/golinters/dupl"
"github.com/golangci/golangci-lint/pkg/golinters/dupword"
Expand Down Expand Up @@ -203,6 +204,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithPresets(linter.PresetStyle, linter.PresetImport, linter.PresetModule).
WithURL("https://github.com/OpenPeeDeeP/depguard"),

linter.NewConfig(docenv.New(&cfg.LintersSettings.Docenv)).
WithSince("v1.63.0").
WithPresets(linter.PresetComment).
WithURL("https://github.com/g4s8/envdoc/tree/master/docenv"),

linter.NewConfig(dogsled.New(&cfg.LintersSettings.Dogsled)).
WithSince("v1.19.0").
WithPresets(linter.PresetStyle).
Expand Down