Skip to content

Conversation

@alexandear
Copy link
Contributor

This PR renames jsonfieldname linter to structfield and extends it to check struct tags.

The linter enforces that:

  • The tag names for json and url match the struct field name
  • Fields with json and url tags that include omitempty must use pointers types, except for slices, maps, json.RawMessage, and any.

Example output for the ListCursorOptions struct:

go-github/github/github.go

Lines 262 to 267 in 671b8b0

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

@alexandear alexandear force-pushed the chore/structfield-linter branch from fd07588 to e7e528b Compare November 24, 2025 16:54
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.42%. Comparing base (903265b) to head (e83e366).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3843   +/-   ##
=======================================
  Coverage   92.41%   92.42%           
=======================================
  Files         197      197           
  Lines       14152    14167   +15     
=======================================
+ Hits        13079    13094   +15     
  Misses        884      884           
  Partials      189      189           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thank you, @alexandear!
Just a couple questions, really.

@alexandear alexandear requested a review from gmlewis November 25, 2025 16:53
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @alexandear!
LGTM.
Merging.

@gmlewis gmlewis merged commit 3afe183 into google:master Nov 26, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter for detect json:"omitempty" usage with value types

2 participants