Add API param linter (#44045)
Adds a linter to ensure we don't add new instances of `team` or `query`
in API params. This will be used incrementally, but this PR also adds
`nolint` directives to places that still have these terms, both to avoid
false-positives later and to help with full migration away from these
terms in in Fleet 5.
Example:
```
server/fleet/campaigns.go:51:16: json tag "team_id": uses deprecated "team"/"teams" — use "fleet"/"fleets" instead (apiparamcheck)
Team *uint `json:"team_id,omitempty"`
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added a new static analyzer (apiparamcheck) to flag deprecated API
parameter names ("team/teams") and improper usages of "query/queries".
* **Chores**
* Integrated the new check into CI tooling and configuration.
* Added analyzer tests and plugin registration.
* Applied targeted lint-suppression annotations across code and tests
where legacy parameter names must remain.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
0f94afe29b
commit
4daed869ad
@@ -407,7 +407,7 @@ func TestDuplicateJSONKeysWithEncoder(t *testing.T) {
|
||||
}
|
||||
|
||||
type response struct {
|
||||
TeamID int `json:"team_id"`
|
||||
TeamID int `json:"team_id"` //nolint:apiparamcheck // rename handled centrally by spec.DeprecatedGitOpsKeyMappings
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ func TestJSONKeyRewriteReader_WithJSONDecoderOldKey(t *testing.T) {
|
||||
rewriter := NewJSONKeyRewriteReader(strings.NewReader(input), rules)
|
||||
|
||||
type request struct {
|
||||
TeamID int `json:"team_id"`
|
||||
TeamID int `json:"team_id"` //nolint:apiparamcheck // rename handled centrally by spec.DeprecatedGitOpsKeyMappings
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var req request
|
||||
@@ -356,7 +356,7 @@ func TestJSONKeyRewriteReader_WithJSONDecoderNewKey(t *testing.T) {
|
||||
rewriter := NewJSONKeyRewriteReader(strings.NewReader(input), rules)
|
||||
|
||||
type request struct {
|
||||
TeamID int `json:"team_id"`
|
||||
TeamID int `json:"team_id"` //nolint:apiparamcheck // rename handled centrally by spec.DeprecatedGitOpsKeyMappings
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var req request
|
||||
@@ -374,7 +374,7 @@ func TestJSONKeyRewriteReader_AliasConflictWithJSONDecoder(t *testing.T) {
|
||||
rewriter := NewJSONKeyRewriteReader(strings.NewReader(input), rules)
|
||||
|
||||
type request struct {
|
||||
TeamID int `json:"team_id"`
|
||||
TeamID int `json:"team_id"` //nolint:apiparamcheck // rename handled centrally by spec.DeprecatedGitOpsKeyMappings
|
||||
}
|
||||
var req request
|
||||
err := json.NewDecoder(rewriter).Decode(&req)
|
||||
|
||||
Reference in New Issue
Block a user