tagalyzer

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MIT Imports: 6 Imported by: 4

README

tagalyzer

Static analyzer to find missing tags in your Golang structs

This Analyzer follows the Golang standardized way of creating static analyzers based on the package (https://pkg.go.dev/golang.org/x/tools/go/analysis) and is fully compatible with the command go vet

Usage

First install the tool on your machine

$ go get github.com/salihzain/tagalyzer/cmd/tagalyzer

Then run inside your project

$ tagalyzer -tag=json -tag=gorm  ./...

To include embedded fields

$ tagalyzer -checkembedded -tag=json -tag=gorm  ./...

Notes:

You may use any number of tags

./... is a spread operator to pass all the packages in the current directory as command line arguments.

You may also run tagalyzer using go vet as follows

$ go vet -vettool=$(which tagalyzer) -tag json -tag gorm ./...

Example

Suppose we have the following struct in our project:

type User struct {
 Username string `gorm:"primaryKey"`
 Name string `json:"name"`
 Age int
}

then running tagalyzer -tag json -tag gorm ./... will output the following:

path/to/file.go:25:2: field:Username is missing tag:json
path/to/file.go:26:2: field:Name is missing tag:gorm
path/to/file.go:27:2: field:Age is missing tag:json
path/to/file.go:27:2: field:Age is missing tag:gorm

Documentation

Index

Constants

View Source
const (
	TAG_IGNORE_FIELD = `tagalyzer:"-"`
)

Variables

View Source
var (
	Analyzer = &analysis.Analyzer{
		Name: "tagalyzer",
		Doc:  doc,
		Run:  run,
		Requires: []*analysis.Analyzer{
			inspect.Analyzer,
		},
	}
)

Functions

This section is empty.

Types

type Tags

type Tags []string

Tags allow passing multiple values to the same command line flag

func (*Tags) Set

func (t *Tags) Set(newtag string) error

func (*Tags) String

func (t *Tags) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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