Skip to content

Commit d69610a

Browse files
authored
Update jsonfieldname linter to support $ in json tag names (#3826)
1 parent e6f325b commit d69610a

File tree

4 files changed

+4
-1
lines changed

4 files changed

+4
-1
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ linters:
202202
- RepositoriesSearchResult.Repositories
203203
- RepositoriesSearchResult.Total
204204
- RepositoryVulnerabilityAlert.GitHubSecurityAdvisoryID
205-
- SCIMDisplayReference.Ref
206205
- SecretScanningAlertLocationDetails.Startline # TODO: StartLine
207206
- SecretScanningPatternOverride.Bypassrate # TODO: BypassRate
208207
- StarredRepository.Repository # TODO: Repo

tools/jsonfieldname/jsonfieldname.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ func checkGoFieldName(structName, goFieldName, jsonTagName string, tokenPos toke
134134
}
135135

136136
func splitJSONTag(jsonTagName string) []string {
137+
jsonTagName = strings.TrimPrefix(jsonTagName, "$")
138+
137139
if strings.Contains(jsonTagName, "_") {
138140
return strings.Split(jsonTagName, "_")
139141
}

tools/jsonfieldname/testdata/src/has-warnings/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ type Example struct {
1010
Id string `json:"id,omitempty"` // want `change Go field name "Id" to "ID" for JSON tag "id" in struct "Example"`
1111
strings string `json:"strings,omitempty"` // want `change Go field name "strings" to "Strings" for JSON tag "strings" in struct "Example"`
1212
camelcaseexample *int `json:"camelCaseExample,omitempty"` // want `change Go field name "camelcaseexample" to "CamelCaseExample" for JSON tag "camelCaseExample" in struct "Example"`
13+
DollarRef string `json:"$ref"` // want `change Go field name "DollarRef" to "Ref" for JSON tag "\$ref" in struct "Example"`
1314
}

tools/jsonfieldname/testdata/src/no-warnings/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ type Example struct {
99
GithubThing string `json:"github_thing"` // Should not be flagged
1010
ID string `json:"id,omitempty"` // Should not be flagged
1111
Strings string `json:"strings,omitempty"` // Should not be flagged
12+
Ref string `json:"$ref,omitempty"` // Should not be flagged
1213
}

0 commit comments

Comments
 (0)