Skip to content

Commit

Permalink
fixup warnings in code
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley committed Jul 22, 2024
1 parent 459fa61 commit f7f82ff
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 65 deletions.
100 changes: 50 additions & 50 deletions engine/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,224 +15,224 @@ func Test_sortConditionEntries(t *testing.T) {
{
title: "correctly sorted conditions should stay sorted",
entries: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
As: "b",
From: "a",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
As: "b",
From: "a",
},
},
}, {
title: "incorrectly sorted conditions should be sorted",
entries: []ConditionEntry{
ConditionEntry{
{
As: "b",
From: "a",
},
ConditionEntry{
{
As: "a",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
As: "b",
From: "a",
},
},
}, {
title: "incorrectly sorted conditions that branch should be sorted",
entries: []ConditionEntry{
ConditionEntry{
{
As: "b",
From: "a",
},
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
As: "c",
From: "b",
},
ConditionEntry{
{
As: "e",
From: "d",
},
ConditionEntry{
{
As: "d",
From: "b",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
As: "b",
From: "a",
},
ConditionEntry{
{
As: "c",
From: "b",
},
ConditionEntry{
{
As: "d",
From: "b",
},
ConditionEntry{
{
As: "e",
From: "d",
},
},
}, {
title: "longer chains should sort properly",
entries: []ConditionEntry{
ConditionEntry{
{
From: "e",
As: "f",
},
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
From: "d",
As: "e",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "c",
As: "d",
},
ConditionEntry{
{
From: "f",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "c",
As: "d",
},
ConditionEntry{
{
From: "d",
As: "e",
},
ConditionEntry{
{
From: "e",
As: "f",
},
ConditionEntry{
{
From: "f",
},
},
}, {
title: "completely reversed chains should sort properly",
entries: []ConditionEntry{
ConditionEntry{
{
From: "c",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
As: "a",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "c",
},
},
}, {
title: "unused As should not cause error",
entries: []ConditionEntry{
ConditionEntry{
{
From: "c",
As: "d",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
As: "a",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
ConditionEntry{
{
From: "a",
As: "b",
},
ConditionEntry{
{
From: "b",
As: "c",
},
ConditionEntry{
{
From: "c",
As: "d",
},
},
}, {
title: "length 1 lists should not cause error",
entries: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
},
expected: []ConditionEntry{
ConditionEntry{
{
As: "a",
},
},
Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func (r *ruleEngine) createViolation(ctx context.Context, conditionResponse Cond
}, nil
}

func (r *ruleEngine) getCodeLocation(ctx context.Context, m IncidentContext, rule Rule) (codeSnip string, err error) {
func (r *ruleEngine) getCodeLocation(_ context.Context, m IncidentContext, rule Rule) (codeSnip string, err error) {
if m.CodeLocation == nil {
r.logger.V(6).Info("unable to get the code snip", "URI", m.FileURI)
return "", nil
Expand Down
2 changes: 1 addition & 1 deletion lsp/protocol/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func init() {
namesTextDocumentSaveReason[int(FocusOut)] = "FocusOut"
}

func formatEnum(f fmt.State, c rune, i int, names []string, unknown string) {
func formatEnum(f fmt.State, _ rune, i int, names []string, unknown string) {
s := ""
if i >= 0 && i < len(names) {
s = names[i]
Expand Down
2 changes: 1 addition & 1 deletion lsp/protocol/tsdocument_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ func (d *DocumentChanges) MarshalJSON() ([]byte, error) {
} else if d.RenameFile != nil {
return json.Marshal(d.RenameFile)
}
return nil, fmt.Errorf("Empty DocumentChanges union value")
return nil, fmt.Errorf("empty DocumentChanges union value")
}
10 changes: 5 additions & 5 deletions parser/rule_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,16 @@ func (r *RuleParser) getConditionForProvider(langProvider, capability string, va

fullCondition, ok := value.(map[interface{}]interface{})
if !ok {
return nil, nil, fmt.Errorf("Unable to parse dependency condition for %s", langProvider)
return nil, nil, fmt.Errorf("unable to parse dependency condition for %s", langProvider)
}
for k, v := range fullCondition {
key, ok := k.(string)
if !ok {
return nil, nil, fmt.Errorf("Unable to parse dependency condition for %s", langProvider)
return nil, nil, fmt.Errorf("unable to parse dependency condition for %s", langProvider)
}
value, ok := v.(string)
if !ok {
return nil, nil, fmt.Errorf("Unable to parse dependency condition for %s", langProvider)
return nil, nil, fmt.Errorf("unable to parse dependency condition for %s", langProvider)
}
switch key {
case "name":
Expand All @@ -792,11 +792,11 @@ func (r *RuleParser) getConditionForProvider(langProvider, capability string, va

}
if depCondition.Name == "" {
return nil, nil, fmt.Errorf("Unable to parse dependency condition for %s (name is required)", langProvider)
return nil, nil, fmt.Errorf("unable to parse dependency condition for %s (name is required)", langProvider)
}

if depCondition.Upperbound == "" && depCondition.Lowerbound == "" {
return nil, nil, fmt.Errorf("Unable to parse dependency condition for %s (one of upperbound or lowerbound is required)", langProvider)
return nil, nil, fmt.Errorf("unable to parse dependency condition for %s (one of upperbound or lowerbound is required)", langProvider)
}

return &depCondition, client, nil
Expand Down
2 changes: 1 addition & 1 deletion parser/rule_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func TestLoadRules(t *testing.T) {
t.Errorf("Got err: %v expected: should have error: %v or message: %v", err, tc.ShouldErr, tc.ErrorMessage)
return
}
if err == nil && tc.ShouldErr {
if tc.ShouldErr {
t.Errorf("expected error but not none")
return
}
Expand Down
4 changes: 4 additions & 0 deletions provider/grpc/dependency_resolver_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (d *dependencyLocationResolverClient) GetLocation(ctx context.Context, dep
},
DepFile: depFile,
})
if err != nil {
// Igonore the error so that some failures just continue processing
return engine.Location{}, nil
}
if res == nil || res.Location == nil {
return engine.Location{}, nil
}
Expand Down
6 changes: 0 additions & 6 deletions provider/internal/builtin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (

const TAGS_FILE_INIT_OPTION = "tagsFile"

var (
filePathsDescription = "file pattern to search"
)

var capabilities = []provider.Capability{}

type builtinCondition struct {
Expand Down Expand Up @@ -57,7 +53,6 @@ type jsonCondition struct {
}

type builtinProvider struct {
ctx context.Context
log logr.Logger

config provider.Config
Expand Down Expand Up @@ -185,5 +180,4 @@ func (p *builtinProvider) Evaluate(ctx context.Context, cap string, conditionInf
}

func (p *builtinProvider) Stop() {
return
}

0 comments on commit f7f82ff

Please sign in to comment.