Skip to content

Commit

Permalink
Merge pull request #933 from stacklok/exhaustive-switch
Browse files Browse the repository at this point in the history
golangci-lint: Turn on `exhaustive` linter
  • Loading branch information
JAORMX authored Sep 12, 2023
2 parents fcb94e3 + 5800a5e commit 05c54fd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ linters:
disable-all: true
enable:
- lll
- exhaustive
- goconst
- gocyclo
- gofmt
Expand Down
4 changes: 4 additions & 0 deletions cmd/dev/app/rule_type/rule_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func readEntityFromFile(fpath string, entType pb.Entity) (protoreflect.ProtoMess
out = &pb.VersionedArtifact{}
case pb.Entity_ENTITY_PULL_REQUESTS:
out = &pb.PullRequest{}
case pb.Entity_ENTITY_BUILD_ENVIRONMENTS:
return nil, fmt.Errorf("build environments not yet supported")
case pb.Entity_ENTITY_UNSPECIFIED:
return nil, fmt.Errorf("entity type unspecified")
default:
return nil, fmt.Errorf("unknown entity type: %s", entType)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/engine/entity_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func pbEntityTypeToString(t pb.Entity) (string, error) {
return VersionedArtifactEventEntityType, nil
case pb.Entity_ENTITY_PULL_REQUESTS:
return PullRequestEventEntityType, nil
case pb.Entity_ENTITY_BUILD_ENVIRONMENTS:
return "", fmt.Errorf("build environments not yet supported")
case pb.Entity_ENTITY_UNSPECIFIED:
return "", fmt.Errorf("entity type unspecified")
default:
return "", fmt.Errorf("unknown entity type: %s", t.String())
}
Expand Down
3 changes: 3 additions & 0 deletions internal/engine/eval/vulncheck/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func pbEcosystemAsString(ecosystem pb.DepEcosystem) string {
switch ecosystem {
case pb.DepEcosystem_DEP_ECOSYSTEM_NPM:
return "npm"
case pb.DepEcosystem_DEP_ECOSYSTEM_UNSPECIFIED:
// this shouldn't happen
return ""
default:
return ""
}
Expand Down
2 changes: 2 additions & 0 deletions internal/engine/ingester/diff/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func newEcosystemParser(eco DependencyEcosystem) ecosystemParser {
switch eco {
case DepEcosystemNPM:
return npmParse
case DepEcosystemNone:
return nil
default:
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions internal/engine/pipeline_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func GetRulesForEntity(p *pb.PipelinePolicy, entity pb.Entity) ([]*pb.PipelinePo
return p.Artifact, nil
case pb.Entity_ENTITY_PULL_REQUESTS:
return p.PullRequest, nil
case pb.Entity_ENTITY_UNSPECIFIED:
return nil, fmt.Errorf("entity type unspecified")
default:
return nil, fmt.Errorf("unknown entity: %s", entity)
}
Expand Down Expand Up @@ -339,6 +341,9 @@ func rowInfoToPolicyMap(
policy.Artifact = ruleset
case pb.Entity_ENTITY_PULL_REQUESTS:
policy.PullRequest = ruleset
case pb.Entity_ENTITY_UNSPECIFIED:
// This shouldn't happen
log.Printf("unknown entity found in database: %s", entity)
}

return policy
Expand Down
5 changes: 1 addition & 4 deletions pkg/controlplane/handlers_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,7 @@ func getRuleEvalEntityInfo(
return entityInfo
}

// linter complaints that switches with one-case are bad, but I think that a switch is more extensible for future
// nolint:revive
switch entityType.Entities {
case db.EntitiesArtifact:
if entityType.Entities == db.EntitiesArtifact {
artifact, err := store.GetArtifactByID(ctx, selector.Int32)
if err != nil {
log.Printf("error getting artifact: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func IsValidEntity(entity pb.Entity) bool {
case pb.Entity_ENTITY_REPOSITORIES, pb.Entity_ENTITY_BUILD_ENVIRONMENTS,
pb.Entity_ENTITY_ARTIFACTS, pb.Entity_ENTITY_PULL_REQUESTS:
return true
case pb.Entity_ENTITY_UNSPECIFIED:
return false
}
return false
}
Expand Down Expand Up @@ -130,6 +132,8 @@ func EntityTypeToDB(entity pb.Entity) db.Entities {
dbEnt = db.EntitiesArtifact
case pb.Entity_ENTITY_PULL_REQUESTS:
dbEnt = db.EntitiesPullRequest
case pb.Entity_ENTITY_UNSPECIFIED:
// This shouldn't happen
}

return dbEnt
Expand Down

0 comments on commit 05c54fd

Please sign in to comment.