wayneashleyberry / jsonstructlint

An opinionated linter for json struct tags in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An opinionated linter for json struct tags in Go

Go Go Report Card

This linter is based on a post by Fatih Arslan, which is a fantastic read and highly recommended.

Rules

  • json struct tags must be lower camel case eg. camelCase
  • json struct tags must not contain whitespace
  • json struct tags must exist on all fields, if they exist on one

Example

go get -u github.com/wayneashleyberry/jsonstructlint
jsonstructlint ./...
test_data/testdata.go:14:2: `x_y` is not camelcase
test_data/testdata.go:16:2: `foo bar` contains whitespace
test_data/testdata.go:17:2: `TitleCase` is not camelcase
test_data/testdata.go:18:2: `a b` contains whitespace
test_data/testdata.go:25:3: `Inline Struct` contains whitespace
test_data/testdata.go:25:3: `Inline Struct` is not camelcase
test_data/testdata.go:30:4: `Super Inline` contains whitespace
test_data/testdata.go:30:4: `Super Inline` is not camelcase
test_data/testdata.go:40:4: `FileName` is not camelcase
test_data/testdata.go:12:2: `F2` is missing a json tag
test_data/testdata.go:13:2: `F3` is missing a json tag
test_data/testdata.go:41:4: `MissingStructTag` is missing a json tag

Editor Config

This linter checks that code conforms to the following vscode config:

"go.addTags": {
  "tags": "json",
  "options": "json=omitempty",
  "promptForTags": false,
  "transform": "camelcase"
}

About

An opinionated linter for json struct tags in Go

License:MIT License


Languages

Language:Go 100.0%