Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds extra linting rules #105

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ linters:
- ginkgolinter
- gofmt
- goimports
- gosec
- importas
- misspell
- nestif
- nonamedreturns
- prealloc
- revive
- stylecheck
Expand All @@ -28,8 +30,29 @@ linters-settings:

importas:
alias:
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/util/runtime
alias: utilruntime
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
alias: $1$2
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
- pkg: github.com/operator-framework/rukpak/api/v1alpha1
alias: rukpakv1alpha1
goimports:
local-prefixes: github.com/operator-framework/deppy

issues:
exclude-rules:
- path: "internal/solver/bench_test.go"
text: "G404: Use of weak random number generator"
linters:
- gosec

output:
format: tab
12 changes: 6 additions & 6 deletions internal/solver/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ type TestScopeCounter struct {
inter.S
}

func (c *TestScopeCounter) Test(dst []z.Lit) (result int, out []z.Lit) {
result, out = c.S.Test(dst)
func (c *TestScopeCounter) Test(dst []z.Lit) (int, []z.Lit) {
result, out := c.S.Test(dst)
*c.depth++
return
return result, out
}

func (c *TestScopeCounter) Untest() (result int) {
result = c.S.Untest()
func (c *TestScopeCounter) Untest() int {
result := c.S.Untest()
*c.depth--
return
return result
}

func TestSearch(t *testing.T) {
Expand Down
21 changes: 12 additions & 9 deletions internal/solver/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ const (
// containing only those Variables that were selected for
// installation. If no solution is possible, or if the provided
// Context times out or is cancelled, an error is returned.
func (s *solver) Solve(_ context.Context) (result []deppy.Variable, err error) {
defer func() {
// This likely indicates a bug, so discard whatever
// return values were produced.
if derr := s.litMap.Error(); derr != nil {
result = nil
err = derr
}
}()
ncdc marked this conversation as resolved.
Show resolved Hide resolved
func (s *solver) Solve(_ context.Context) ([]deppy.Variable, error) {
result, err := s.solve()

// This likely indicates a bug, so discard whatever
// return values were produced.
if derr := s.litMap.Error(); derr != nil {
return nil, derr
}

return result, err
}

func (s *solver) solve() ([]deppy.Variable, error) {
// teach all constraints to the solver
s.litMap.AddConstraints(s.g)

Expand Down
9 changes: 6 additions & 3 deletions pkg/deppy/input/cache_entity_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func (c CacheEntitySource) Get(_ context.Context, id deppy.Identifier) (*Entity,

func (c CacheEntitySource) Filter(_ context.Context, filter Predicate) (EntityList, error) {
resultSet := EntityList{}
for _, entity := range c.entities {
for i := range c.entities {
entity := c.entities[i]
if filter(&entity) {
resultSet = append(resultSet, entity)
}
Expand All @@ -39,7 +40,8 @@ func (c CacheEntitySource) Filter(_ context.Context, filter Predicate) (EntityLi

func (c CacheEntitySource) GroupBy(_ context.Context, fn GroupByFunction) (EntityListMap, error) {
resultSet := EntityListMap{}
for _, entity := range c.entities {
for i := range c.entities {
entity := c.entities[i]
keys := fn(&entity)
for _, key := range keys {
resultSet[key] = append(resultSet[key], entity)
Expand All @@ -49,7 +51,8 @@ func (c CacheEntitySource) GroupBy(_ context.Context, fn GroupByFunction) (Entit
}

func (c CacheEntitySource) Iterate(_ context.Context, fn IteratorFunction) error {
for _, entity := range c.entities {
for i := range c.entities {
entity := c.entities[i]
if err := fn(&entity); err != nil {
return err
}
Expand Down