diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 728179f3..eb8159d9 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1803,6 +1803,11 @@ linters-settings: - mapstructure - binding - validate + # Whether enable strict style. + # In this style, the tags will be sorted and aligned in the dictionary order, + # and the tags with the same name will be aligned together. + # Default: false + strict: true tagliatelle: # Check the struct tag name case. diff --git a/go.mod b/go.mod index c7171eb2..7eefa6a2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( 4d63.com/gocheckcompilerdirectives v1.2.1 4d63.com/gochecknoglobals v0.2.1 - github.com/4meepo/tagalign v1.2.2 + github.com/4meepo/tagalign v1.3.1 github.com/Abirdcfly/dupword v0.0.12 github.com/Antonboom/errname v0.1.10 github.com/Antonboom/nilnil v0.1.5 diff --git a/go.sum b/go.sum index e1aeaa76..cf3c0bbd 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/4meepo/tagalign v1.2.2 h1:kQeUTkFTaBRtd/7jm8OKJl9iHk0gAO+TDFPHGSna0aw= -github.com/4meepo/tagalign v1.2.2/go.mod h1:Q9c1rYMZJc9dPRkbQPpcBNCLEmY2njbAsXhQOZFE2dE= +github.com/4meepo/tagalign v1.3.1 h1:rgmaEHXOCks52e6IpowKCPAIRJCVLlO3jyf97uDmmgo= +github.com/4meepo/tagalign v1.3.1/go.mod h1:Q9c1rYMZJc9dPRkbQPpcBNCLEmY2njbAsXhQOZFE2dE= github.com/Abirdcfly/dupword v0.0.12 h1:56NnOyrXzChj07BDFjeRA+IUzSz01jmzEq+G4kEgFhc= github.com/Abirdcfly/dupword v0.0.12/go.mod h1:+us/TGct/nI9Ndcbcp3rgNcQzctTj68pq7TcgNpLfdI= github.com/Antonboom/errname v0.1.10 h1:RZ7cYo/GuZqjr1nuJLNe8ZH+a+Jd9DaZzttWzak9Bls= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 41c2cb6c..a1778ed9 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -114,9 +114,10 @@ var defaultLintersSettings = LintersSettings{ Qualified: false, }, TagAlign: TagAlignSettings{ - Align: true, - Sort: true, - Order: nil, + Align: true, + Sort: true, + Order: nil, + Strict: false, }, Testpackage: TestpackageSettings{ SkipRegexp: `(export|internal)_test\.go`, @@ -720,9 +721,10 @@ type StructCheckSettings struct { } type TagAlignSettings struct { - Align bool `mapstructure:"align"` - Sort bool `mapstructure:"sort"` - Order []string `mapstructure:"order"` + Align bool `mapstructure:"align"` + Sort bool `mapstructure:"sort"` + Order []string `mapstructure:"order"` + Strict bool `mapstructure:"strict"` } type TagliatelleSettings struct { diff --git a/pkg/golinters/tagalign.go b/pkg/golinters/tagalign.go index 07b75646..16a11366 100644 --- a/pkg/golinters/tagalign.go +++ b/pkg/golinters/tagalign.go @@ -24,6 +24,10 @@ func NewTagAlign(settings *config.TagAlignSettings) *goanalysis.Linter { if settings.Sort || len(settings.Order) > 0 { options = append(options, tagalign.WithSort(settings.Order...)) } + + if settings.Strict { + options = append(options, tagalign.WithStrictStyle()) + } } analyzer := tagalign.NewAnalyzer(options...)