Skip to content

Commit

Permalink
🐛 use the location from the inital call (#668)
Browse files Browse the repository at this point in the history
I assume we used to find the class definition, and then had to find
those references, with the updated call I can only assume we are getting
the actual usage and the refenece is now finding the places that this is
being called.

---------

Signed-off-by: Shawn Hurley <shawn@hurley.page>
  • Loading branch information
shawn-hurley committed Jul 22, 2024
1 parent 4fdf5e5 commit a24f7ea
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 170 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
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI
}
}

func (p *javaServiceClient) getDependenciesForMaven(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
localRepoPath := getMavenLocalRepoPath(p.mvnSettingsFile)

path := p.findPom()
Expand Down Expand Up @@ -338,7 +338,7 @@ func (p *javaServiceClient) getDependenciesForMaven(ctx context.Context) (map[ur

// getDependenciesForGradle invokes the Gradle wrapper to get the dependency tree and returns all project dependencies
// TODO: what if no wrapper?
func (p *javaServiceClient) getDependenciesForGradle(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
func (p *javaServiceClient) getDependenciesForGradle(_ context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
subprojects, err := p.getGradleSubprojects()
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ func Test_parseMavenDepLines(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lines := strings.Split(tt.mavenOutput, "\n")
deps := []provider.DepDAGItem{}
var err error
p := javaServiceClient{
log: testr.New(t),
Expand All @@ -540,6 +539,7 @@ func Test_parseMavenDepLines(t *testing.T) {
}
// we are not testing dep init here, so ignore error
p.depInit()
var deps []provider.DepDAGItem
if deps, err = p.parseMavenDepLines(lines[1:], "testdata", "pom.xml"); (err != nil) != tt.wantErr {
t.Errorf("parseMavenDepLines() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
Loading

0 comments on commit a24f7ea

Please sign in to comment.