gotaglint

package module
v0.0.0-...-1f295fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 12 Imported by: 0

README

gotaglint

linter for go tag

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BindingNameAnalyzer = analysis.Analyzer{
	Name: "bindingtaglint",
	Doc:  "report bad usage for validator tag",
	Run:  runBindingTagLint,
}
View Source
var BsonAnalyzer = analysis.Analyzer{
	Name: "bsontaglint",
	Doc:  "report bson tag problem",
	Run: runTagChecker("bson", func(pass *analysis.Pass, field *ast.Field, tag string) {
		bsonTag := ParseBsonTag(tag)
		if bsonTag.Skip {
			return
		}
		if len(bsonTag.InvalidOptions) > 0 {
			pass.Reportf(field.Tag.Pos(), "invalid bson options:%q", render(pass.Fset, field.Tag))
		}
		if len(field.Names) > 0 && bsonTag.Name == strings.ToLower(field.Names[0].Name) {
			pass.Reportf(field.Tag.Pos(), "same bson tag name:%q", render(pass.Fset, field.Tag))
		}
		if bsonTag.Inline && !isBsonInlineable(pass.TypesInfo.TypeOf(field.Type)) {
			pass.Reportf(field.Tag.Pos(), "inline must be struct, pointer to struct, map[string]*:%q", render(pass.Fset, field.Tag))
		}
		if bsonTag.MinSize && !isBsonMinSizeable(pass.TypesInfo.TypeOf(field.Type)) {
			pass.Reportf(field.Tag.Pos(), "minsize must be int64, uint64, uintptr:%q", render(pass.Fset, field.Tag))
		}

	}),
}
View Source
var JsonNameAnalyzer = analysis.Analyzer{
	Name: "jsontaglint",
	Doc:  "report unused json tag",
	Run: runTagChecker("json", func(pass *analysis.Pass, f *ast.Field, tag string) {
		jsonTag := ParseJsonTag(tag)
		if jsonTag.Skip {
			return
		}

		if !isValidTag(jsonTag.Name) {
			pass.Reportf(f.Tag.Pos(), "invalid name:%q", render(pass.Fset, f.Tag))
		}

		if jsonTag.String {
			if !isStringable(pass.TypesInfo.TypeOf(f.Type)) {
				pass.Report(analysis.Diagnostic{
					Pos:     f.Tag.Pos(),
					End:     f.Tag.End(),
					Message: fmt.Sprintf("string must use on scalar field:%q", render(pass.Fset, f.Tag)),
				})
			}
		}

		if len(f.Names) != 0 && jsonTag.Name == f.Names[0].String() {
			pass.Report(analysis.Diagnostic{
				Pos:     f.Tag.Pos(),
				End:     f.Tag.End(),
				Message: fmt.Sprintf("same json tag name %q", render(pass.Fset, f.Tag)),
			})
		}
	}),
}

Functions

This section is empty.

Types

type BsonTag

type BsonTag struct {
	Name           string
	Skip           bool
	OmitEmpty      bool
	MinSize        bool
	Inline         bool
	InvalidOptions []string
}

func ParseBsonTag

func ParseBsonTag(tag string) BsonTag

type JsonTag

type JsonTag struct {
	Name      string
	String    bool
	OmitEmpty bool
	Skip      bool
}

func ParseJsonTag

func ParseJsonTag(tag string) JsonTag

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL