https://github.com/wayneashleyberry/jsonstructlint
An opinionated linter for json struct tags in Go
https://github.com/wayneashleyberry/jsonstructlint
go golang json linter
Last synced: 5 months ago
JSON representation
An opinionated linter for json struct tags in Go
- Host: GitHub
- URL: https://github.com/wayneashleyberry/jsonstructlint
- Owner: wayneashleyberry
- License: mit
- Created: 2018-09-03T11:07:51.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2021-10-25T06:43:21.000Z (over 4 years ago)
- Last Synced: 2024-06-21T17:54:43.122Z (about 2 years ago)
- Topics: go, golang, json, linter
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> An opinionated linter for json struct tags in Go
[](https://github.com/wayneashleyberry/jsonstructlint/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/wayneashleyberry/jsonstructlint)
This linter is based on [a post by Fatih Arslan](https://arslan.io/2019/06/13/using-go-analysis-to-write-a-custom-linter/), 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
```sh
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:
```json
"go.addTags": {
"tags": "json",
"options": "json=omitempty",
"promptForTags": false,
"transform": "camelcase"
}
```