diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index bc88db36c93f..2adb14f8b4b7 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -398,6 +398,9 @@ linters: # Default: [] ignore: - "0C0C" + # Checks only comments, skip strings. + # Default: false + comments-only: true embeddedstructfieldcheck: # Checks that there is an empty space between the embedded fields and regular fields. diff --git a/go.mod b/go.mod index 7dfc006259d3..ecf0c7554c1e 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( 4d63.com/gochecknoglobals v0.2.2 dev.gaijin.team/go/exhaustruct/v4 v4.0.0 github.com/4meepo/tagalign v1.4.3 - github.com/Abirdcfly/dupword v0.1.6 + github.com/Abirdcfly/dupword v0.1.7 github.com/AdminBenni/iota-mixing v1.0.0 github.com/AlwxSin/noinlineerr v1.0.5 github.com/Antonboom/errname v1.1.1 diff --git a/go.sum b/go.sum index 98bce79cb101..32bd83d4fbb7 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ dev.gaijin.team/go/golib v0.6.0/go.mod h1:uY1mShx8Z/aNHWDyAkZTkX+uCi5PdX7KsG1eDQ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/4meepo/tagalign v1.4.3 h1:Bnu7jGWwbfpAie2vyl63Zup5KuRv21olsPIha53BJr8= github.com/4meepo/tagalign v1.4.3/go.mod h1:00WwRjiuSbrRJnSVeGWPLp2epS5Q/l4UEy0apLLS37c= -github.com/Abirdcfly/dupword v0.1.6 h1:qeL6u0442RPRe3mcaLcbaCi2/Y/hOcdtw6DE9odjz9c= -github.com/Abirdcfly/dupword v0.1.6/go.mod h1:s+BFMuL/I4YSiFv29snqyjwzDp4b65W2Kvy+PKzZ6cw= +github.com/Abirdcfly/dupword v0.1.7 h1:2j8sInznrje4I0CMisSL6ipEBkeJUJAmK1/lfoNGWrQ= +github.com/Abirdcfly/dupword v0.1.7/go.mod h1:K0DkBeOebJ4VyOICFdppB23Q0YMOgVafM0zYW0n9lF4= github.com/AdminBenni/iota-mixing v1.0.0 h1:Os6lpjG2dp/AE5fYBPAA1zfa2qMdCAWwPMCgpwKq7wo= github.com/AdminBenni/iota-mixing v1.0.0/go.mod h1:i4+tpAaB+qMVIV9OK3m4/DAynOd5bQFaOu+2AhtBCNY= github.com/AlwxSin/noinlineerr v1.0.5 h1:RUjt63wk1AYWTXtVXbSqemlbVTb23JOSRiNsshj7TbY= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 31c1c0e08c97..a2cf0fd963d0 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -945,6 +945,11 @@ "type": "string", "examples": ["0C0C"] } + }, + "comments-only": { + "description": "Checks only comments, skip strings.", + "type": "boolean", + "default": false } } }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 7c39600a44c1..ba60dd2c63ce 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -386,8 +386,9 @@ type DuplSettings struct { } type DupWordSettings struct { - Keywords []string `mapstructure:"keywords"` - Ignore []string `mapstructure:"ignore"` + Keywords []string `mapstructure:"keywords"` + Ignore []string `mapstructure:"ignore"` + CommentsOnly bool `mapstructure:"comments-only"` } type EmbeddedStructFieldCheckSettings struct { diff --git a/pkg/golinters/dupword/dupword.go b/pkg/golinters/dupword/dupword.go index 7b989bc22a8f..0308534e3180 100644 --- a/pkg/golinters/dupword/dupword.go +++ b/pkg/golinters/dupword/dupword.go @@ -14,8 +14,9 @@ func New(settings *config.DupWordSettings) *goanalysis.Linter { if settings != nil { cfg = map[string]any{ - "keyword": strings.Join(settings.Keywords, ","), - "ignore": strings.Join(settings.Ignore, ","), + "keyword": strings.Join(settings.Keywords, ","), + "ignore": strings.Join(settings.Ignore, ","), + "comments-only": settings.CommentsOnly, } } diff --git a/pkg/golinters/dupword/testdata/dupword_comments_only.go b/pkg/golinters/dupword/testdata/dupword_comments_only.go new file mode 100644 index 000000000000..1ade06b37b6b --- /dev/null +++ b/pkg/golinters/dupword/testdata/dupword_comments_only.go @@ -0,0 +1,16 @@ +//golangcitest:args -Edupword +//golangcitest:config_path testdata/dupword_comments_only.yml +package testdata + +import "fmt" + +func _() { + // want +2 `Duplicate words \(and\) found` + // want +2 `Duplicate words \(and,the\) found` + // this line include duplicate word and and + // print the\n the line, print the the \n\t the line. and and + + a := "this line include duplicate word and and" + b := "print the\n the line, print the the \n\t the line. and and" + fmt.Println(a, b) +} diff --git a/pkg/golinters/dupword/testdata/dupword_comments_only.yml b/pkg/golinters/dupword/testdata/dupword_comments_only.yml new file mode 100644 index 000000000000..8281f7112d23 --- /dev/null +++ b/pkg/golinters/dupword/testdata/dupword_comments_only.yml @@ -0,0 +1,6 @@ +version: "2" + +linters: + settings: + dupword: + comments-only: true diff --git a/pkg/golinters/dupword/testdata/dupword_ignore_the.go b/pkg/golinters/dupword/testdata/dupword_ignore.go similarity index 87% rename from pkg/golinters/dupword/testdata/dupword_ignore_the.go rename to pkg/golinters/dupword/testdata/dupword_ignore.go index b00d19b22803..2d58dd6341db 100644 --- a/pkg/golinters/dupword/testdata/dupword_ignore_the.go +++ b/pkg/golinters/dupword/testdata/dupword_ignore.go @@ -1,5 +1,5 @@ //golangcitest:args -Edupword -//golangcitest:config_path testdata/dupword_ignore_the.yml +//golangcitest:config_path testdata/dupword_ignore.yml package testdata import "fmt" diff --git a/pkg/golinters/dupword/testdata/dupword_ignore_the.yml b/pkg/golinters/dupword/testdata/dupword_ignore.yml similarity index 100% rename from pkg/golinters/dupword/testdata/dupword_ignore_the.yml rename to pkg/golinters/dupword/testdata/dupword_ignore.yml