Add custom structfield linter to check struct field names and tags by alexandear · Pull Request #3843 · google/go-github
This PR renames jsonfieldname linter to structfield and extends it to check struct tags.
The linter enforces that:
- The tag names for
jsonandurlmatch the struct field name - Fields with
jsonandurltags that includeomitemptymust use pointers types, except for slices, maps,json.RawMessage, andany.
Example output for the ListCursorOptions struct:
| type ListCursorOptions struct { | |
| // For paginated result sets, page of results to retrieve. | |
| Page string `url:"page,omitempty"` | |
| // For paginated result sets, the number of results to include per page. | |
| PerPage int `url:"per_page,omitempty"` |
$ ./script/lint.sh github/github.go:264:7: change the "Page" field type to "*string" in the struct "ListCursorOptions" because its tag uses "omitempty" (structfield) Page string `url:"page,omitempty"` ^ github/github.go:267:10: change the "PerPage" field type to "*int" in the struct "ListCursorOptions" because its tag uses "omitempty" (structfield) PerPage int `url:"per_page,omitempty"` ^ ...
Closes #3775