clerk/internal/linter/rule_duplicated_tag.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com linter: add different rules related to tags..., 2 months ago
olexsmir@gmail.com linter: add different rules related to tags..., 2 months ago
| 1 | package linter |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "olexsmir.xyz/clerk/internal/analyzer" |
| 7 | ) |
| 8 | |
| 9 | // DuplicatedTag flags tag declarations that appear more than once. |
| 10 | type DuplicatedTag struct{} |
| 11 | |
| 12 | func (DuplicatedTag) ID() RuleID { return "duplicated-tag" } |
| 13 | func (DuplicatedTag) Severity() Severity { return SeverityWarning } |
| 14 | func (d *DuplicatedTag) CheckJournal(an *analyzer.Analysis) []Find { |
| 15 | var finds []Find |
| 16 | for name, info := range an.Tags { |
| 17 | if len(info.Directives) <= 1 { |
| 18 | continue |
| 19 | } |
| 20 | for _, td := range info.Directives { |
| 21 | finds = append(finds, Find{ |
| 22 | Code: d.ID(), |
| 23 | Severity: d.Severity(), |
| 24 | Message: fmt.Sprintf("duplicated tag declaration: %s", name), |
| 25 | Span: td.Span, |
| 26 | }) |
| 27 | } |
| 28 | } |
| 29 | return finds |
| 30 | } |