mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
struct-tag warns on private fields with tags (#131)
This commit is contained in:
@@ -2,11 +2,12 @@ package rule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fatih/structtag"
|
||||
"github.com/mgechev/revive/lint"
|
||||
"go/ast"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structtag"
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// StructTagRule lints struct tags.
|
||||
@@ -58,6 +59,10 @@ func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
|
||||
// checkTaggedField checks the tag of the given field.
|
||||
// precondition: the field has a tag
|
||||
func (w lintStructTagRule) checkTaggedField(f *ast.Field) {
|
||||
if len(f.Names) > 0 && !f.Names[0].IsExported() {
|
||||
w.addFailure(f, "tag on not-exported field "+f.Names[0].Name)
|
||||
}
|
||||
|
||||
tags, err := structtag.Parse(strings.Trim(f.Tag.Value, "`"))
|
||||
if err != nil || tags == nil {
|
||||
w.addFailure(f.Tag, "malformed tag")
|
||||
|
||||
Reference in New Issue
Block a user