diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 44ce5c4a9db8..cd02dde81dd0 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,74 @@ linters: # Default: 30 (but we recommend 10-20) 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`, `start-with-name`, and `deprecated`) + default: all + + # List of rules to enable in addition to the default set. + # Default: empty + enable: + # 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. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#single-pkg-doc + - single-pkg-doc + # 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. + # https://github.com/godoc-lint/godoc-lint?tab=readme-ov-file#start-with-name + - start-with-name + # 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 + # 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: empty + disable: + - pkg-doc + - single-pkg-doc + - require-pkg-doc + - start-with-name + - require-doc + - deprecated + - max-len + - no-unused-link + + # 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. + # Default: 77 + length: 127 + + 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 + + start-with-name: + # Include unexported symbols when applying the `start-with-name` rule. + # Default: false + include-unexported: true + godot: # Comments to be checked: `declarations`, `toplevel`, `noinline` or `all`. # Default: declarations diff --git a/go.mod b/go.mod index 788c13b6d9f3..fb374c86b7ed 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.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 afd7617733b4..e0617fe2d72a 100644 --- a/go.sum +++ b/go.sum @@ -223,6 +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.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/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 9221df3feb96..ee12cba23d1b 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -477,6 +477,18 @@ "-QF1012" ] }, + "godoclint-rules": { + "enum": [ + "pkg-doc", + "single-pkg-doc", + "require-pkg-doc", + "start-with-name", + "require-doc", + "deprecated", + "max-len", + "no-unused-link" + ] + }, "gosec-rules": { "enum": [ "G101", @@ -795,6 +807,7 @@ "goconst", "gocritic", "gocyclo", + "godoclint", "godot", "godox", "err113", @@ -1848,6 +1861,74 @@ } } }, + "godoclintSettings": { + "type": "object", + "properties": { + "default": { + "type": "string", + "enum": ["all", "basic", "none"], + "default": "basic", + "description": "Default set of rules to enable." + }, + "enable": { + "description": "List of rules to enable in addition to the default set.", + "type": "array", + "uniqueItems": true, + "items": { + "$ref": "#/definitions/godoclint-rules" + } + }, + "disable": { + "description": "List of rules to disable.", + "type": "array", + "uniqueItems": true, + "items": { + "$ref": "#/definitions/godoclint-rules" + } + }, + "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 + } + } + }, + "require-doc": { + "type": "object", + "properties": { + "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-unexported": { + "type": "boolean", + "description": "Include unexported symbols when applying the `start-with-name` rule.", + "default": false + } + } + } + } + } + } + }, "godotSettings": { "type": "object", "additionalProperties": false, @@ -4547,6 +4628,9 @@ "gocyclo": { "$ref": "#/definitions/settings/definitions/gocycloSettings" }, + "godoclint": { + "$ref": "#/definitions/settings/definitions/godoclintSettings" + }, "godot": { "$ref": "#/definitions/settings/definitions/godotSettings" }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 567416d977de..1eb50a74662f 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,24 @@ type GoCycloSettings struct { MinComplexity int `mapstructure:"min-complexity"` } +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"` + RequireDoc struct { + IgnoreExported *bool `mapstructure:"ignore-exported"` + IgnoreUnexported *bool `mapstructure:"ignore-unexported"` + } `mapstructure:"require-doc"` + StartWithName struct { + IncludeUnexported *bool `mapstructure:"include-unexported"` + } `mapstructure:"start-with-name"` + } `mapstructure:"options"` +} + type GodotSettings struct { Scope string `mapstructure:"scope"` Exclude []string `mapstructure:"exclude"` diff --git a/pkg/golinters/godoclint/godoclint.go b/pkg/golinters/godoclint/godoclint.go new file mode 100644 index 000000000000..235909217f63 --- /dev/null +++ b/pkg/golinters/godoclint/godoclint.go @@ -0,0 +1,109 @@ +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/godoc-lint/godoc-lint/pkg/model" + + "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 + + // 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{ + Default: settings.Default, + Enable: settings.Enable, + Disable: settings.Disable, + Options: &glconfig.PlainRuleOptions{ + MaxLenLength: settings.Options.MaxLen.Length, + MaxLenIncludeTests: pointer(true), + PkgDocIncludeTests: pointer(false), + SinglePkgDocIncludeTests: pointer(true), + RequirePkgDocIncludeTests: pointer(false), + RequireDocIncludeTests: pointer(true), + RequireDocIgnoreExported: settings.Options.RequireDoc.IgnoreExported, + RequireDocIgnoreUnexported: settings.Options.RequireDoc.IgnoreUnexported, + StartWithNameIncludeTests: pointer(false), + StartWithNameIncludeUnexported: settings.Options.StartWithName.IncludeUnexported, + NoUnusedLinkIncludeTests: pointer(true), + }, + } + } + + composition := glcompose.Compose(glcompose.CompositionConfig{ + BaseDirPlainConfig: &pcfg, + ExitFunc: func(_ int, err error) { + internal.LinterLogger.Errorf("godoclint: %v", err) + }, + }) + + return goanalysis. + NewLinterFromAnalyzer(composition.Analyzer.GetAnalyzer()). + WithLoadMode(goanalysis.LoadModeSyntax) +} + +func checkSettings(settings *config.GodoclintSettings) error { + switch deref(settings.Default) { + case string(model.DefaultSetAll): + if len(settings.Enable) > 0 { + return errors.New("cannot use 'enable' with 'default=all'") + } + + case string(model.DefaultSetNone): + 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 +} 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..4cabcb6dea2d --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint.yml @@ -0,0 +1,22 @@ +version: "2" + +linters: + settings: + godoclint: + default: none + enable: + - pkg-doc + - require-pkg-doc + - start-with-name + - require-doc + - deprecated + - max-len + - no-unused-link + options: + start-with-name: + include-unexported: true + require-doc: + ignore-exported: false + ignore-unexported: false + max-len: + length: 127 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..a399f55ef343 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_default_fail.go @@ -0,0 +1,41 @@ +//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 \("FooType"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \("FooAlias"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \("FooConst"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \("FooVar"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` +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 new file mode 100644 index 000000000000..51453b6787fd --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_default_pass.go @@ -0,0 +1,58 @@ +//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() {} + +// 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_fail.go b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go new file mode 100644 index 000000000000..772e126e699b --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_fail.go @@ -0,0 +1,107 @@ +//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 \("FooType"\)` +type FooType struct{} + +// bad godoc // want `godoc should start with symbol name \("FooAlias"\)` +type FooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \("FooConst"\)` +const FooConst = 1 + +// bad godoc // want `godoc should start with symbol name \("FooVar"\)` +var FooVar = 1 + +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` +func FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \("FooFunc"\)` +func (FooType) FooFunc() {} + +// bad godoc // want `godoc should start with symbol name \("fooType"\)` +type fooType struct{} + +// bad godoc // want `godoc should start with symbol name \("fooAlias"\)` +type fooAlias = ast.Comment + +// bad godoc // want `godoc should start with symbol name \("fooConst"\)` +const fooConst = 1 + +// bad godoc // want `godoc should start with symbol name \("fooVar"\)` +var fooVar = 1 + +// bad godoc // want `godoc should start with symbol name \("fooFunc"\)` +func fooFunc() {} + +// bad godoc // want `godoc should start with symbol name \("fooFunc"\)` +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" + +// 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" + +// 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 new file mode 100644 index 000000000000..b6e863d7d8c7 --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass.go @@ -0,0 +1,75 @@ +//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) + +// FooType is... +type FooType struct{} + +// FooAlias is... +type FooAlias = ast.Comment + +// FooConst is... +const FooConst = 1 + +// FooVar is... +var FooVar = 1 + +// FooFunc is... +func FooFunc() {} + +// FooFunc is... +func (FooType) FooFunc() {} + +// fooType is... +type fooType struct{} + +// fooAlias is... +type fooAlias = ast.Comment + +// fooConst is... +const fooConst = 1 + +// fooVar is... +var fooVar = 1 + +// fooFunc is... +func fooFunc() {} + +// fooFunc is... +func (FooType) fooFunc() {} + +// Asserting rule "no-unused-link" + +// constWithUnusedLink point to a [used] link and has no unused one. +// +// [used]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// 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 new file mode 100644 index 000000000000..5af229c836ff --- /dev/null +++ b/pkg/golinters/godoclint/testdata/godoclint_full_pass_test.go @@ -0,0 +1,70 @@ +//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) + +// FooType is... +type FooType struct{} + +// FooAlias is... +type FooAlias = ast.Comment + +// FooConst is... +const FooConst = 1 + +// FooVar is... +var FooVar = 1 + +// FooFunc is... +func FooFunc() {} + +// FooFunc is... +func (FooType) FooFunc() {} + +// fooType is... +type fooType struct{} + +// fooAlias is... +type fooAlias = ast.Comment + +// fooConst is... +const fooConst = 1 + +// fooVar is... +var fooVar = 1 + +// fooFunc is... +func fooFunc() {} + +// fooFunc is... +func (FooType) fooFunc() {} + +// Asserting rule "no-unused-link" + +// constWithUnusedLink point to a [used] link and has no unused one. +// +// [used]: https://example.com +const constWithUnusedLink = 1 + +// Asserting rule "max-len" + +// 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 diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index c64d498e4198..d8c9b8bdc309 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,10 @@ 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"). + WithURL("https://github.com/godoc-lint/godoc-lint"), + linter.NewConfig(godot.New(&cfg.Linters.Settings.Godot)). WithSince("v1.25.0"). WithAutoFix().