From 9fb5457aeea94d2f758d3d68546f6980710a6977 Mon Sep 17 00:00:00 2001 From: 4meepo Date: Fri, 28 Jul 2023 15:15:27 +0800 Subject: [PATCH 1/3] bump tagalign from v1.3.1 to v1.3.2 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7eefa6a2689b..530f4c0c159c 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.3.1 + github.com/4meepo/tagalign v1.3.2 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 cf3c0bbdf165..9251a1d8f7a0 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/4meepo/tagalign v1.3.1 h1:rgmaEHXOCks52e6IpowKCPAIRJCVLlO3jyf97uDmmgo= github.com/4meepo/tagalign v1.3.1/go.mod h1:Q9c1rYMZJc9dPRkbQPpcBNCLEmY2njbAsXhQOZFE2dE= +github.com/4meepo/tagalign v1.3.2 h1:1idD3yxlRGV18VjqtDbqYvQ5pXqQS0wO2dn6M3XstvI= +github.com/4meepo/tagalign v1.3.2/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= From 210b9165d8e4c5b8dafe1365e76a2504bb4a1891 Mon Sep 17 00:00:00 2001 From: 4meepo Date: Fri, 28 Jul 2023 15:15:39 +0800 Subject: [PATCH 2/3] strict style test case --- test/testdata/configs/tagalign_strict.yml | 5 +++++ test/testdata/tagalign_strict.go | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/testdata/configs/tagalign_strict.yml create mode 100644 test/testdata/tagalign_strict.go diff --git a/test/testdata/configs/tagalign_strict.yml b/test/testdata/configs/tagalign_strict.yml new file mode 100644 index 000000000000..84a0dd88c387 --- /dev/null +++ b/test/testdata/configs/tagalign_strict.yml @@ -0,0 +1,5 @@ +linters-settings: + tagalign: + align: true + sort: true + strict: true diff --git a/test/testdata/tagalign_strict.go b/test/testdata/tagalign_strict.go new file mode 100644 index 000000000000..6689d486fc52 --- /dev/null +++ b/test/testdata/tagalign_strict.go @@ -0,0 +1,10 @@ +//golangcitest:args -Etagalign +//golangcitest:config_path testdata/configs/tagalign_strict.yml +package testdata + +import "time" + +type TagAlignExampleStrictKO struct { + Foo time.Time `json:"foo,omitempty" validate:"required" zip:"foo"` // want ` json:"foo,omitempty" validate:"required" zip:"foo"` + FooBar struct{} `gorm:"column:fooBar" validate:"required" zip:"fooBar" xml:"fooBar" json:"fooBar,omitempty" yaml:"fooBar"` // want `gorm:"column:fooBar" json:"fooBar,omitempty" validate:"required" xml:"fooBar" yaml:"fooBar" zip:"fooBar"` +} From 8edebb9add99cdcad62be188701c639c0908cb14 Mon Sep 17 00:00:00 2001 From: 4meepo Date: Fri, 28 Jul 2023 15:17:07 +0800 Subject: [PATCH 3/3] Strict style must be used together with align and sort --- .golangci.reference.yml | 1 + pkg/golinters/tagalign.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index eb8159d9b77f..18c34aafd0d3 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1806,6 +1806,7 @@ linters-settings: # 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. + # Note: This option will be ignored if 'align' or 'sort' is false. # Default: false strict: true diff --git a/pkg/golinters/tagalign.go b/pkg/golinters/tagalign.go index 16a113669e3e..c23838f702b5 100644 --- a/pkg/golinters/tagalign.go +++ b/pkg/golinters/tagalign.go @@ -25,7 +25,8 @@ func NewTagAlign(settings *config.TagAlignSettings) *goanalysis.Linter { options = append(options, tagalign.WithSort(settings.Order...)) } - if settings.Strict { + // Strict style will be applied only if Align and Sort are enabled together. + if settings.Strict && settings.Align && settings.Sort { options = append(options, tagalign.WithStrictStyle()) } }