k3forx / jsonCameler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsonCameler Go Report Card

jsonCameler can be used to check whether JSON tags of structs are written in lowerCamel case. You can skip lint check by adding comment nocaml to the fields of the struct or to the above line of the declaration of the struct.

Installation

go install github.com/k3forx/jsonCameler/cmd/jsonCameler@latest

How to use

go vet -vettool=`which jsonCameler` ./...

Here is an example.

package main

import (
	"time"
)

type User struct {
	ID        int       `json:"id"`
	FirstName string    `json:"firstName"`
	LastName  string    `json:"last-name"` // invalid
	Username  string    `json:"user-name"` // nocamel
	BirthDay  time.Time `json:"-"`
}

// nocamel
type Score struct {
	ID        int
	UserID    int       `json:"user_id"`
	Score     int       `json:"s-co-re"`
	CreatedAt time.Time `json:"created_at" some tags`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

func main() {
	...
}

The result will be like...

go vet -vettool=`which jsonCameler` ./
./main.go:16:2: invalid JSON tag `last-name`

Plugin

go build -buildmode=plugin -o . ./plugin/jsonCameler.go

About

License:MIT License


Languages

Language:Go 100.0%