Skip to content

Commit

Permalink
rename checks
Browse files Browse the repository at this point in the history
Signed-off-by: Holly Gong <[email protected]>
  • Loading branch information
hogo6002 committed Oct 21, 2024
1 parent c0a4f99 commit 889b6bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
21 changes: 0 additions & 21 deletions tools/osv-linter/internal/checks/affected.go

This file was deleted.

4 changes: 2 additions & 2 deletions tools/osv-linter/internal/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var Collections = []CheckCollection{
Name: "ALL",
Description: "all checks currently defined",
Checks: []*CheckDef{
CheckAffectedFieldValid,
CheckRecordHasAffected,
CheckRangeHasIntroducedEvent,
CheckRangeIsDistinct,
CheckPackageExists,
Expand All @@ -103,7 +103,7 @@ var Collections = []CheckCollection{
Name: "offline",
Description: "checks that do not have remote data dependencies",
Checks: []*CheckDef{
CheckAffectedFieldValid,
CheckRecordHasAffected,
CheckRangeHasIntroducedEvent,
CheckRangeIsDistinct,
CheckPackagePurlValid,
Expand Down
21 changes: 21 additions & 0 deletions tools/osv-linter/internal/checks/record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package checks

import (
"github.com/tidwall/gjson"
)

var CheckRecordHasAffected = &CheckDef{
Code: "A0001",
Name: "affected-data-exists",
Description: "every record has affected data",
Check: RecordHasAffected,
}

// RecordHasAffected checks if the 'affected' field exists in the JSON and is not an empty array.
func RecordHasAffected(json *gjson.Result, config *Config) (findings []CheckError) {
affectedEntries := json.Get("affected")
if !affectedEntries.Exists() || affectedEntries.String() == "[]" {
findings = append(findings, CheckError{Message: "Invalid Affected: affected filed cannot be null or empty"})
}
return findings
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestAffectedField(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotFindings := AffectedFieldValid(tt.args.json, &Config{Verbose: true})
gotFindings := RecordHasAffected(tt.args.json, &Config{Verbose: true})
if diff := cmp.Diff(tt.wantFindings, gotFindings, cmpopts.EquateErrors()); diff != "" {
t.Errorf("AffectedFieldValid() mismatch (-want +got):\n%s", diff)
t.Errorf("RecordHasAffected() mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down

0 comments on commit 889b6bd

Please sign in to comment.