From a5552d3a0535395a69aaa585740d478f15b3839a Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:56:02 +0100 Subject: [PATCH 01/15] chore: add `github.com/godoc-lint/godoc-lint@v0.6.1` Signed-off-by: Babak K. Shandiz --- go.mod | 1 + go.sum | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/go.mod b/go.mod index 788c13b6d9f3..d569086bd9b0 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( github.com/go-critic/go-critic v0.13.0 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-xmlfmt/xmlfmt v1.1.3 + github.com/godoc-lint/godoc-lint v0.6.1 github.com/gofrs/flock v0.12.1 github.com/golangci/asciicheck v0.5.0 github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 diff --git a/go.sum b/go.sum index afd7617733b4..5aeb457868f7 100644 --- a/go.sum +++ b/go.sum @@ -223,6 +223,14 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/godoc-lint/godoc-lint v0.4.0 h1:XYfN+KoZ+JXDfTUIhA5g0b+Xjitmu4dylBJzjmK7Eko= +github.com/godoc-lint/godoc-lint v0.4.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.5.0 h1:YgrwixdFh/Amw8X1WquD765qV+qz/2nFVqvrgQ2uHVA= +github.com/godoc-lint/godoc-lint v0.5.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.6.0 h1:Sg+S4QgVHm+WCMfjHTN3RtlnwRq43jjnLSE4YBOVJRs= +github.com/godoc-lint/godoc-lint v0.6.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.6.1 h1:gPLPXuE0ae+ogVGVmOklyZoA9e5NGlyZdXoc/8VOqI8= +github.com/godoc-lint/godoc-lint v0.6.1/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= From 0907a1d162525a3865f982a38e06cb069d8b5c6e Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:57:03 +0100 Subject: [PATCH 02/15] fix: add godoclint config type Signed-off-by: Babak K. Shandiz --- pkg/config/linters_settings.go | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 567416d977de..1e56d80c160f 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -242,6 +242,7 @@ type LintersSettings struct { Goconst GoConstSettings `mapstructure:"goconst"` Gocritic GoCriticSettings `mapstructure:"gocritic"` Gocyclo GoCycloSettings `mapstructure:"gocyclo"` + Godoclint GodoclintSettings `mapstructure:"godoclint"` Godot GodotSettings `mapstructure:"godot"` Godox GodoxSettings `mapstructure:"godox"` Goheader GoHeaderSettings `mapstructure:"goheader"` @@ -520,6 +521,42 @@ type GoCycloSettings struct { MinComplexity int `mapstructure:"min-complexity"` } +type GodoclintSettings struct { + Include []string `mapstructure:"include"` + Exclude []string `mapstructure:"exclude"` + Enable []string `mapstructure:"enable"` + Disable []string `mapstructure:"disable"` + Options struct { + MaxLen struct { + Length *uint `mapstructure:"length"` + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"max-len"` + PkgDoc struct { + StartWith *string `mapstructure:"start-with"` + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"pkg-doc"` + SinglePkgDoc struct { + IncludeTests *bool `mapstructure:"include-tests"` + } + RequirePkgDoc struct { + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"require-pkg-doc"` + RequireDoc struct { + IgnoreExported *bool `mapstructure:"ignore-exported"` + IgnoreUnexported *bool `mapstructure:"ignore-unexported"` + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"require-doc"` + StartWithName struct { + Pattern *string `mapstructure:"pattern"` + IncludeUnexported *bool `mapstructure:"include-unexported"` + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"start-with-name"` + NoUnusedLink struct { + IncludeTests *bool `mapstructure:"include-tests"` + } `mapstructure:"no-unused-link"` + } `mapstructure:"options"` +} + type GodotSettings struct { Scope string `mapstructure:"scope"` Exclude []string `mapstructure:"exclude"` From b5bb8b3bf6141eee31ef0eab99e28c27c36e217b Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:57:34 +0100 Subject: [PATCH 03/15] fix: add godoclint to JSON schema Signed-off-by: Babak K. Shandiz --- jsonschema/golangci.next.jsonschema.json | 197 +++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 9221df3feb96..e552cc7f9690 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -795,6 +795,7 @@ "goconst", "gocritic", "gocyclo", + "godoclint", "godot", "godox", "err113", @@ -1848,6 +1849,199 @@ } } }, + "godoclintSettings": { + "type": "object", + "properties": { + "include": { + "default": null, + "description": "List of regexp patterns matching relative paths to files the linter should include. Paths are forward-slash separated (Unix-style).", + "oneOf": [ + { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + }, + "exclude": { + "default": null, + "description": "List of regexp patterns matching relative paths to files the linter should skip. Paths are forward-slash separated (Unix-style).", + "oneOf": [ + { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + } + }, + { + "type": "null" + } + ] + }, + "enable": { + "default": null, + "description": "List of rules to enable.", + "oneOf": [ + { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string", + "enum": [ + "pkg-doc", + "single-pkg-doc", + "require-pkg-doc", + "start-with-name", + "require-doc", + "max-len", + "no-unused-link" + ] + } + }, + { + "type": "null" + } + ] + }, + "disable": { + "default": null, + "description": "List of rules to disable.", + "oneOf": [ + { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string", + "enum": [ + "pkg-doc", + "single-pkg-doc", + "require-pkg-doc", + "start-with-name", + "require-doc", + "max-len", + "no-unused-link" + ] + } + }, + { + "type": "null" + } + ] + }, + "options": { + "type": "object", + "description": "A map for setting individual rule options.", + "properties": { + "max-len": { + "type": "object", + "properties": { + "length": { + "type": "integer", + "description": "Maximum line length for godocs, not including the `// `, or `/*` or `*/` tokens.", + "default": 77 + }, + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `max-len` rule.", + "default": false + } + } + }, + "pkg-doc": { + "type": "object", + "properties": { + "start-with": { + "type": "string", + "description": "The start of a valid package godoc (e.g., \"Package ...\").", + "default": "Package" + }, + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `pkg-doc` rule.", + "default": false + } + } + }, + "single-pkg-doc": { + "type": "object", + "properties": { + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `single-pkg-doc` rule.", + "default": false + } + } + }, + "require-pkg-doc": { + "type": "object", + "properties": { + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `require-pkg-doc` rule.", + "default": false + } + } + }, + "require-doc": { + "type": "object", + "properties": { + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `require-doc` rule.", + "default": false + }, + "ignore-exported": { + "type": "boolean", + "description": "Ignore exported (public) symbols when applying the `require-doc` rule.", + "default": false + }, + "ignore-unexported": { + "type": "boolean", + "description": "Ignore unexported (private) symbols when applying the `require-doc` rule.", + "default": true + } + } + }, + "start-with-name": { + "type": "object", + "properties": { + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `start-with-name` rule.", + "default": false + }, + "include-unexported": { + "type": "boolean", + "description": "Include unexported symbols when applying the `start-with-name` rule.", + "default": false + }, + "pattern": { + "type": "string", + "description": "Acceptable start pattern (regexp) for godoc starte when applying the `start-with-name` rule. The `%` placeholder is where the corresponding symbol name should should appear. An omitted placeholder means the symbol name should appear at the end of the pattern.", + "default": "((A|a|An|an|THE|The|the) )?%" + } + } + }, + "no-unused-link": { + "type": "object", + "properties": { + "include-tests": { + "type": "boolean", + "description": "Include test files when applying the `no-unused-link` rule.", + "default": false + } + } + } + } + } + } + }, "godotSettings": { "type": "object", "additionalProperties": false, @@ -4547,6 +4741,9 @@ "gocyclo": { "$ref": "#/definitions/settings/definitions/gocycloSettings" }, + "godoclint": { + "$ref": "#/definitions/settings/definitions/godoclintSettings" + }, "godot": { "$ref": "#/definitions/settings/definitions/godotSettings" }, From e6d7a5bb5e1ea99f64782f4f3fa9bd46dfdb2b7f Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:58:05 +0100 Subject: [PATCH 04/15] fix: add godoclint to next version config reference Signed-off-by: Babak K. Shandiz --- .golangci.next.reference.yml | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 44ce5c4a9db8..24487863e5e1 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -59,6 +59,7 @@ linters: - goconst - gocritic - gocyclo + - godoclint - godot - godox - goheader @@ -170,6 +171,7 @@ linters: - goconst - gocritic - gocyclo + - godoclint - godot - godox - goheader @@ -1266,6 +1268,115 @@ linters: # Default: 30 (but we recommend 10-20) min-complexity: 10 + godoclint: + # List of regexp patterns matching files the linter should include. If assigned, + # then only the files whose relative path matches any of the patterns will be + # processed. Pattern should assume Unix-style paths ("/"-separated). + # Default: null (include all) + include: + - ^pkg/ + - _foo.go$ + + # List of regexp patterns matching files the linter should skip. If assigned, + # then only the files whose relative path does not match any of the patterns will be + # processed. Pattern should assume Unix-style paths ("/"-separated). + # Default: null (exclude none) + exclude: + - ^internal/ + - _autogenerated.go$ + + # List of rules to enable. See the linter docs for more details. + # Default: + # - pkg-doc + # - single-pkg-doc + # - start-with-name + enable: + # Check proper package-level godoc, if any + - pkg-doc + # Assert at most one godoc per package + - single-pkg-doc + # Require all packages to have a godoc + - require-pkg-doc + # Assert symbol godocs start with the symbol name + - start-with-name + # Require godoc for all public symbols + - require-doc + # Assert maximum line length for godocs + - max-len + # Assert no unused link in godocs + - no-unused-link + + # List of rules to disable, useful when using the default rules. + # Default: null + disable: + - pkg-doc + - single-pkg-doc + - start-with-name + + # A map for fine tuning individual rules. All sub-keys are optional. + options: + max-len: + # Maximum line length for godocs, not including the `// `, or `/*` or `*/` tokens. + # Default: 77 + length: 127 + + # Include test files when applying the `max-len` rule. + # Default: false + include-tests: true + + pkg-doc: + # The start of a valid package godoc (e.g., "Package ..."). + # Default: "Package" + start-with: PACKAGE + + # Include test files when applying the `pkg-doc` rule. + # Default: false + include-tests: true + + single-pkg-doc: + # Include test files when applying the `single-pkg-doc` rule. + # Default: false + include-tests: true + + require-pkg-doc: + # Include test files when applying the `require-pkg-doc` rule. + # Default: false + include-tests: true + + require-doc: + # Ignore exported (public) symbols when applying the `require-doc` rule. + # Default: false + ignore-exported: true + + # Ignore unexported (private) symbols when applying the `require-doc` rule. + # Default: true + ignore-unexported: false + + # Include test files when applying the `require-doc` rule. + # Default: false + include-tests: true + + start-with-name: + # Acceptable start pattern (regexp) for godocs when applying the + # `start-with-name` rule. The `%` placeholder is where the corresponding + # symbol name should appear. An omitted placeholder means the symbol + # name should appear at the end of the pattern. + # Default: "((A|a|An|an|THE|The|the) )?%" + pattern: "%" + + # Include unexported symbols when applying the `start-with-name` rule. + # Default: false + include-unexported: true + + # Include test files when applying the `start-with-name` rule. + # Default: false + include-tests: false + + no-unused-link: + # Include test files when applying the `no-unused-link` rule. + # Default: false + include-tests: false + godot: # Comments to be checked: `declarations`, `toplevel`, `noinline` or `all`. # Default: declarations From 3dc081695f0e71bf6e4c88a48cfe576bb9776b9d Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:59:18 +0100 Subject: [PATCH 05/15] feat: add godoclint to linters Signed-off-by: Babak K. Shandiz --- pkg/golinters/godoclint/godoclint.go | 41 ++++++++++++++++++++++++++++ pkg/lint/lintersdb/builder_linter.go | 6 ++++ 2 files changed, 47 insertions(+) create mode 100644 pkg/golinters/godoclint/godoclint.go diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go new file mode 100644 index 000000000000..6f8196e93a84 --- /dev/null +++ b/pkg/golinters/godoclint/godoclint.go @@ -0,0 +1,41 @@ +package godoclint + +import ( + glcompose "github.com/godoc-lint/godoc-lint/pkg/compose" + glconfig "github.com/godoc-lint/godoc-lint/pkg/config" + + "github.com/golangci/golangci-lint/v2/pkg/config" + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New(settings *config.GodoclintSettings) *goanalysis.Linter { + pcfg := glconfig.PlainConfig{ + Include: settings.Include, + Exclude: settings.Exclude, + Enable: settings.Enable, + Disable: settings.Disable, + Options: &glconfig.PlainRuleOptions{ + MaxLenLength: settings.Options.MaxLen.Length, + MaxLenIncludeTests: settings.Options.MaxLen.IncludeTests, + PkgDocStartWith: settings.Options.PkgDoc.StartWith, + PkgDocIncludeTests: settings.Options.PkgDoc.IncludeTests, + SinglePkgDocIncludeTests: settings.Options.SinglePkgDoc.IncludeTests, + RequirePkgDocIncludeTests: settings.Options.RequirePkgDoc.IncludeTests, + RequireDocIncludeTests: settings.Options.RequireDoc.IncludeTests, + RequireDocIgnoreExported: settings.Options.RequireDoc.IgnoreExported, + RequireDocIgnoreUnexported: settings.Options.RequireDoc.IgnoreUnexported, + StartWithNamePattern: settings.Options.StartWithName.Pattern, + StartWithNameIncludeTests: settings.Options.StartWithName.IncludeTests, + StartWithNameIncludeUnexported: settings.Options.StartWithName.IncludeUnexported, + NoUnusedLinkIncludeTests: settings.Options.NoUnusedLink.IncludeTests, + }, + } + + composition := glcompose.Compose(glcompose.CompositionConfig{ + BaseDirPlainConfig: &pcfg, + }) + + return goanalysis. + NewLinterFromAnalyzer(composition.Analyzer.GetAnalyzer()). + WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index c64d498e4198..8863cf0fa58e 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -43,6 +43,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/goconst" "github.com/golangci/golangci-lint/v2/pkg/golinters/gocritic" "github.com/golangci/golangci-lint/v2/pkg/golinters/gocyclo" + "github.com/golangci/golangci-lint/v2/pkg/golinters/godoclint" "github.com/golangci/golangci-lint/v2/pkg/golinters/godot" "github.com/golangci/golangci-lint/v2/pkg/golinters/godox" "github.com/golangci/golangci-lint/v2/pkg/golinters/gofmt" @@ -331,6 +332,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.0.0"). WithURL("https://github.com/fzipp/gocyclo"), + linter.NewConfig(godoclint.New(&cfg.Linters.Settings.Godoclint)). + WithSince("v2.5.0"). + WithLoadForGoAnalysis(). + WithURL("https://github.com/godoc-lint/godoc-lint"), + linter.NewConfig(godot.New(&cfg.Linters.Settings.Godot)). WithSince("v1.25.0"). WithAutoFix(). From 49eddf54151bef48e0b7bd1a69fcae5be2b811b2 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Sun, 7 Sep 2025 22:59:33 +0100 Subject: [PATCH 06/15] test: add godoclint tests Signed-off-by: Babak K. Shandiz --- .../godoclint/godoclint_integration_test.go | 11 +++ .../godoclint/testdata/godoclint.yml | 37 ++++++++ .../testdata/godoclint_default_fail.go | 26 ++++++ .../testdata/godoclint_default_pass.go | 45 +++++++++ .../testdata/godoclint_full_fail_excluded.go | 16 ++++ .../godoclint_full_fail_excluded_test.go | 16 ++++ .../godoclint_full_fail_most_rules.go | 92 +++++++++++++++++++ ...godoclint_full_fail_most_rules_pkg_test.go | 92 +++++++++++++++++++ .../godoclint_full_fail_most_rules_test.go | 92 +++++++++++++++++++ .../godoclint_full_fail_rest_pkg_test.go | 8 ++ .../testdata/godoclint_full_fail_rest_test.go | 8 ++ .../godoclint/testdata/godoclint_full_pass.go | 62 +++++++++++++ .../testdata/godoclint_full_pass_pkg_test.go | 62 +++++++++++++ .../testdata/godoclint_full_pass_test.go | 62 +++++++++++++ 14 files changed, 629 insertions(+) create mode 100644 pkg/golinters/godoclint/godoclint_integration_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint.yml create mode 100644 pkg/golinters/godoclint/testdata/godoclint_default_fail.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_default_pass.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_pass.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go create mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go diff --git a/pkg/golinters/godoclint/godoclint_integration_test.go b/pkg/golinters/godoclint/godoclint_integration_test.go new file mode 100644 index 000000000000..1b9b0ad82782 --- /dev/null +++ b/pkg/golinters/godoclint/godoclint_integration_test.go @@ -0,0 +1,11 @@ +package godoclint + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/godoclint/testdata/godoclint.yml b/pkg/golinters/godoclint/testdata/godoclint.yml new file mode 100644 index 000000000000..d148615f1eaa --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint.yml @@ -0,0 +1,37 @@ +# This is an unusual configuration assigning all options with non-default values +# to ensure they are correctly parsed. + +version: "2" + +linters: + settings: + godoclint: + exclude: + - _excluded.go$ + - _excluded_test.go$ + enable: + - pkg-doc + - require-pkg-doc + - start-with-name + - require-doc + - no-unused-link + - max-len + options: + pkg-doc: + start-with: PACKAGE + include-tests: true + require-pkg-doc: + include-tests: true + start-with-name: + pattern: "GODOC %" + include-unexported: true + include-tests: true + require-doc: + include-tests: true + ignore-exported: false + ignore-unexported: false + max-len: + length: 127 + include-tests: true + no-unused-link: + include-tests: true diff --git a/pkg/golinters/godoclint/testdata/godoclint_default_fail.go b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go new file mode 100644 index 000000000000..8a0577fe9938 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go @@ -0,0 +1,26 @@ +//golangcitest:args -Egodoclint + +// bad godoc // want `package godoc should start with "Package testdata "` +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +func FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +func (FooType) FooFunc() {} diff --git a/pkg/golinters/godoclint/testdata/godoclint_default_pass.go b/pkg/golinters/godoclint/testdata/godoclint_default_pass.go new file mode 100644 index 000000000000..11fdcaac5576 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_default_pass.go @@ -0,0 +1,45 @@ +//golangcitest:args -Egodoclint +//golangcitest:expected_exitcode 0 + +// Package testdata has good godoc. +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// FooType is a type. +type FooType struct{} + +// FooAlias is an alias. +type FooAlias = ast.Comment + +// FooConst is a constant. +const FooConst = 1 + +// FooVar is a variable. +var FooVar = 1 + +// FooFunc is a function. +func FooFunc() {} + +// FooFunc is a method. +func (FooType) FooFunc() {} + +// bad godoc on unexported symbol +type fooType struct{} + +// bad godoc on unexported symbol +type fooAlias = ast.Comment + +// bad godoc on unexported symbol +const fooConst = 1 + +// bad godoc on unexported symbol +var fooVar = 1 + +// bad godoc on unexported symbol +func fooFunc() {} + +// bad godoc on unexported symbol +func (FooType) fooFunc() {} diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go new file mode 100644 index 000000000000..f1ba1dd09a6f --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go @@ -0,0 +1,16 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml +//golangcitest:expected_exitcode 0 + +// Since this file is excluded in the config, godoclint should not report any +// issues (i.e.exit code 0). + +// bad godoc +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// bad godoc +type FooAlias = ast.Comment diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go new file mode 100644 index 000000000000..f1ba1dd09a6f --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go @@ -0,0 +1,16 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml +//golangcitest:expected_exitcode 0 + +// Since this file is excluded in the config, godoclint should not report any +// issues (i.e.exit code 0). + +// bad godoc +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// bad godoc +type FooAlias = ast.Comment diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go new file mode 100644 index 000000000000..8ae3854c365e --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go @@ -0,0 +1,92 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml + +// Asserting rule "pkg-doc" + +// bad godoc // want `package godoc should start with "PACKAGE testdata "` +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const fooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var fooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func fooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) fooFunc() {} + +// Asserting rule "require-doc" + +// The //foo:bar directives mark the trailing comment as a directive so they're +// not parsed as a normal trailing comment group. + +type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` + +type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` + +const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` + +var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` + +func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` + +type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` + +const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` + +var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` + +func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` +// +// [used]: https://example.com +// +// [unused]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` +const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go new file mode 100644 index 000000000000..0d99f71cd6d6 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go @@ -0,0 +1,92 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml + +// Asserting rule "pkg-doc" + +// bad godoc // want `package godoc should start with "PACKAGE testdata_test "` +package testdata_test + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const fooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var fooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func fooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) fooFunc() {} + +// Asserting rule "require-doc" + +// The //foo:bar directives mark the trailing comment as a directive so they're +// not parsed as a normal trailing comment group. + +type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` + +type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` + +const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` + +var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` + +func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` + +type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` + +const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` + +var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` + +func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` +// +// [used]: https://example.com +// +// [unused]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` +const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go new file mode 100644 index 000000000000..8ae3854c365e --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go @@ -0,0 +1,92 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml + +// Asserting rule "pkg-doc" + +// bad godoc // want `package godoc should start with "PACKAGE testdata "` +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooType struct{} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +type fooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +const fooConst = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +var fooVar = 1 + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func fooFunc() {} + +// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +func (FooType) fooFunc() {} + +// Asserting rule "require-doc" + +// The //foo:bar directives mark the trailing comment as a directive so they're +// not parsed as a normal trailing comment group. + +type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` + +type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` + +const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` + +var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` + +func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` + +type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` + +type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` + +const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` + +var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` + +func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` +// +// [used]: https://example.com +// +// [unused]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` +const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go new file mode 100644 index 000000000000..396ebeff7ec6 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go @@ -0,0 +1,8 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml + +package testdata_test // want `package should have a godoc` + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import _ "go/ast" diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go new file mode 100644 index 000000000000..fdb1d6f1932b --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go @@ -0,0 +1,8 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml + +package testdata // want `package should have a godoc` + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import _ "go/ast" diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go new file mode 100644 index 000000000000..ba2b58866a49 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go @@ -0,0 +1,62 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml +//golangcitest:expected_exitcode 0 + +// Asserting rule "pkg-doc" and "require-pkg-doc" since the package has a godoc. + +// PACKAGE testdata +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" and "require-doc" (since all have godocs) + +// GODOC FooType is... +type FooType struct{} + +// GODOC FooAlias is... +type FooAlias = ast.Comment + +// GODOC FooConst is... +const FooConst = 1 + +// GODOC FooVar is... +var FooVar = 1 + +// GODOC FooFunc is... +func FooFunc() {} + +// GODOC FooFunc is... +func (FooType) FooFunc() {} + +// GODOC fooType is... +type fooType struct{} + +// GODOC fooAlias is... +type fooAlias = ast.Comment + +// GODOC fooConst is... +const fooConst = 1 + +// GODOC fooVar is... +var fooVar = 1 + +// GODOC fooFunc is... +func fooFunc() {} + +// GODOC fooFunc is... +func (FooType) fooFunc() {} + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to a [used] link and has no unused one. +// +// [used]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. +const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go new file mode 100644 index 000000000000..19513eece5c6 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go @@ -0,0 +1,62 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml +//golangcitest:expected_exitcode 0 + +// Asserting rule "pkg-doc" + +// PACKAGE testdata_test +package testdata_test + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" (also covering "require-doc" since all have godocs) + +// GODOC FooType is... +type FooType struct{} + +// GODOC FooAlias is... +type FooAlias = ast.Comment + +// GODOC FooConst is... +const FooConst = 1 + +// GODOC FooVar is... +var FooVar = 1 + +// GODOC FooFunc is... +func FooFunc() {} + +// GODOC FooFunc is... +func (FooType) FooFunc() {} + +// GODOC fooType is... +type fooType struct{} + +// GODOC fooAlias is... +type fooAlias = ast.Comment + +// GODOC fooConst is... +const fooConst = 1 + +// GODOC fooVar is... +var fooVar = 1 + +// GODOC fooFunc is... +func fooFunc() {} + +// GODOC fooFunc is... +func (FooType) fooFunc() {} + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to a [used] link and has no unused one. +// +// [used]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. +const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go new file mode 100644 index 000000000000..d17596e298af --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go @@ -0,0 +1,62 @@ +//golangcitest:args -Egodoclint +//golangcitest:config_path testdata/godoclint.yml +//golangcitest:expected_exitcode 0 + +// Asserting rule "pkg-doc" + +// PACKAGE testdata +package testdata + +// This is a special stdlib import because the package itself has issues that +// godoclint can, but must not, detect. +import "go/ast" + +// Asserting rule "start-with-name" (also covering "require-doc" since all have godocs) + +// GODOC FooType is... +type FooType struct{} + +// GODOC FooAlias is... +type FooAlias = ast.Comment + +// GODOC FooConst is... +const FooConst = 1 + +// GODOC FooVar is... +var FooVar = 1 + +// GODOC FooFunc is... +func FooFunc() {} + +// GODOC FooFunc is... +func (FooType) FooFunc() {} + +// GODOC fooType is... +type fooType struct{} + +// GODOC fooAlias is... +type fooAlias = ast.Comment + +// GODOC fooConst is... +const fooConst = 1 + +// GODOC fooVar is... +var fooVar = 1 + +// GODOC fooFunc is... +func fooFunc() {} + +// GODOC fooFunc is... +func (FooType) fooFunc() {} + +// Asserting rule "no-unused-link" + +// GODOC constWithUnusedLink point to a [used] link and has no unused one. +// +// [used]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. +const constWithTooLongGodoc = 1 From 8c6788aa56df8191d0abf80d948ba711f176212a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 8 Sep 2025 02:10:27 +0200 Subject: [PATCH 07/15] review --- .golangci.next.reference.yml | 47 ------- go.sum | 6 - jsonschema/golangci.next.jsonschema.json | 115 ++---------------- pkg/config/linters_settings.go | 19 +-- pkg/golinters/godoclint/godoclint.go | 59 +++++---- .../godoclint/testdata/godoclint.yml | 14 --- .../testdata/godoclint_full_fail_excluded.go | 16 --- .../godoclint_full_fail_excluded_test.go | 16 --- ...godoclint_full_fail_most_rules_pkg_test.go | 92 -------------- .../godoclint_full_fail_most_rules_test.go | 92 -------------- .../godoclint_full_fail_rest_pkg_test.go | 8 -- .../testdata/godoclint_full_fail_rest_test.go | 8 -- .../testdata/godoclint_full_pass_pkg_test.go | 62 ---------- pkg/lint/lintersdb/builder_linter.go | 1 - 14 files changed, 53 insertions(+), 502 deletions(-) delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go delete mode 100644 pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 24487863e5e1..3d1a2c6692f5 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1269,22 +1269,6 @@ linters: min-complexity: 10 godoclint: - # List of regexp patterns matching files the linter should include. If assigned, - # then only the files whose relative path matches any of the patterns will be - # processed. Pattern should assume Unix-style paths ("/"-separated). - # Default: null (include all) - include: - - ^pkg/ - - _foo.go$ - - # List of regexp patterns matching files the linter should skip. If assigned, - # then only the files whose relative path does not match any of the patterns will be - # processed. Pattern should assume Unix-style paths ("/"-separated). - # Default: null (exclude none) - exclude: - - ^internal/ - - _autogenerated.go$ - # List of rules to enable. See the linter docs for more details. # Default: # - pkg-doc @@ -1320,29 +1304,11 @@ linters: # Default: 77 length: 127 - # Include test files when applying the `max-len` rule. - # Default: false - include-tests: true - pkg-doc: # The start of a valid package godoc (e.g., "Package ..."). # Default: "Package" start-with: PACKAGE - # Include test files when applying the `pkg-doc` rule. - # Default: false - include-tests: true - - single-pkg-doc: - # Include test files when applying the `single-pkg-doc` rule. - # Default: false - include-tests: true - - require-pkg-doc: - # Include test files when applying the `require-pkg-doc` rule. - # Default: false - include-tests: true - require-doc: # Ignore exported (public) symbols when applying the `require-doc` rule. # Default: false @@ -1352,10 +1318,6 @@ linters: # Default: true ignore-unexported: false - # Include test files when applying the `require-doc` rule. - # Default: false - include-tests: true - start-with-name: # Acceptable start pattern (regexp) for godocs when applying the # `start-with-name` rule. The `%` placeholder is where the corresponding @@ -1368,15 +1330,6 @@ linters: # Default: false include-unexported: true - # Include test files when applying the `start-with-name` rule. - # Default: false - include-tests: false - - no-unused-link: - # Include test files when applying the `no-unused-link` rule. - # Default: false - include-tests: false - godot: # Comments to be checked: `declarations`, `toplevel`, `noinline` or `all`. # Default: declarations diff --git a/go.sum b/go.sum index 5aeb457868f7..1f8df6f28fd5 100644 --- a/go.sum +++ b/go.sum @@ -223,12 +223,6 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godoc-lint/godoc-lint v0.4.0 h1:XYfN+KoZ+JXDfTUIhA5g0b+Xjitmu4dylBJzjmK7Eko= -github.com/godoc-lint/godoc-lint v0.4.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= -github.com/godoc-lint/godoc-lint v0.5.0 h1:YgrwixdFh/Amw8X1WquD765qV+qz/2nFVqvrgQ2uHVA= -github.com/godoc-lint/godoc-lint v0.5.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= -github.com/godoc-lint/godoc-lint v0.6.0 h1:Sg+S4QgVHm+WCMfjHTN3RtlnwRq43jjnLSE4YBOVJRs= -github.com/godoc-lint/godoc-lint v0.6.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/godoc-lint/godoc-lint v0.6.1 h1:gPLPXuE0ae+ogVGVmOklyZoA9e5NGlyZdXoc/8VOqI8= github.com/godoc-lint/godoc-lint v0.6.1/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index e552cc7f9690..ec87ccea6f39 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -477,6 +477,17 @@ "-QF1012" ] }, + "godoclint-rules": { + "enum": [ + "pkg-doc", + "single-pkg-doc", + "require-pkg-doc", + "start-with-name", + "require-doc", + "max-len", + "no-unused-link" + ] + }, "gosec-rules": { "enum": [ "G101", @@ -1852,38 +1863,6 @@ "godoclintSettings": { "type": "object", "properties": { - "include": { - "default": null, - "description": "List of regexp patterns matching relative paths to files the linter should include. Paths are forward-slash separated (Unix-style).", - "oneOf": [ - { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string" - } - }, - { - "type": "null" - } - ] - }, - "exclude": { - "default": null, - "description": "List of regexp patterns matching relative paths to files the linter should skip. Paths are forward-slash separated (Unix-style).", - "oneOf": [ - { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string" - } - }, - { - "type": "null" - } - ] - }, "enable": { "default": null, "description": "List of rules to enable.", @@ -1892,16 +1871,7 @@ "type": "array", "uniqueItems": true, "items": { - "type": "string", - "enum": [ - "pkg-doc", - "single-pkg-doc", - "require-pkg-doc", - "start-with-name", - "require-doc", - "max-len", - "no-unused-link" - ] + "$ref": "#/definitions/godoclint-rules" } }, { @@ -1917,16 +1887,7 @@ "type": "array", "uniqueItems": true, "items": { - "type": "string", - "enum": [ - "pkg-doc", - "single-pkg-doc", - "require-pkg-doc", - "start-with-name", - "require-doc", - "max-len", - "no-unused-link" - ] + "$ref": "#/definitions/godoclint-rules" } }, { @@ -1945,11 +1906,6 @@ "type": "integer", "description": "Maximum line length for godocs, not including the `// `, or `/*` or `*/` tokens.", "default": 77 - }, - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `max-len` rule.", - "default": false } } }, @@ -1960,42 +1916,12 @@ "type": "string", "description": "The start of a valid package godoc (e.g., \"Package ...\").", "default": "Package" - }, - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `pkg-doc` rule.", - "default": false - } - } - }, - "single-pkg-doc": { - "type": "object", - "properties": { - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `single-pkg-doc` rule.", - "default": false - } - } - }, - "require-pkg-doc": { - "type": "object", - "properties": { - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `require-pkg-doc` rule.", - "default": false } } }, "require-doc": { "type": "object", "properties": { - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `require-doc` rule.", - "default": false - }, "ignore-exported": { "type": "boolean", "description": "Ignore exported (public) symbols when applying the `require-doc` rule.", @@ -2011,11 +1937,6 @@ "start-with-name": { "type": "object", "properties": { - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `start-with-name` rule.", - "default": false - }, "include-unexported": { "type": "boolean", "description": "Include unexported symbols when applying the `start-with-name` rule.", @@ -2027,16 +1948,6 @@ "default": "((A|a|An|an|THE|The|the) )?%" } } - }, - "no-unused-link": { - "type": "object", - "properties": { - "include-tests": { - "type": "boolean", - "description": "Include test files when applying the `no-unused-link` rule.", - "default": false - } - } } } } diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 1e56d80c160f..d2b9d842086f 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -522,38 +522,23 @@ type GoCycloSettings struct { } type GodoclintSettings struct { - Include []string `mapstructure:"include"` - Exclude []string `mapstructure:"exclude"` Enable []string `mapstructure:"enable"` Disable []string `mapstructure:"disable"` Options struct { MaxLen struct { - Length *uint `mapstructure:"length"` - IncludeTests *bool `mapstructure:"include-tests"` + Length *uint `mapstructure:"length"` } `mapstructure:"max-len"` PkgDoc struct { - StartWith *string `mapstructure:"start-with"` - IncludeTests *bool `mapstructure:"include-tests"` + StartWith *string `mapstructure:"start-with"` } `mapstructure:"pkg-doc"` - SinglePkgDoc struct { - IncludeTests *bool `mapstructure:"include-tests"` - } - RequirePkgDoc struct { - IncludeTests *bool `mapstructure:"include-tests"` - } `mapstructure:"require-pkg-doc"` RequireDoc struct { IgnoreExported *bool `mapstructure:"ignore-exported"` IgnoreUnexported *bool `mapstructure:"ignore-unexported"` - IncludeTests *bool `mapstructure:"include-tests"` } `mapstructure:"require-doc"` StartWithName struct { Pattern *string `mapstructure:"pattern"` IncludeUnexported *bool `mapstructure:"include-unexported"` - IncludeTests *bool `mapstructure:"include-tests"` } `mapstructure:"start-with-name"` - NoUnusedLink struct { - IncludeTests *bool `mapstructure:"include-tests"` - } `mapstructure:"no-unused-link"` } `mapstructure:"options"` } diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go index 6f8196e93a84..9662abb4531d 100644 --- a/pkg/golinters/godoclint/godoclint.go +++ b/pkg/golinters/godoclint/godoclint.go @@ -9,26 +9,41 @@ import ( ) func New(settings *config.GodoclintSettings) *goanalysis.Linter { - pcfg := glconfig.PlainConfig{ - Include: settings.Include, - Exclude: settings.Exclude, - Enable: settings.Enable, - Disable: settings.Disable, - Options: &glconfig.PlainRuleOptions{ - MaxLenLength: settings.Options.MaxLen.Length, - MaxLenIncludeTests: settings.Options.MaxLen.IncludeTests, - PkgDocStartWith: settings.Options.PkgDoc.StartWith, - PkgDocIncludeTests: settings.Options.PkgDoc.IncludeTests, - SinglePkgDocIncludeTests: settings.Options.SinglePkgDoc.IncludeTests, - RequirePkgDocIncludeTests: settings.Options.RequirePkgDoc.IncludeTests, - RequireDocIncludeTests: settings.Options.RequireDoc.IncludeTests, - RequireDocIgnoreExported: settings.Options.RequireDoc.IgnoreExported, - RequireDocIgnoreUnexported: settings.Options.RequireDoc.IgnoreUnexported, - StartWithNamePattern: settings.Options.StartWithName.Pattern, - StartWithNameIncludeTests: settings.Options.StartWithName.IncludeTests, - StartWithNameIncludeUnexported: settings.Options.StartWithName.IncludeUnexported, - NoUnusedLinkIncludeTests: settings.Options.NoUnusedLink.IncludeTests, - }, + var pcfg glconfig.PlainConfig + + if settings != nil { + // The following options are explicitly ignored: they must be handled globally with exclusions or nolint directives. + // - Include + // - Exclude + + // The following options are explicitly ignored: these options cannot work as expected because the global configuration about tests. + // - Options.MaxLenIncludeTests + // - Options.PkgDocIncludeTests + // - Options.SinglePkgDocIncludeTests + // - Options.RequirePkgDocIncludeTests + // - Options.RequireDocIncludeTests + // - Options.StartWithNameIncludeTests + // - Options.NoUnusedLinkIncludeTests + + pcfg = glconfig.PlainConfig{ + Enable: settings.Enable, + Disable: settings.Disable, + Options: &glconfig.PlainRuleOptions{ + MaxLenLength: settings.Options.MaxLen.Length, + MaxLenIncludeTests: pointer(true), + PkgDocStartWith: settings.Options.PkgDoc.StartWith, + PkgDocIncludeTests: pointer(false), + SinglePkgDocIncludeTests: pointer(true), + RequirePkgDocIncludeTests: pointer(false), + RequireDocIncludeTests: pointer(true), + RequireDocIgnoreExported: settings.Options.RequireDoc.IgnoreExported, + RequireDocIgnoreUnexported: settings.Options.RequireDoc.IgnoreUnexported, + StartWithNamePattern: settings.Options.StartWithName.Pattern, + StartWithNameIncludeTests: pointer(false), + StartWithNameIncludeUnexported: settings.Options.StartWithName.IncludeUnexported, + NoUnusedLinkIncludeTests: pointer(true), + }, + } } composition := glcompose.Compose(glcompose.CompositionConfig{ @@ -37,5 +52,7 @@ func New(settings *config.GodoclintSettings) *goanalysis.Linter { return goanalysis. NewLinterFromAnalyzer(composition.Analyzer.GetAnalyzer()). - WithLoadMode(goanalysis.LoadModeTypesInfo) + WithLoadMode(goanalysis.LoadModeSyntax) } + +func pointer[T any](v T) *T { return &v } diff --git a/pkg/golinters/godoclint/testdata/godoclint.yml b/pkg/golinters/godoclint/testdata/godoclint.yml index d148615f1eaa..55bc4ea5fc64 100644 --- a/pkg/golinters/godoclint/testdata/godoclint.yml +++ b/pkg/golinters/godoclint/testdata/godoclint.yml @@ -1,14 +1,8 @@ -# This is an unusual configuration assigning all options with non-default values -# to ensure they are correctly parsed. - version: "2" linters: settings: godoclint: - exclude: - - _excluded.go$ - - _excluded_test.go$ enable: - pkg-doc - require-pkg-doc @@ -19,19 +13,11 @@ linters: options: pkg-doc: start-with: PACKAGE - include-tests: true - require-pkg-doc: - include-tests: true start-with-name: pattern: "GODOC %" include-unexported: true - include-tests: true require-doc: - include-tests: true ignore-exported: false ignore-unexported: false max-len: length: 127 - include-tests: true - no-unused-link: - include-tests: true diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go deleted file mode 100644 index f1ba1dd09a6f..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded.go +++ /dev/null @@ -1,16 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml -//golangcitest:expected_exitcode 0 - -// Since this file is excluded in the config, godoclint should not report any -// issues (i.e.exit code 0). - -// bad godoc -package testdata - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import "go/ast" - -// bad godoc -type FooAlias = ast.Comment diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go deleted file mode 100644 index f1ba1dd09a6f..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_excluded_test.go +++ /dev/null @@ -1,16 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml -//golangcitest:expected_exitcode 0 - -// Since this file is excluded in the config, godoclint should not report any -// issues (i.e.exit code 0). - -// bad godoc -package testdata - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import "go/ast" - -// bad godoc -type FooAlias = ast.Comment diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go deleted file mode 100644 index 0d99f71cd6d6..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_pkg_test.go +++ /dev/null @@ -1,92 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml - -// Asserting rule "pkg-doc" - -// bad godoc // want `package godoc should start with "PACKAGE testdata_test "` -package testdata_test - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import "go/ast" - -// Asserting rule "start-with-name" - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type FooType struct{} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type FooAlias = ast.Comment - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -const FooConst = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -var FooVar = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func FooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func (FooType) FooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type fooType struct{} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type fooAlias = ast.Comment - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -const fooConst = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -var fooVar = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func fooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func (FooType) fooFunc() {} - -// Asserting rule "require-doc" - -// The //foo:bar directives mark the trailing comment as a directive so they're -// not parsed as a normal trailing comment group. - -type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` - -type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` - -const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` - -var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` - -func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` - -func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` - -type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` - -type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` - -const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` - -var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` - -func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` - -func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` - -// Asserting rule "no-unused-link" - -// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` -// -// [used]: https://example.com -// -// [unused]: https://example.com -const constWithUnusedLink = 1 - -// Asserting rule "max-len" - -// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` -const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go deleted file mode 100644 index 8ae3854c365e..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules_test.go +++ /dev/null @@ -1,92 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml - -// Asserting rule "pkg-doc" - -// bad godoc // want `package godoc should start with "PACKAGE testdata "` -package testdata - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import "go/ast" - -// Asserting rule "start-with-name" - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type FooType struct{} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type FooAlias = ast.Comment - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -const FooConst = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -var FooVar = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func FooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func (FooType) FooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type fooType struct{} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -type fooAlias = ast.Comment - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -const fooConst = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -var fooVar = 1 - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func fooFunc() {} - -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` -func (FooType) fooFunc() {} - -// Asserting rule "require-doc" - -// The //foo:bar directives mark the trailing comment as a directive so they're -// not parsed as a normal trailing comment group. - -type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` - -type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` - -const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` - -var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` - -func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` - -func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` - -type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` - -type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` - -const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` - -var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` - -func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` - -func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` - -// Asserting rule "no-unused-link" - -// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` -// -// [used]: https://example.com -// -// [unused]: https://example.com -const constWithUnusedLink = 1 - -// Asserting rule "max-len" - -// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` -const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go deleted file mode 100644 index 396ebeff7ec6..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_pkg_test.go +++ /dev/null @@ -1,8 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml - -package testdata_test // want `package should have a godoc` - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import _ "go/ast" diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go deleted file mode 100644 index fdb1d6f1932b..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_rest_test.go +++ /dev/null @@ -1,8 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml - -package testdata // want `package should have a godoc` - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import _ "go/ast" diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go deleted file mode 100644 index 19513eece5c6..000000000000 --- a/pkg/golinters/godoclint/testdata/godoclint_full_pass_pkg_test.go +++ /dev/null @@ -1,62 +0,0 @@ -//golangcitest:args -Egodoclint -//golangcitest:config_path testdata/godoclint.yml -//golangcitest:expected_exitcode 0 - -// Asserting rule "pkg-doc" - -// PACKAGE testdata_test -package testdata_test - -// This is a special stdlib import because the package itself has issues that -// godoclint can, but must not, detect. -import "go/ast" - -// Asserting rule "start-with-name" (also covering "require-doc" since all have godocs) - -// GODOC FooType is... -type FooType struct{} - -// GODOC FooAlias is... -type FooAlias = ast.Comment - -// GODOC FooConst is... -const FooConst = 1 - -// GODOC FooVar is... -var FooVar = 1 - -// GODOC FooFunc is... -func FooFunc() {} - -// GODOC FooFunc is... -func (FooType) FooFunc() {} - -// GODOC fooType is... -type fooType struct{} - -// GODOC fooAlias is... -type fooAlias = ast.Comment - -// GODOC fooConst is... -const fooConst = 1 - -// GODOC fooVar is... -var fooVar = 1 - -// GODOC fooFunc is... -func fooFunc() {} - -// GODOC fooFunc is... -func (FooType) fooFunc() {} - -// Asserting rule "no-unused-link" - -// GODOC constWithUnusedLink point to a [used] link and has no unused one. -// -// [used]: https://example.com -const constWithUnusedLink = 1 - -// Asserting rule "max-len" - -// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. -const constWithTooLongGodoc = 1 diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 8863cf0fa58e..d8c9b8bdc309 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -334,7 +334,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { linter.NewConfig(godoclint.New(&cfg.Linters.Settings.Godoclint)). WithSince("v2.5.0"). - WithLoadForGoAnalysis(). WithURL("https://github.com/godoc-lint/godoc-lint"), linter.NewConfig(godot.New(&cfg.Linters.Settings.Godot)). From 6616bf1965aa79ae905c26151f54c98e47b02f93 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Mon, 8 Sep 2025 21:01:35 +0100 Subject: [PATCH 08/15] fix: upgrade godoclint to v0.7.0 Signed-off-by: Babak K. Shandiz --- go.mod | 2 +- go.sum | 2 + .../testdata/godoclint_default_fail.go | 12 ++--- .../godoclint_full_fail_most_rules.go | 52 +++++++++---------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index d569086bd9b0..ac3effeaa4fb 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/go-critic/go-critic v0.13.0 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-xmlfmt/xmlfmt v1.1.3 - github.com/godoc-lint/godoc-lint v0.6.1 + github.com/godoc-lint/godoc-lint v0.7.0 github.com/gofrs/flock v0.12.1 github.com/golangci/asciicheck v0.5.0 github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 diff --git a/go.sum b/go.sum index 1f8df6f28fd5..0dbdac08339c 100644 --- a/go.sum +++ b/go.sum @@ -225,6 +225,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/godoc-lint/godoc-lint v0.6.1 h1:gPLPXuE0ae+ogVGVmOklyZoA9e5NGlyZdXoc/8VOqI8= github.com/godoc-lint/godoc-lint v0.6.1/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.7.0 h1:ZkjtW7myCi2/Yu2sLJNxoB8X7kXKrA1EYHKbJyhCRW0= +github.com/godoc-lint/godoc-lint v0.7.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/pkg/golinters/godoclint/testdata/godoclint_default_fail.go b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go index 8a0577fe9938..c7424672f1d3 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_default_fail.go +++ b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go @@ -7,20 +7,20 @@ package testdata // godoclint can, but must not, detect. import "go/ast" -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooType"\)` type FooType struct{} -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooAlias"\)` type FooAlias = ast.Comment -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooConst"\)` const FooConst = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooVar"\)` var FooVar = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` func FooFunc() {} -// bad godoc // want `godoc should start with symbol name \(pattern "\(\(A\|a\|An\|an\|THE\|The\|the\) \)\?%"\)` +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` func (FooType) FooFunc() {} diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go index 8ae3854c365e..661e8286c451 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go @@ -12,40 +12,40 @@ import "go/ast" // Asserting rule "start-with-name" -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooType"\)` type FooType struct{} -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooAlias"\)` type FooAlias = ast.Comment -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooConst"\)` const FooConst = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooVar"\)` var FooVar = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` func FooFunc() {} -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` func (FooType) FooFunc() {} -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooType"\)` type fooType struct{} -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooAlias"\)` type fooAlias = ast.Comment -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooConst"\)` const fooConst = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooVar"\)` var fooVar = 1 -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooFunc"\)` func fooFunc() {} -// bad godoc // want `godoc should start with symbol name \(pattern "GODOC %"\)` +// bad godoc // want `godoc should start with symbol name \("fooFunc"\)` func (FooType) fooFunc() {} // Asserting rule "require-doc" @@ -53,33 +53,33 @@ func (FooType) fooFunc() {} // The //foo:bar directives mark the trailing comment as a directive so they're // not parsed as a normal trailing comment group. -type BarType struct{} //foo:bar // want `symbol should have a godoc \(BarType\)` +type BarType struct{} //foo:bar // want `symbol should have a godoc \("BarType"\)` -type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(BarAlias\)` +type BarAlias = ast.Comment //foo:bar // want `symbol should have a godoc \("BarAlias"\)` -const BarConst = 1 //foo:bar // want `symbol should have a godoc \(BarConst\)` +const BarConst = 1 //foo:bar // want `symbol should have a godoc \("BarConst"\)` -var BarVar = 1 //foo:bar // want `symbol should have a godoc \(BarVar\)` +var BarVar = 1 //foo:bar // want `symbol should have a godoc \("BarVar"\)` -func BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` +func BarFunc() {} //foo:bar // want `symbol should have a godoc \("BarFunc"\)` -func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \(BarFunc\)` +func (BarType) BarFunc() {} //foo:bar // want `symbol should have a godoc \("BarFunc"\)` -type barType struct{} //foo:bar // want `symbol should have a godoc \(barType\)` +type barType struct{} //foo:bar // want `symbol should have a godoc \("barType"\)` -type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \(barAlias\)` +type barAlias = ast.Comment //foo:bar // want `symbol should have a godoc \("barAlias"\)` -const barConst = 1 //foo:bar // want `symbol should have a godoc \(barConst\)` +const barConst = 1 //foo:bar // want `symbol should have a godoc \("barConst"\)` -var barVar = 1 //foo:bar // want `symbol should have a godoc \(barVar\)` +var barVar = 1 //foo:bar // want `symbol should have a godoc \("barVar"\)` -func barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` +func barFunc() {} //foo:bar // want `symbol should have a godoc \("barFunc"\)` -func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \(barFunc\)` +func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \("barFunc"\)` // Asserting rule "no-unused-link" -// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \(unused\)` +// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \("unused"\)` // // [used]: https://example.com // @@ -88,5 +88,5 @@ const constWithUnusedLink = 1 // Asserting rule "max-len" -// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc exceeds max length \(177 > 127\)` +// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc line is too long \(175 > 127\)` const constWithTooLongGodoc = 1 From f9ff8b2d46fe6b084482b47e01b884047b5800d3 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 8 Sep 2025 22:24:31 +0200 Subject: [PATCH 09/15] review --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 0dbdac08339c..e92ce9c73e3c 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,6 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godoc-lint/godoc-lint v0.6.1 h1:gPLPXuE0ae+ogVGVmOklyZoA9e5NGlyZdXoc/8VOqI8= -github.com/godoc-lint/godoc-lint v0.6.1/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/godoc-lint/godoc-lint v0.7.0 h1:ZkjtW7myCi2/Yu2sLJNxoB8X7kXKrA1EYHKbJyhCRW0= github.com/godoc-lint/godoc-lint v0.7.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= From 5053586192e2cc10cd8a5f22e2b5b92012c560fd Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 11 Sep 2025 19:06:39 +0100 Subject: [PATCH 10/15] fix: upgrade godoclint v0.8.0 The version of godoclint has removed extra configuration parameters, and introduced a new `default` parameter to control the default set of enabled rules. Signed-off-by: Babak K. Shandiz --- .golangci.next.reference.yml | 29 ++++++---------- go.mod | 2 +- go.sum | 4 +-- jsonschema/golangci.next.jsonschema.json | 23 ++++--------- pkg/config/linters_settings.go | 7 ++-- pkg/golinters/godoclint/godoclint.go | 3 +- .../godoclint/testdata/godoclint.yml | 4 +-- ...l_most_rules.go => godoclint_full_fail.go} | 6 ++-- .../godoclint/testdata/godoclint_full_pass.go | 30 ++++++++-------- .../testdata/godoclint_full_pass_test.go | 34 +++++++++---------- 10 files changed, 60 insertions(+), 82 deletions(-) rename pkg/golinters/godoclint/testdata/{godoclint_full_fail_most_rules.go => godoclint_full_fail.go} (88%) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 3d1a2c6692f5..5dd1fa9902aa 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1269,11 +1269,12 @@ linters: min-complexity: 10 godoclint: - # List of rules to enable. See the linter docs for more details. - # Default: - # - pkg-doc - # - single-pkg-doc - # - start-with-name + # Default set of rules to enable. Possible values are: `basic`, `all` or `none`. + # Default: basic (enables `pkg-doc`, `single-pkg-doc`, and `start-with-name`) + default: all + + # List of rules to enable in addition to default set. See the linter docs for more details. + # Default: null enable: # Check proper package-level godoc, if any - pkg-doc @@ -1290,12 +1291,16 @@ linters: # Assert no unused link in godocs - no-unused-link - # List of rules to disable, useful when using the default rules. + # List of rules to disable. # Default: null disable: - pkg-doc - single-pkg-doc + - require-pkg-doc - start-with-name + - require-doc + - max-len + - no-unused-link # A map for fine tuning individual rules. All sub-keys are optional. options: @@ -1304,11 +1309,6 @@ linters: # Default: 77 length: 127 - pkg-doc: - # The start of a valid package godoc (e.g., "Package ..."). - # Default: "Package" - start-with: PACKAGE - require-doc: # Ignore exported (public) symbols when applying the `require-doc` rule. # Default: false @@ -1319,13 +1319,6 @@ linters: ignore-unexported: false start-with-name: - # Acceptable start pattern (regexp) for godocs when applying the - # `start-with-name` rule. The `%` placeholder is where the corresponding - # symbol name should appear. An omitted placeholder means the symbol - # name should appear at the end of the pattern. - # Default: "((A|a|An|an|THE|The|the) )?%" - pattern: "%" - # Include unexported symbols when applying the `start-with-name` rule. # Default: false include-unexported: true diff --git a/go.mod b/go.mod index ac3effeaa4fb..09de6b1ef997 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/go-critic/go-critic v0.13.0 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-xmlfmt/xmlfmt v1.1.3 - github.com/godoc-lint/godoc-lint v0.7.0 + github.com/godoc-lint/godoc-lint v0.8.0 github.com/gofrs/flock v0.12.1 github.com/golangci/asciicheck v0.5.0 github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 diff --git a/go.sum b/go.sum index e92ce9c73e3c..008a210ce264 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godoc-lint/godoc-lint v0.7.0 h1:ZkjtW7myCi2/Yu2sLJNxoB8X7kXKrA1EYHKbJyhCRW0= -github.com/godoc-lint/godoc-lint v0.7.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.8.0 h1:gYTh+PKN3SIIeNMkP1WV2KaxAKLpyWKI2pzrglHlBao= +github.com/godoc-lint/godoc-lint v0.8.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index ec87ccea6f39..8894c5fb5eb8 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -1863,9 +1863,15 @@ "godoclintSettings": { "type": "object", "properties": { + "default": { + "type": "string", + "enum": ["all", "basic", "none"], + "default": "basic", + "description": "Default set of rules to enable." + }, "enable": { "default": null, - "description": "List of rules to enable.", + "description": "List of rules to enable in addition to the default set.", "oneOf": [ { "type": "array", @@ -1909,16 +1915,6 @@ } } }, - "pkg-doc": { - "type": "object", - "properties": { - "start-with": { - "type": "string", - "description": "The start of a valid package godoc (e.g., \"Package ...\").", - "default": "Package" - } - } - }, "require-doc": { "type": "object", "properties": { @@ -1941,11 +1937,6 @@ "type": "boolean", "description": "Include unexported symbols when applying the `start-with-name` rule.", "default": false - }, - "pattern": { - "type": "string", - "description": "Acceptable start pattern (regexp) for godoc starte when applying the `start-with-name` rule. The `%` placeholder is where the corresponding symbol name should should appear. An omitted placeholder means the symbol name should appear at the end of the pattern.", - "default": "((A|a|An|an|THE|The|the) )?%" } } } diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index d2b9d842086f..1eb50a74662f 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -522,22 +522,19 @@ type GoCycloSettings struct { } type GodoclintSettings struct { + Default *string `mapstructure:"default"` Enable []string `mapstructure:"enable"` Disable []string `mapstructure:"disable"` Options struct { MaxLen struct { Length *uint `mapstructure:"length"` } `mapstructure:"max-len"` - PkgDoc struct { - StartWith *string `mapstructure:"start-with"` - } `mapstructure:"pkg-doc"` RequireDoc struct { IgnoreExported *bool `mapstructure:"ignore-exported"` IgnoreUnexported *bool `mapstructure:"ignore-unexported"` } `mapstructure:"require-doc"` StartWithName struct { - Pattern *string `mapstructure:"pattern"` - IncludeUnexported *bool `mapstructure:"include-unexported"` + IncludeUnexported *bool `mapstructure:"include-unexported"` } `mapstructure:"start-with-name"` } `mapstructure:"options"` } diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go index 9662abb4531d..ceae6033c19d 100644 --- a/pkg/golinters/godoclint/godoclint.go +++ b/pkg/golinters/godoclint/godoclint.go @@ -26,19 +26,18 @@ func New(settings *config.GodoclintSettings) *goanalysis.Linter { // - Options.NoUnusedLinkIncludeTests pcfg = glconfig.PlainConfig{ + Default: settings.Default, Enable: settings.Enable, Disable: settings.Disable, Options: &glconfig.PlainRuleOptions{ MaxLenLength: settings.Options.MaxLen.Length, MaxLenIncludeTests: pointer(true), - PkgDocStartWith: settings.Options.PkgDoc.StartWith, PkgDocIncludeTests: pointer(false), SinglePkgDocIncludeTests: pointer(true), RequirePkgDocIncludeTests: pointer(false), RequireDocIncludeTests: pointer(true), RequireDocIgnoreExported: settings.Options.RequireDoc.IgnoreExported, RequireDocIgnoreUnexported: settings.Options.RequireDoc.IgnoreUnexported, - StartWithNamePattern: settings.Options.StartWithName.Pattern, StartWithNameIncludeTests: pointer(false), StartWithNameIncludeUnexported: settings.Options.StartWithName.IncludeUnexported, NoUnusedLinkIncludeTests: pointer(true), diff --git a/pkg/golinters/godoclint/testdata/godoclint.yml b/pkg/golinters/godoclint/testdata/godoclint.yml index 55bc4ea5fc64..75cf69e0a38e 100644 --- a/pkg/golinters/godoclint/testdata/godoclint.yml +++ b/pkg/golinters/godoclint/testdata/godoclint.yml @@ -3,6 +3,7 @@ version: "2" linters: settings: godoclint: + default: none enable: - pkg-doc - require-pkg-doc @@ -11,10 +12,7 @@ linters: - no-unused-link - max-len options: - pkg-doc: - start-with: PACKAGE start-with-name: - pattern: "GODOC %" include-unexported: true require-doc: ignore-exported: false diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go similarity index 88% rename from pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go rename to pkg/golinters/godoclint/testdata/godoclint_full_fail.go index 661e8286c451..6b003c0e53d0 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail_most_rules.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go @@ -3,7 +3,7 @@ // Asserting rule "pkg-doc" -// bad godoc // want `package godoc should start with "PACKAGE testdata "` +// bad godoc // want `package godoc should start with "Package testdata "` package testdata // This is a special stdlib import because the package itself has issues that @@ -79,7 +79,7 @@ func (BarType) barFunc() {} //foo:bar // want `symbol should have a godoc \("bar // Asserting rule "no-unused-link" -// GODOC constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \("unused"\)` +// constWithUnusedLink point to [used] and unused links. // want `godoc has unused link \("unused"\)` // // [used]: https://example.com // @@ -88,5 +88,5 @@ const constWithUnusedLink = 1 // Asserting rule "max-len" -// GODOC constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc line is too long \(175 > 127\)` +// constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc line is too long \(169 > 127\)` const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go index ba2b58866a49..2ced76848afd 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_pass.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go @@ -4,7 +4,7 @@ // Asserting rule "pkg-doc" and "require-pkg-doc" since the package has a godoc. -// PACKAGE testdata +// Package testdata package testdata // This is a special stdlib import because the package itself has issues that @@ -13,50 +13,50 @@ import "go/ast" // Asserting rule "start-with-name" and "require-doc" (since all have godocs) -// GODOC FooType is... +// FooType is... type FooType struct{} -// GODOC FooAlias is... +// FooAlias is... type FooAlias = ast.Comment -// GODOC FooConst is... +// FooConst is... const FooConst = 1 -// GODOC FooVar is... +// FooVar is... var FooVar = 1 -// GODOC FooFunc is... +// FooFunc is... func FooFunc() {} -// GODOC FooFunc is... +// FooFunc is... func (FooType) FooFunc() {} -// GODOC fooType is... +// fooType is... type fooType struct{} -// GODOC fooAlias is... +// fooAlias is... type fooAlias = ast.Comment -// GODOC fooConst is... +// fooConst is... const fooConst = 1 -// GODOC fooVar is... +// fooVar is... var fooVar = 1 -// GODOC fooFunc is... +// fooFunc is... func fooFunc() {} -// GODOC fooFunc is... +// fooFunc is... func (FooType) fooFunc() {} // Asserting rule "no-unused-link" -// GODOC constWithUnusedLink point to a [used] link and has no unused one. +// constWithUnusedLink point to a [used] link and has no unused one. // // [used]: https://example.com const constWithUnusedLink = 1 // Asserting rule "max-len" -// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. +// constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. const constWithTooLongGodoc = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go index d17596e298af..2ced76848afd 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go @@ -2,61 +2,61 @@ //golangcitest:config_path testdata/godoclint.yml //golangcitest:expected_exitcode 0 -// Asserting rule "pkg-doc" +// Asserting rule "pkg-doc" and "require-pkg-doc" since the package has a godoc. -// PACKAGE testdata +// Package testdata package testdata // This is a special stdlib import because the package itself has issues that // godoclint can, but must not, detect. import "go/ast" -// Asserting rule "start-with-name" (also covering "require-doc" since all have godocs) +// Asserting rule "start-with-name" and "require-doc" (since all have godocs) -// GODOC FooType is... +// FooType is... type FooType struct{} -// GODOC FooAlias is... +// FooAlias is... type FooAlias = ast.Comment -// GODOC FooConst is... +// FooConst is... const FooConst = 1 -// GODOC FooVar is... +// FooVar is... var FooVar = 1 -// GODOC FooFunc is... +// FooFunc is... func FooFunc() {} -// GODOC FooFunc is... +// FooFunc is... func (FooType) FooFunc() {} -// GODOC fooType is... +// fooType is... type fooType struct{} -// GODOC fooAlias is... +// fooAlias is... type fooAlias = ast.Comment -// GODOC fooConst is... +// fooConst is... const fooConst = 1 -// GODOC fooVar is... +// fooVar is... var fooVar = 1 -// GODOC fooFunc is... +// fooFunc is... func fooFunc() {} -// GODOC fooFunc is... +// fooFunc is... func (FooType) fooFunc() {} // Asserting rule "no-unused-link" -// GODOC constWithUnusedLink point to a [used] link and has no unused one. +// constWithUnusedLink point to a [used] link and has no unused one. // // [used]: https://example.com const constWithUnusedLink = 1 // Asserting rule "max-len" -// GODOC constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. +// constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. const constWithTooLongGodoc = 1 From cad671179d8e310b6a5797203adecf13f727c416 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 11 Sep 2025 20:19:10 +0200 Subject: [PATCH 11/15] review --- .golangci.next.reference.yml | 35 ++++++++++++++--------- jsonschema/golangci.next.jsonschema.json | 36 +++++++----------------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 5dd1fa9902aa..dcf131d11e96 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1269,30 +1269,38 @@ linters: min-complexity: 10 godoclint: - # Default set of rules to enable. Possible values are: `basic`, `all` or `none`. - # Default: basic (enables `pkg-doc`, `single-pkg-doc`, and `start-with-name`) + # Default set of rules to enable. + # Possible values are: `basic`, `all` or `none`. + # Default: `basic` (enables `pkg-doc`, `single-pkg-doc`, and `start-with-name`) default: all - # List of rules to enable in addition to default set. See the linter docs for more details. - # Default: null + # List of rules to enable in addition to the default set. + # Default: empty enable: - # Check proper package-level godoc, if any + # Check proper package-level godoc, if any. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#pkg-doc - pkg-doc - # Assert at most one godoc per package + # Assert at most one godoc per package. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#single-pkg-doc - single-pkg-doc - # Require all packages to have a godoc + # Require all packages to have a godoc. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#require-pkg-doc - require-pkg-doc - # Assert symbol godocs start with the symbol name + # Assert symbol godocs start with the symbol name. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#start-with-name - start-with-name - # Require godoc for all public symbols + # Require godoc for all public symbols. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#require-doc - require-doc - # Assert maximum line length for godocs + # Assert maximum line length for godocs. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#max-len - max-len - # Assert no unused link in godocs + # Assert no unused link in godocs. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#no-unused-link - no-unused-link # List of rules to disable. - # Default: null + # Default: empty disable: - pkg-doc - single-pkg-doc @@ -1302,7 +1310,8 @@ linters: - max-len - no-unused-link - # A map for fine tuning individual rules. All sub-keys are optional. + # A map for fine-tuning individual rules. + # All subkeys are optional. options: max-len: # Maximum line length for godocs, not including the `// `, or `/*` or `*/` tokens. diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 8894c5fb5eb8..cee3898755da 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -1870,36 +1870,20 @@ "description": "Default set of rules to enable." }, "enable": { - "default": null, "description": "List of rules to enable in addition to the default set.", - "oneOf": [ - { - "type": "array", - "uniqueItems": true, - "items": { - "$ref": "#/definitions/godoclint-rules" - } - }, - { - "type": "null" - } - ] + "type": "array", + "uniqueItems": true, + "items": { + "$ref": "#/definitions/godoclint-rules" + } }, "disable": { - "default": null, "description": "List of rules to disable.", - "oneOf": [ - { - "type": "array", - "uniqueItems": true, - "items": { - "$ref": "#/definitions/godoclint-rules" - } - }, - { - "type": "null" - } - ] + "type": "array", + "uniqueItems": true, + "items": { + "$ref": "#/definitions/godoclint-rules" + } }, "options": { "type": "object", From 23ab774dc8d171a906b6c27ab50bb8b56fc19ee3 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 11 Sep 2025 21:50:31 +0100 Subject: [PATCH 12/15] fix: upgrade to godoclint v0.9.0 This version introduces a new rule, named `deprecated`, which checks the formatting of deprecation notes in godocs. Signed-off-by: Babak K. Shandiz --- .golangci.next.reference.yml | 4 ++++ go.mod | 2 +- go.sum | 4 ++-- jsonschema/golangci.next.jsonschema.json | 1 + pkg/golinters/godoclint/testdata/godoclint.yml | 3 ++- .../godoclint/testdata/godoclint_full_fail.go | 15 +++++++++++++++ .../godoclint/testdata/godoclint_full_pass.go | 13 +++++++++++++ .../testdata/godoclint_full_pass_test.go | 8 ++++++++ 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index dcf131d11e96..b70796d7c633 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1292,6 +1292,9 @@ linters: # Require godoc for all public symbols. # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#require-doc - require-doc + # Assert correct formatting of deprecation notes. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#deprecated + - deprecated # Assert maximum line length for godocs. # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#max-len - max-len @@ -1307,6 +1310,7 @@ linters: - require-pkg-doc - start-with-name - require-doc + - deprecated - max-len - no-unused-link diff --git a/go.mod b/go.mod index 09de6b1ef997..31bf2b03d1be 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/go-critic/go-critic v0.13.0 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-xmlfmt/xmlfmt v1.1.3 - github.com/godoc-lint/godoc-lint v0.8.0 + github.com/godoc-lint/godoc-lint v0.9.0 github.com/gofrs/flock v0.12.1 github.com/golangci/asciicheck v0.5.0 github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 diff --git a/go.sum b/go.sum index 008a210ce264..6d6ab2883e12 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godoc-lint/godoc-lint v0.8.0 h1:gYTh+PKN3SIIeNMkP1WV2KaxAKLpyWKI2pzrglHlBao= -github.com/godoc-lint/godoc-lint v0.8.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.9.0 h1:W1me5GrTLujhXaLmxuWfQSZRr6+7EYzbpPKdm49SsiE= +github.com/godoc-lint/godoc-lint v0.9.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index cee3898755da..ee12cba23d1b 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -484,6 +484,7 @@ "require-pkg-doc", "start-with-name", "require-doc", + "deprecated", "max-len", "no-unused-link" ] diff --git a/pkg/golinters/godoclint/testdata/godoclint.yml b/pkg/golinters/godoclint/testdata/godoclint.yml index 75cf69e0a38e..4cabcb6dea2d 100644 --- a/pkg/golinters/godoclint/testdata/godoclint.yml +++ b/pkg/golinters/godoclint/testdata/godoclint.yml @@ -9,8 +9,9 @@ linters: - require-pkg-doc - start-with-name - require-doc - - no-unused-link + - deprecated - max-len + - no-unused-link options: start-with-name: include-unexported: true diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_fail.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go index 6b003c0e53d0..772e126e699b 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_fail.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go @@ -90,3 +90,18 @@ const constWithUnusedLink = 1 // constWithTooLongGodoc has a very long godoc that exceeds the maximum allowed length for godoc comments in this test setup. // want `godoc line is too long \(169 > 127\)` const constWithTooLongGodoc = 1 + +// DeprecatedConstA is... // want `deprecation note should be formatted as "Deprecated: "` +// +// DEPRECATED: do not use +const DeprecatedConstA = 1 + +// DeprecatedConstB is... // want `deprecation note should be formatted as "Deprecated: "` +// +// DEPRECATED:do not use +const DeprecatedConstB = 1 + +// DeprecatedConstC is... // want `deprecation note should be formatted as "Deprecated: "` +// +// deprecated:do not use +const DeprecatedConstC = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go index 2ced76848afd..b6e863d7d8c7 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_pass.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go @@ -60,3 +60,16 @@ const constWithUnusedLink = 1 // constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. const constWithTooLongGodoc = 1 + +// DeprecatedConstA is... +// +// Deprecated: do not use +const DeprecatedConstA = 1 + +// Deprecated: do not use +const DeprecatedConstB = 1 + +// deprecatedConstC is... +// +// DEPRECATED: invalid deprecation note but okay since the symbol is not exported +const deprecatedConstC = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go index 2ced76848afd..5af229c836ff 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go @@ -60,3 +60,11 @@ const constWithUnusedLink = 1 // constWithTooLongGodoc has a very long godoc that does not exceed the maximum allowed length for godoc comments. const constWithTooLongGodoc = 1 + +// DeprecatedConstA is... +// +// Deprecated: do not use +const DeprecatedConstA = 1 + +// Deprecated: do not use +const DeprecatedConstB = 1 From 21e4af2a0952e756aa4986e5598401957253b2e9 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 11 Sep 2025 22:39:15 +0100 Subject: [PATCH 13/15] fix: upgrade to godoclint v0.10.0 With this version, the `deprecated` rule is enabled by default, so the default config test cases had to be updated. Signed-off-by: Babak K. Shandiz --- .golangci.next.reference.yml | 2 +- go.mod | 2 +- go.sum | 4 ++-- .../godoclint/testdata/godoclint_default_fail.go | 15 +++++++++++++++ .../godoclint/testdata/godoclint_default_pass.go | 13 +++++++++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index b70796d7c633..cd02dde81dd0 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -1271,7 +1271,7 @@ linters: godoclint: # Default set of rules to enable. # Possible values are: `basic`, `all` or `none`. - # Default: `basic` (enables `pkg-doc`, `single-pkg-doc`, and `start-with-name`) + # Default: `basic` (enables `pkg-doc`, `single-pkg-doc`, `start-with-name`, and `deprecated`) default: all # List of rules to enable in addition to the default set. diff --git a/go.mod b/go.mod index 31bf2b03d1be..fb374c86b7ed 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/go-critic/go-critic v0.13.0 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/go-xmlfmt/xmlfmt v1.1.3 - github.com/godoc-lint/godoc-lint v0.9.0 + github.com/godoc-lint/godoc-lint v0.10.0 github.com/gofrs/flock v0.12.1 github.com/golangci/asciicheck v0.5.0 github.com/golangci/dupl v0.0.0-20250308024227-f665c8d69b32 diff --git a/go.sum b/go.sum index 6d6ab2883e12..e0617fe2d72a 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUW github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/godoc-lint/godoc-lint v0.9.0 h1:W1me5GrTLujhXaLmxuWfQSZRr6+7EYzbpPKdm49SsiE= -github.com/godoc-lint/godoc-lint v0.9.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= +github.com/godoc-lint/godoc-lint v0.10.0 h1:OcyrziBi18sQSEpib6NesVHEJ/Xcng97NunePBA48g4= +github.com/godoc-lint/godoc-lint v0.10.0/go.mod h1:KleLcHu/CGSvkjUH2RvZyoK1MBC7pDQg4NxMYLcBBsw= github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/pkg/golinters/godoclint/testdata/godoclint_default_fail.go b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go index c7424672f1d3..a399f55ef343 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_default_fail.go +++ b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go @@ -24,3 +24,18 @@ func FooFunc() {} // bad godoc // want `godoc should start with symbol name \("FooFunc"\)` func (FooType) FooFunc() {} + +// DeprecatedConstA is... // want `deprecation note should be formatted as "Deprecated: "` +// +// DEPRECATED: do not use +const DeprecatedConstA = 1 + +// DeprecatedConstB is... // want `deprecation note should be formatted as "Deprecated: "` +// +// DEPRECATED:do not use +const DeprecatedConstB = 1 + +// DeprecatedConstC is... // want `deprecation note should be formatted as "Deprecated: "` +// +// deprecated:do not use +const DeprecatedConstC = 1 diff --git a/pkg/golinters/godoclint/testdata/godoclint_default_pass.go b/pkg/golinters/godoclint/testdata/godoclint_default_pass.go index 11fdcaac5576..51453b6787fd 100644 --- a/pkg/golinters/godoclint/testdata/godoclint_default_pass.go +++ b/pkg/golinters/godoclint/testdata/godoclint_default_pass.go @@ -43,3 +43,16 @@ func fooFunc() {} // bad godoc on unexported symbol func (FooType) fooFunc() {} + +// DeprecatedConstA is... +// +// Deprecated: do not use +const DeprecatedConstA = 1 + +// Deprecated: do not use +const DeprecatedConstB = 1 + +// deprecatedConstC is... +// +// DEPRECATED: invalid deprecation note but okay since the symbol is not exported +const deprecatedConstC = 1 From 3922fe58e7a36ce03363ce5854b5198f8d3d2de6 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 12 Sep 2025 00:14:47 +0200 Subject: [PATCH 14/15] review: settings validation --- pkg/golinters/godoclint/godoclint.go | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go index ceae6033c19d..cc56af5429b1 100644 --- a/pkg/golinters/godoclint/godoclint.go +++ b/pkg/golinters/godoclint/godoclint.go @@ -1,17 +1,27 @@ package godoclint import ( + "errors" + "fmt" + "slices" + glcompose "github.com/godoc-lint/godoc-lint/pkg/compose" glconfig "github.com/godoc-lint/godoc-lint/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" + "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) func New(settings *config.GodoclintSettings) *goanalysis.Linter { var pcfg glconfig.PlainConfig if settings != nil { + err := checkSettings(settings) + if err != nil { + internal.LinterLogger.Fatalf("godoclint: %v", err) + } + // The following options are explicitly ignored: they must be handled globally with exclusions or nolint directives. // - Include // - Exclude @@ -47,6 +57,9 @@ func New(settings *config.GodoclintSettings) *goanalysis.Linter { composition := glcompose.Compose(glcompose.CompositionConfig{ BaseDirPlainConfig: &pcfg, + ExitFunc: func(_ int, err error) { + internal.LinterLogger.Errorf("godoclint: %v", err) + }, }) return goanalysis. @@ -54,4 +67,42 @@ func New(settings *config.GodoclintSettings) *goanalysis.Linter { WithLoadMode(goanalysis.LoadModeSyntax) } +func checkSettings(settings *config.GodoclintSettings) error { + switch deref(settings.Default) { + case "all": + if len(settings.Enable) > 0 { + return errors.New("cannot use 'enable' with 'default=all'") + } + + case "none": + if len(settings.Disable) > 0 { + return errors.New("cannot use 'disable' with 'default=none'") + } + + default: + for _, rule := range settings.Enable { + if slices.Contains(settings.Disable, rule) { + return fmt.Errorf("a rule cannot be enabled and disabled at the same time: '%s'", rule) + } + } + + for _, rule := range settings.Disable { + if slices.Contains(settings.Enable, rule) { + return fmt.Errorf("a rule cannot be enabled and disabled at the same time: '%s'", rule) + } + } + } + + return nil +} + func pointer[T any](v T) *T { return &v } + +func deref[T any](v *T) T { + if v == nil { + var zero T + return zero + } + + return *v +} From f9bb85fe0c0fce23797aa31f3dc585de9f10d1f2 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 12 Sep 2025 00:20:05 +0200 Subject: [PATCH 15/15] review: use constants --- pkg/golinters/godoclint/godoclint.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go index cc56af5429b1..235909217f63 100644 --- a/pkg/golinters/godoclint/godoclint.go +++ b/pkg/golinters/godoclint/godoclint.go @@ -7,6 +7,7 @@ import ( glcompose "github.com/godoc-lint/godoc-lint/pkg/compose" glconfig "github.com/godoc-lint/godoc-lint/pkg/config" + "github.com/godoc-lint/godoc-lint/pkg/model" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -69,12 +70,12 @@ func New(settings *config.GodoclintSettings) *goanalysis.Linter { func checkSettings(settings *config.GodoclintSettings) error { switch deref(settings.Default) { - case "all": + case string(model.DefaultSetAll): if len(settings.Enable) > 0 { return errors.New("cannot use 'enable' with 'default=all'") } - case "none": + case string(model.DefaultSetNone): if len(settings.Disable) > 0 { return errors.New("cannot use 'disable' with 'default=none'") }