From 3339876a47c97c5a44af1e15bc8d931d540abadf Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:00:02 -0500 Subject: [PATCH 1/2] Support $ in json TAG names Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- tools/jsonfieldname/jsonfieldname.go | 2 ++ tools/jsonfieldname/testdata/src/has-warnings/main.go | 1 + tools/jsonfieldname/testdata/src/no-warnings/main.go | 1 + 3 files changed, 4 insertions(+) diff --git a/tools/jsonfieldname/jsonfieldname.go b/tools/jsonfieldname/jsonfieldname.go index e4c117e3cb6..1de10bc2f8c 100644 --- a/tools/jsonfieldname/jsonfieldname.go +++ b/tools/jsonfieldname/jsonfieldname.go @@ -134,6 +134,8 @@ func checkGoFieldName(structName, goFieldName, jsonTagName string, tokenPos toke } func splitJSONTag(jsonTagName string) []string { + jsonTagName = strings.TrimPrefix(jsonTagName, "$") + if strings.Contains(jsonTagName, "_") { return strings.Split(jsonTagName, "_") } diff --git a/tools/jsonfieldname/testdata/src/has-warnings/main.go b/tools/jsonfieldname/testdata/src/has-warnings/main.go index 04670e20b1d..abc246652f3 100644 --- a/tools/jsonfieldname/testdata/src/has-warnings/main.go +++ b/tools/jsonfieldname/testdata/src/has-warnings/main.go @@ -10,4 +10,5 @@ type Example struct { Id string `json:"id,omitempty"` // want `change Go field name "Id" to "ID" for JSON tag "id" in struct "Example"` strings string `json:"strings,omitempty"` // want `change Go field name "strings" to "Strings" for JSON tag "strings" in struct "Example"` camelcaseexample *int `json:"camelCaseExample,omitempty"` // want `change Go field name "camelcaseexample" to "CamelCaseExample" for JSON tag "camelCaseExample" in struct "Example"` + DollarRef string `json:"$ref"` // want `change Go field name "DollarRef" to "Ref" for JSON tag "$ref" in struct "Example"` } diff --git a/tools/jsonfieldname/testdata/src/no-warnings/main.go b/tools/jsonfieldname/testdata/src/no-warnings/main.go index 73119c771f0..c522c7783ea 100644 --- a/tools/jsonfieldname/testdata/src/no-warnings/main.go +++ b/tools/jsonfieldname/testdata/src/no-warnings/main.go @@ -9,4 +9,5 @@ type Example struct { GithubThing string `json:"github_thing"` // Should not be flagged ID string `json:"id,omitempty"` // Should not be flagged Strings string `json:"strings,omitempty"` // Should not be flagged + Ref string `json:"$ref,omitempty"` // Should not be flagged } From 646573219f4f2eb280373592ae384d55279334f5 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:24:11 -0500 Subject: [PATCH 2/2] Fix tests Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .golangci.yml | 1 - tools/jsonfieldname/testdata/src/has-warnings/main.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c405b15467a..6793bed9135 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -202,7 +202,6 @@ linters: - RepositoriesSearchResult.Repositories - RepositoriesSearchResult.Total - RepositoryVulnerabilityAlert.GitHubSecurityAdvisoryID - - SCIMDisplayReference.Ref - SecretScanningAlertLocationDetails.Startline # TODO: StartLine - SecretScanningPatternOverride.Bypassrate # TODO: BypassRate - StarredRepository.Repository # TODO: Repo diff --git a/tools/jsonfieldname/testdata/src/has-warnings/main.go b/tools/jsonfieldname/testdata/src/has-warnings/main.go index abc246652f3..c1a74c6059a 100644 --- a/tools/jsonfieldname/testdata/src/has-warnings/main.go +++ b/tools/jsonfieldname/testdata/src/has-warnings/main.go @@ -10,5 +10,5 @@ type Example struct { Id string `json:"id,omitempty"` // want `change Go field name "Id" to "ID" for JSON tag "id" in struct "Example"` strings string `json:"strings,omitempty"` // want `change Go field name "strings" to "Strings" for JSON tag "strings" in struct "Example"` camelcaseexample *int `json:"camelCaseExample,omitempty"` // want `change Go field name "camelcaseexample" to "CamelCaseExample" for JSON tag "camelCaseExample" in struct "Example"` - DollarRef string `json:"$ref"` // want `change Go field name "DollarRef" to "Ref" for JSON tag "$ref" in struct "Example"` + DollarRef string `json:"$ref"` // want `change Go field name "DollarRef" to "Ref" for JSON tag "\$ref" in struct "Example"` }