Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Documentation reference check #4286

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
17 changes: 17 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,20 @@ jobs:
env:
# needed for github-action-config.json generation
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Unshallow
run: git fetch --prune --unshallow
- name: Install Go
uses: actions/setup-go@v5
with:
# https://github.com/actions/setup-go#supported-version-syntax
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: ${{ env.GO_VERSION }}
- name: Check if documentation reference is up to date
run: HELP_RUN=2 go run cmd/golangci-lint/main.go -c .golangci.reference.yml
38 changes: 38 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,23 @@ run:
# Default: false
allow-parallel-runners: false

# Allow multiple golangci-lint instances running, but serialize them around a lock.
# If false, golangci-lint exits with an error if it fails to acquire file lock on start.
# Default: false
allow-serial-runners: true

# Print avg and max memory usage of golangci-lint and total time.
# Default: false
print-resources-usage: true

# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17
go: '1.19'

# Deprecated: use Timeout instead.
deadline: 5m


# output configuration options
output:
Expand Down Expand Up @@ -659,6 +671,8 @@ linters-settings:
# Check that each sentence starts with a capital letter.
# Default: false
capital: true
# Deprecated: use `Scope` instead
check-all: false

godox:
# Report any comments starting with keywords, this is useful for TODO or FIXME comments that
Expand Down Expand Up @@ -775,6 +789,10 @@ linters-settings:
ignored-functions:
- '^math\.'
- '^http\.StatusText$'
# Deprecated
settings:
deprecated:
deprecated: do not use

gomoddirectives:
# Allow local `replace` directives.
Expand Down Expand Up @@ -1505,6 +1523,14 @@ linters-settings:
# Default: 0.8
confidence: 0.1

error-code: 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the options I was not able to get help/documentation from where I found them in the code


warning-code: 0

directives:
name: example
severity: example

rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
- name: add-constant
Expand Down Expand Up @@ -2146,6 +2172,9 @@ linters-settings:
# Default: false
check-exported: true

# Deprecated: isn't supported anymore
algo: cha

unused:
# Mark all struct fields that have been written to as used.
# Default: true
Expand Down Expand Up @@ -2313,6 +2342,9 @@ linters-settings:
# This logic overrides force-err-cuddling among others.
force-short-decl-cuddling: false

structcheck:
exported-fields: false

# The custom section can be used to define linter plugins to be loaded at runtime.
# See README documentation for more info.
custom:
Expand All @@ -2328,6 +2360,8 @@ linters-settings:
# Optional.
original-url: github.com/golangci/example-linter

settings: symbol


linters:
# Disable all linters.
Expand Down Expand Up @@ -2698,6 +2732,10 @@ issues:
# Default: false
fix: true

# Show issues in any part of update files (requires new-from-rev or new-from-patch).
# Default: false
whole-files: true


severity:
# Set the default severity for issues.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/golangci/misspell v0.4.1
github.com/golangci/revgrep v0.5.2
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
github.com/google/go-cmp v0.6.0
github.com/gordonklaus/ineffassign v0.1.0
github.com/gostaticanalysis/forcetypeassert v0.1.0
github.com/gostaticanalysis/nilerr v0.1.1
Expand Down Expand Up @@ -151,7 +152,6 @@ require (
github.com/go-toolsmith/typep v1.1.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/comment v1.4.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
fs.BoolVar(&oc.UniqByLine, "uniq-by-line", true, wh("Make issues output unique by line"))
fs.BoolVar(&oc.SortResults, "sort-results", false, wh("Sort linter results"))
fs.BoolVar(&oc.PrintWelcomeMessage, "print-welcome", false, wh("Print welcome message"))
fs.StringVar(&oc.PathPrefix, "path-prefix", "", wh("Path prefix to add to output"))
hideFlag("print-welcome") // no longer used
fs.StringVar(&oc.PathPrefix, "path-prefix", "", wh("Path prefix to add to output"))

fs.BoolVar(&cfg.InternalCmdTest, "internal-cmd-test", false, wh("Option is used only for testing golangci-lint command, don't use it"))
if err := fs.MarkHidden("internal-cmd-test"); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (

// Config encapsulates the config data specified in the golangci yaml config file.
type Config struct {
cfgDir string // The directory containing the golangci config file.
Run Run

Output Output

Run Run `mapstructure:"run"`
Output Output
LintersSettings LintersSettings `mapstructure:"linters-settings"`
Linters Linters
Issues Issues
Severity Severity
Version Version

InternalCmdTest bool `mapstructure:"internal-cmd-test"` // Option is used only for testing golangci-lint command, don't use it
InternalTest bool // Option is used only for testing golangci-lint code, don't use it
InternalTest bool // Option is used only for testing golangci-lint code, don't use it

// Internal usage options, not available to users
cfgDir string `mapstructure:"-"` // The directory containing the golangci config file.
Version Version `mapstructure:"-"`
InternalCmdTest bool `mapstructure:"-"` // Option is used only for testing golangci-lint command, don't use it
}

// GetConfigDir returns the directory that contains golangci config file.
Expand Down
34 changes: 26 additions & 8 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ type LintersSettings struct {
GoModDirectives GoModDirectivesSettings
Gomodguard GoModGuardSettings
Gosec GoSecSettings
Gosimple StaticCheckSettings
Gosimple CommonStaticCheckSettings
Gosmopolitan GosmopolitanSettings
Govet GovetSettings
Grouper GrouperSettings
Expand Down Expand Up @@ -245,7 +245,7 @@ type LintersSettings struct {
Revive ReviveSettings
RowsErrCheck RowsErrCheckSettings
SlogLint SlogLintSettings
Staticcheck StaticCheckSettings
Staticcheck CommonStaticCheckSettings
Structcheck StructCheckSettings
Stylecheck StaticCheckSettings
TagAlign TagAlignSettings
Expand Down Expand Up @@ -774,19 +774,36 @@ type SlogLintSettings struct {
}

type StaticCheckSettings struct {
CommonStaticCheckSettings `mapstructure:",squash"`
Initialisms []string `mapstructure:"initialisms"`
DotImportWhitelist []string `mapstructure:"dot-import-whitelist"`
HTTPStatusCodeWhitelist []string `mapstructure:"http-status-code-whitelist"`
}

type CommonStaticCheckSettings struct {
// Deprecated: use the global `run.go` instead.
GoVersion string `mapstructure:"go"`

Checks []string `mapstructure:"checks"`
Initialisms []string `mapstructure:"initialisms"` // only for stylecheck
DotImportWhitelist []string `mapstructure:"dot-import-whitelist"` // only for stylecheck
HTTPStatusCodeWhitelist []string `mapstructure:"http-status-code-whitelist"` // only for stylecheck
Checks []string `mapstructure:"checks"`
}

func (s *StaticCheckSettings) HasConfiguration() bool {
return len(s.Initialisms) > 0 || len(s.HTTPStatusCodeWhitelist) > 0 || len(s.DotImportWhitelist) > 0 || len(s.Checks) > 0
}

func (s *CommonStaticCheckSettings) GetGoVersion() string {
var goVersion string
if s != nil {
goVersion = s.GoVersion
}

if goVersion != "" {
return goVersion
}

return "1.17"
}

type StructCheckSettings struct {
CheckExportedFields bool `mapstructure:"exported-fields"`
}
Expand Down Expand Up @@ -863,7 +880,9 @@ type UseStdlibVarsSettings struct {

type UnparamSettings struct {
CheckExported bool `mapstructure:"check-exported"`
Algo string

// Deprecated
Algo string
}

type UnusedSettings struct {
Expand Down Expand Up @@ -938,7 +957,6 @@ type CustomLinterSettings struct {
Description string
// OriginalURL The URL containing the source code for the private linter.
OriginalURL string `mapstructure:"original-url"`

// Settings plugin settings only work with linterdb.PluginConstructor symbol.
Settings any
}
18 changes: 9 additions & 9 deletions pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ var OutFormats = []string{
}

type Output struct {
Format string
PrintIssuedLine bool `mapstructure:"print-issued-lines"`
PrintLinterName bool `mapstructure:"print-linter-name"`
UniqByLine bool `mapstructure:"uniq-by-line"`
SortResults bool `mapstructure:"sort-results"`
PrintWelcomeMessage bool `mapstructure:"print-welcome"`
PathPrefix string `mapstructure:"path-prefix"`
Format string
PrintIssuedLine bool `mapstructure:"print-issued-lines"`
PrintLinterName bool `mapstructure:"print-linter-name"`
UniqByLine bool `mapstructure:"uniq-by-line"`
SortResults bool `mapstructure:"sort-results"`
PathPrefix string `mapstructure:"path-prefix"`

// only work with CLI flags because the setup of logs is done before the config file parsing.
Color string
// Internal usage options, not available to users
PrintWelcomeMessage bool `mapstructure:"-"`
Color string `mapstructure:"-"`
}
Loading
Loading