Skip to content

Commit 3afe183

Browse files
authored
Add custom structfield linter to check struct field names and tags (#3843)
1 parent 55ef859 commit 3afe183

File tree

11 files changed

+668
-275
lines changed

11 files changed

+668
-275
lines changed

.custom-gcl.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: v2.6.1
22
plugins:
33
- module: "github.com/google/go-github/v79/tools/fmtpercentv"
44
path: ./tools/fmtpercentv
5-
- module: "github.com/google/go-github/v79/tools/jsonfieldname"
6-
path: ./tools/jsonfieldname
75
- module: "github.com/google/go-github/v79/tools/sliceofpointers"
86
path: ./tools/sliceofpointers
7+
- module: "github.com/google/go-github/v79/tools/structfield"
8+
path: ./tools/structfield

.golangci.yml

Lines changed: 209 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ linters:
1616
- goheader
1717
- gosec
1818
- intrange
19-
- jsonfieldname
2019
- misspell
2120
- modernize
2221
- musttag
@@ -27,6 +26,7 @@ linters:
2726
- revive
2827
- sliceofpointers
2928
- staticcheck
29+
- structfield
3030
- tparallel
3131
- unconvert
3232
- unparam
@@ -152,12 +152,16 @@ linters:
152152
type: module
153153
description: Reports usage of %d or %s in format strings.
154154
original-url: github.com/google/go-github/v79/tools/fmtpercentv
155-
jsonfieldname:
155+
sliceofpointers:
156+
type: module
157+
description: Reports usage of []*string and slices of structs without pointers.
158+
original-url: github.com/google/go-github/v79/tools/sliceofpointers
159+
structfield:
156160
type: module
157-
description: Reports mismatches between Go field and JSON tag names.
158-
original-url: github.com/google/go-github/v79/tools/jsonfieldname
161+
description: Reports mismatches between Go field and JSON, URL tag names and types.
162+
original-url: github.com/google/go-github/v79/tools/structfield
159163
settings:
160-
allowed-exceptions:
164+
allowed-tag-names:
161165
- ActionsCacheUsageList.RepoCacheUsage # TODO: RepoCacheUsages ?
162166
- AuditEntry.ExternalIdentityNameID
163167
- AuditEntry.Timestamp
@@ -186,6 +190,8 @@ linters:
186190
- ListCheckSuiteResults.Total
187191
- ListCustomDeploymentRuleIntegrationsResponse.AvailableIntegrations
188192
- ListDeploymentProtectionRuleResponse.ProtectionRules
193+
- ListIDPGroupsOptions.Query
194+
- ListProjectsOptions.Query
189195
- OrganizationCustomRepoRoles.CustomRepoRoles # TODO: CustomRoles
190196
- OrganizationCustomRoles.CustomRepoRoles # TODO: Roles
191197
- PreReceiveHook.ConfigURL
@@ -219,10 +225,201 @@ linters:
219225
- WeeklyStats.Commits
220226
- WeeklyStats.Deletions
221227
- WeeklyStats.Week
222-
sliceofpointers:
223-
type: module
224-
description: Reports usage of []*string and slices of structs without pointers.
225-
original-url: github.com/google/go-github/v79/tools/sliceofpointers
228+
allowed-tag-types:
229+
- ActivityListStarredOptions.Direction # TODO: Activities
230+
- ActivityListStarredOptions.Sort # TODO: Activities
231+
- AddProjectItemOptions.ID # TODO: Projects
232+
- AddProjectItemOptions.Type # TODO: Projects
233+
- AlertInstancesListOptions.Ref # TODO: CodeScanning
234+
- AlertListOptions.Direction # TODO: CodeScanning
235+
- AlertListOptions.Ref # TODO: CodeScanning
236+
- AlertListOptions.Severity # TODO: CodeScanning
237+
- AlertListOptions.Sort # TODO: CodeScanning
238+
- AlertListOptions.State # TODO: CodeScanning
239+
- AlertListOptions.ToolGUID # TODO: CodeScanning
240+
- AlertListOptions.ToolName # TODO: CodeScanning
241+
- APIMetaArtifactAttestations.TrustDomain # TODO: Meta
242+
- CommitsListOptions.Author # TODO: Repositories
243+
- CommitsListOptions.Path # TODO: Repositories
244+
- CommitsListOptions.SHA # TODO: Repositories
245+
- CommitsListOptions.Since # TODO: Repositories
246+
- CommitsListOptions.Until # TODO: Repositories
247+
- CreateTag.Message # TODO: Git
248+
- CreateTag.Object # TODO: Git
249+
- CreateTag.Tag # TODO: Git
250+
- CreateTag.Type # TODO: Git
251+
- CredentialAuthorizationsListOptions.Login # TODO: Organizations
252+
- DependabotEncryptedSecret.SelectedRepositoryIDs # TODO: Dependabot
253+
- DependabotEncryptedSecret.Visibility # TODO: Dependabot
254+
- DeploymentRequest.RequiredContexts # TODO: Deployments
255+
- DeploymentsListOptions.Environment # TODO: Repositories
256+
- DeploymentsListOptions.Ref # TODO: Repositories
257+
- DeploymentsListOptions.SHA # TODO: Repositories
258+
- DeploymentsListOptions.Task # TODO: Repositories
259+
- DiscussionCommentListOptions.Direction # TODO: Teams
260+
- DiscussionListOptions.Direction # TODO: Teams
261+
- DismissalRestrictionsRequest.Apps # TODO: Repositories
262+
- DismissalRestrictionsRequest.Teams # TODO: Repositories
263+
- DismissalRestrictionsRequest.Users # TODO: Repositories
264+
- EncryptedSecret.SelectedRepositoryIDs # TODO: Actions
265+
- EncryptedSecret.Visibility # TODO: Actions
266+
- ErrorBlock.Reason # TODO: Common
267+
- ErrorResponse.DocumentationURL # TODO: Common
268+
- GetCodeownersErrorsOptions.Ref # TODO: Repositories
269+
- GistListOptions.Since # TODO: Gists
270+
- HostedRunnerRequest.EnableStaticIP # TODO: Actions
271+
- HostedRunnerRequest.Image # TODO: Actions
272+
- HostedRunnerRequest.ImageVersion # TODO: Actions
273+
- HostedRunnerRequest.MaximumRunners # TODO: Actions
274+
- HostedRunnerRequest.Name # TODO: Actions
275+
- HostedRunnerRequest.RunnerGroupID # TODO: Actions
276+
- HostedRunnerRequest.Size # TODO: Actions
277+
- IssueEvent.Action # TODO: Issues
278+
- IssueListByRepoOptions.Assignee # TODO: Issues
279+
- IssueListByRepoOptions.Assignee # TODO: Issues
280+
- IssueListByRepoOptions.Creator # TODO: Issues
281+
- IssueListByRepoOptions.Creator # TODO: Issues
282+
- IssueListByRepoOptions.Direction # TODO: Issues
283+
- IssueListByRepoOptions.Direction # TODO: Issues
284+
- IssueListByRepoOptions.Mentioned # TODO: Issues
285+
- IssueListByRepoOptions.Mentioned # TODO: Issues
286+
- IssueListByRepoOptions.Milestone # TODO: Issues
287+
- IssueListByRepoOptions.Since # TODO: Issues
288+
- IssueListByRepoOptions.Since # TODO: Issues
289+
- IssueListByRepoOptions.Sort # TODO: Issues
290+
- IssueListByRepoOptions.Sort # TODO: Issues
291+
- IssueListByRepoOptions.State # TODO: Issues
292+
- IssueListOptions.Direction # TODO: Issues
293+
- IssueListOptions.Filter # TODO: Issues
294+
- IssueListOptions.Since # TODO: Issues
295+
- IssueListOptions.Sort # TODO: Issues
296+
- IssueListOptions.State # TODO: Issues
297+
- IssueRequest.Assignees # TODO: Issues
298+
- IssueRequest.Labels # TODO: Issues
299+
- License.Conditions # TODO: Licenses
300+
- License.Limitations # TODO: Licenses
301+
- License.Permissions # TODO: Licenses
302+
- ListCodespacesOptions.RepositoryID # TODO: Codespaces
303+
- ListCollaboratorsOptions.Affiliation # TODO: Repositories
304+
- ListCollaboratorsOptions.Permission # TODO: Repositories
305+
- ListContributorsOptions.Anon # TODO: Repositories
306+
- ListCursorOptions.After # TODO: Common
307+
- ListCursorOptions.Before # TODO: Common
308+
- ListCursorOptions.Cursor # TODO: Common
309+
- ListCursorOptions.First # TODO: Common
310+
- ListCursorOptions.Last # TODO: Common
311+
- ListCursorOptions.Page # TODO: Common
312+
- ListCursorOptions.PerPage # TODO: Common
313+
- ListCustomPropertyValuesOptions.RepositoryQuery # TODO: Organizations
314+
- ListEnterpriseRunnerGroupOptions.VisibleToOrganization # TODO: Enterprise
315+
- ListFineGrainedPATOptions.Direction # TODO: Organizations
316+
- ListFineGrainedPATOptions.LastUsedAfter # TODO: Organizations
317+
- ListFineGrainedPATOptions.LastUsedBefore # TODO: Organizations
318+
- ListFineGrainedPATOptions.Permission # TODO: Organizations
319+
- ListFineGrainedPATOptions.Repository # TODO: Organizations
320+
- ListFineGrainedPATOptions.Sort # TODO: Organizations
321+
- ListIDPGroupsOptions.Query # TODO: Teams
322+
- ListMembersOptions.Filter # TODO: Organizations
323+
- ListMembersOptions.Role # TODO: Organizations
324+
- ListOptions.Page # TODO: Common
325+
- ListOptions.PerPage # TODO: Common
326+
- ListOrgMembershipsOptions.State # TODO: Organizations
327+
- ListOrgRunnerGroupOptions.VisibleToRepository # TODO: Actions
328+
- ListOutsideCollaboratorsOptions.Filter # TODO: Organizations
329+
- ListProvisionedSCIMGroupsEnterpriseOptions.Count # TODO: Enterprise
330+
- ListProvisionedSCIMGroupsEnterpriseOptions.ExcludedAttributes # TODO: Enterprise
331+
- ListProvisionedSCIMGroupsEnterpriseOptions.Filter # TODO: Enterprise
332+
- ListProvisionedSCIMGroupsEnterpriseOptions.StartIndex # TODO: Enterprise
333+
- ListReactionOptions.Content # TODO: Reactions
334+
- ListRepositoryActivityOptions.ActivityType # TODO: Repositories
335+
- ListRepositoryActivityOptions.Actor # TODO: Repositories
336+
- ListRepositoryActivityOptions.After # TODO: Repositories
337+
- ListRepositoryActivityOptions.Before # TODO: Repositories
338+
- ListRepositoryActivityOptions.Direction # TODO: Repositories
339+
- ListRepositoryActivityOptions.PerPage # TODO: Repositories
340+
- ListRepositoryActivityOptions.Ref # TODO: Repositories
341+
- ListRepositoryActivityOptions.TimePeriod # TODO: Repositories
342+
- ListRepositorySecurityAdvisoriesOptions.Direction # TODO: SecurityAdvisories
343+
- ListRepositorySecurityAdvisoriesOptions.Direction # TODO: SecurityAdvisories
344+
- ListRepositorySecurityAdvisoriesOptions.Sort # TODO: SecurityAdvisories
345+
- ListRepositorySecurityAdvisoriesOptions.Sort # TODO: SecurityAdvisories
346+
- ListRepositorySecurityAdvisoriesOptions.State # TODO: SecurityAdvisories
347+
- ListRepositorySecurityAdvisoriesOptions.State # TODO: SecurityAdvisories
348+
- ListWorkflowJobsOptions.Filter # TODO: Actions
349+
- ListWorkflowRunsOptions.Actor # TODO: Actions
350+
- ListWorkflowRunsOptions.Branch # TODO: Actions
351+
- ListWorkflowRunsOptions.CheckSuiteID # TODO: Actions
352+
- ListWorkflowRunsOptions.Created # TODO: Actions
353+
- ListWorkflowRunsOptions.Event # TODO: Actions
354+
- ListWorkflowRunsOptions.ExcludePullRequests # TODO: Actions
355+
- ListWorkflowRunsOptions.HeadSHA # TODO: Actions
356+
- ListWorkflowRunsOptions.Status # TODO: Actions
357+
- LockIssueOptions.LockReason # TODO: Issues
358+
- MarketplacePlan.Bullets # TODO: Marketplaces
359+
- MilestoneListOptions.Direction # TODO: Issues
360+
- MilestoneListOptions.Sort # TODO: Issues
361+
- MilestoneListOptions.State # TODO: Issues
362+
- NotificationListOptions.All # TODO: Activities
363+
- NotificationListOptions.Before # TODO: Activities
364+
- NotificationListOptions.Participating # TODO: Activities
365+
- NotificationListOptions.Since # TODO: Activities
366+
- OrganizationsListOptions.Since # TODO: Organizations
367+
- ProjectV2ItemFieldValue.DataType # TODO: Projects
368+
- ProjectV2ItemFieldValue.Name # TODO: Projects
369+
- PullRequestListCommentsOptions.Direction # TODO: PullRequests
370+
- PullRequestListCommentsOptions.Since # TODO: PullRequests
371+
- PullRequestListCommentsOptions.Sort # TODO: PullRequests
372+
- PullRequestListOptions.Base # TODO: PullRequests
373+
- PullRequestListOptions.Direction # TODO: PullRequests
374+
- PullRequestListOptions.Head # TODO: PullRequests
375+
- PullRequestListOptions.Sort # TODO: PullRequests
376+
- PullRequestListOptions.State # TODO: PullRequests
377+
- Rate.Resource # TODO: Common
378+
- RepositoryAddCollaboratorOptions.Permission # TODO: Repositories
379+
- RepositoryContentGetOptions.Ref # TODO: Repositories
380+
- RepositoryCreateForkOptions.DefaultBranchOnly # TODO: Repositories
381+
- RepositoryCreateForkOptions.Name # TODO: Repositories
382+
- RepositoryCreateForkOptions.Organization # TODO: Repositories
383+
- RepositoryListAllOptions.Since # TODO: Repositories
384+
- RepositoryListByAuthenticatedUserOptions.Affiliation # TODO: Repositories
385+
- RepositoryListByAuthenticatedUserOptions.Direction # TODO: Repositories
386+
- RepositoryListByAuthenticatedUserOptions.Sort # TODO: Repositories
387+
- RepositoryListByAuthenticatedUserOptions.Type # TODO: Repositories
388+
- RepositoryListByAuthenticatedUserOptions.Visibility # TODO: Repositories
389+
- RepositoryListByOrgOptions.Direction # TODO: Repositories
390+
- RepositoryListByOrgOptions.Sort # TODO: Repositories
391+
- RepositoryListByOrgOptions.Type # TODO: Repositories
392+
- RepositoryListByUserOptions.Direction # TODO: Repositories
393+
- RepositoryListByUserOptions.Sort # TODO: Repositories
394+
- RepositoryListByUserOptions.Type # TODO: Repositories
395+
- RepositoryListForksOptions.Sort # TODO: Repositories
396+
- RepositoryListOptions.Affiliation # TODO: Repositories
397+
- RepositoryListOptions.Direction # TODO: Repositories
398+
- RepositoryListOptions.Sort # TODO: Repositories
399+
- RepositoryListOptions.Type # TODO: Repositories
400+
- RepositoryListOptions.Visibility # TODO: Repositories
401+
- RequiredStatusChecks.Checks # TODO: Repositories
402+
- RequiredStatusChecks.Contexts # TODO: Repositories
403+
- SearchOptions.Order # TODO: Search
404+
- SearchOptions.Sort # TODO: Search
405+
- Secret.SelectedRepositoriesURL # TODO: Actions
406+
- Secret.Visibility # TODO: Actions
407+
- SecretScanningAlertListOptions.Direction # TODO: SecretScanning
408+
- SecretScanningAlertListOptions.IsMultiRepo # TODO: SecretScanning
409+
- SecretScanningAlertListOptions.IsPubliclyLeaked # TODO: SecretScanning
410+
- SecretScanningAlertListOptions.Resolution # TODO: SecretScanning
411+
- SecretScanningAlertListOptions.SecretType # TODO: SecretScanning
412+
- SecretScanningAlertListOptions.Sort # TODO: SecretScanning
413+
- SecretScanningAlertListOptions.State # TODO: SecretScanning
414+
- SecretScanningAlertListOptions.Validity # TODO: SecretScanning
415+
- TeamAddTeamMembershipOptions.Role # TODO: Teams
416+
- TeamAddTeamRepoOptions.Permission # TODO: Teams
417+
- TeamListTeamMembersOptions.Role # TODO: Teams
418+
- TrafficBreakdownOptions.Per # TODO: Repositories
419+
- UpdateRuleParameters.UpdateAllowsFetchAndMerge # TODO: Rules
420+
- UploadOptions.Label # TODO: Repositories
421+
- UploadOptions.Name # TODO: Repositories
422+
- UserListOptions.Since # TODO: Users
226423
exclusions:
227424
rules:
228425
- linters:
@@ -258,6 +455,9 @@ linters:
258455
# Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10).
259456
- linters: [perfsprint]
260457
text: fmt.Sprint.* can be replaced with faster strconv.FormatInt
458+
issues:
459+
max-issues-per-linter: 0
460+
max-same-issues: 0
261461
formatters:
262462
enable:
263463
- gci

0 commit comments

Comments
 (0)