aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/4meepo
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-12-05 15:10:03 +0100
committerTaras Madan <tarasmadan@google.com>2023-12-06 11:31:44 +0000
commit2ab72b4feef2c97f22f90cfbf9e45a6cfcd08bda (patch)
treea6d19b94b6399fcc00a6cfa430885cd349dd1533 /vendor/github.com/4meepo
parente08e8f492d31d672cc245944c185f8aadf2ee695 (diff)
vendor: updates
Diffstat (limited to 'vendor/github.com/4meepo')
-rw-r--r--vendor/github.com/4meepo/tagalign/README.md4
-rw-r--r--vendor/github.com/4meepo/tagalign/tagalign.go38
2 files changed, 34 insertions, 8 deletions
diff --git a/vendor/github.com/4meepo/tagalign/README.md b/vendor/github.com/4meepo/tagalign/README.md
index 262a2e429..9d04dccbf 100644
--- a/vendor/github.com/4meepo/tagalign/README.md
+++ b/vendor/github.com/4meepo/tagalign/README.md
@@ -48,7 +48,7 @@ By default tagalign will only align tags, but not sort them. But alignment and [
* As a Golangci Linter (Recommended)
Tagalign is a built-in linter in [Golangci Lint](https://golangci-lint.run/usage/linters/#tagalign) since `v1.53`.
- > Note: In order to have the best experience, add the `--fix` flag to `golangci-lint` to enabled the aufofix feature.
+ > Note: In order to have the best experience, add the `--fix` flag to `golangci-lint` to enable the autofix feature.
* Standalone Mode
@@ -117,7 +117,7 @@ type StrictStyleExample struct {
}
```
-> Note: The strict style can't run without the align or sort feature enabled.
+> ⚠️Note: The strict style can't run without the align or sort feature enabled.
## References
diff --git a/vendor/github.com/4meepo/tagalign/tagalign.go b/vendor/github.com/4meepo/tagalign/tagalign.go
index c99851036..4734b5666 100644
--- a/vendor/github.com/4meepo/tagalign/tagalign.go
+++ b/vendor/github.com/4meepo/tagalign/tagalign.go
@@ -29,6 +29,10 @@ const (
StrictStyle
)
+const (
+ errTagValueSyntax = "bad syntax for struct tag value"
+)
+
func NewAnalyzer(options ...Option) *analysis.Analyzer {
return &analysis.Analyzer{
Name: "tagalign",
@@ -208,16 +212,25 @@ func (w *Helper) Process(pass *analysis.Pass) { //nolint:gocognit
uniqueKeys = append(uniqueKeys, k)
}
- for i, field := range fields {
- offsets[i] = pass.Fset.Position(field.Tag.Pos()).Column
+ for i := 0; i < len(fields); {
+ field := fields[i]
+ column := pass.Fset.Position(field.Tag.Pos()).Column - 1
+ offsets[i] = column
+
tag, err := strconv.Unquote(field.Tag.Value)
if err != nil {
- break
+ // if tag value is not a valid string, report it directly
+ w.report(pass, field, column, errTagValueSyntax, field.Tag.Value)
+ fields = removeField(fields, i)
+ continue
}
tags, err := structtag.Parse(tag)
if err != nil {
- break
+ // if tag value is not a valid struct tag, report it directly
+ w.report(pass, field, column, err.Error(), field.Tag.Value)
+ fields = removeField(fields, i)
+ continue
}
maxTagNum = max(maxTagNum, tags.Len())
@@ -234,6 +247,8 @@ func (w *Helper) Process(pass *analysis.Pass) { //nolint:gocognit
addKey(t.Key)
}
tagsGroup = append(tagsGroup, tags.Tags())
+
+ i++
}
if w.sort && StrictStyle == w.style {
@@ -325,19 +340,22 @@ func (w *Helper) Process(pass *analysis.Pass) { //nolint:gocognit
msg := "tag is not aligned, should be: " + unquoteTag
- w.report(pass, field, offsets[i]-1, msg, newTagValue)
+ w.report(pass, field, offsets[i], msg, newTagValue)
}
}
// process single fields
for _, field := range w.singleFields {
+ column := pass.Fset.Position(field.Tag.Pos()).Column - 1
tag, err := strconv.Unquote(field.Tag.Value)
if err != nil {
+ w.report(pass, field, column, errTagValueSyntax, field.Tag.Value)
continue
}
tags, err := structtag.Parse(tag)
if err != nil {
+ w.report(pass, field, column, err.Error(), field.Tag.Value)
continue
}
originalTags := append([]*structtag.Tag(nil), tags.Tags()...)
@@ -353,7 +371,7 @@ func (w *Helper) Process(pass *analysis.Pass) { //nolint:gocognit
msg := "tag is not aligned , should be: " + tags.String()
- w.report(pass, field, pass.Fset.Position(field.Tag.Pos()).Column-1, msg, newTagValue)
+ w.report(pass, field, column, msg, newTagValue)
}
}
@@ -431,3 +449,11 @@ func max(a, b int) int {
}
return b
}
+
+func removeField(fields []*ast.Field, index int) []*ast.Field {
+ if index < 0 || index >= len(fields) {
+ return fields
+ }
+
+ return append(fields[:index], fields[index+1:]...)
+}