Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ifeq ($(WASM_ENABLED),1)
GO_TAGS = -tags=opa_wasm
endif

GOLANGCI_LINT_VERSION := v1.51.0
GOLANGCI_LINT_VERSION := v1.59.1
YAML_LINT_VERSION := 0.29.0
YAML_LINT_FORMAT ?= auto

Expand Down
3 changes: 1 addition & 2 deletions ast/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,8 @@ func (a *AuthorAnnotation) String() string {
return a.Name
} else if len(a.Name) == 0 {
return fmt.Sprintf("<%s>", a.Email)
} else {
return fmt.Sprintf("%s <%s>", a.Name, a.Email)
}
return fmt.Sprintf("%s <%s>", a.Name, a.Email)
}

// Copy returns a deep copy of rr.
Expand Down
4 changes: 2 additions & 2 deletions ast/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ func TestRemoteSchema(t *testing.T) {
schema := `{"type": "boolean"}`

schemaCalled := false
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
schemaCalled = true
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(schema))
Expand Down Expand Up @@ -2477,7 +2477,7 @@ func TestRemoteSchemaHostNotAllowed(t *testing.T) {
schema := `{"type": "boolean"}`

schemaCalled := false
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
schemaCalled = true
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(schema))
Expand Down
2 changes: 1 addition & 1 deletion ast/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4194,7 +4194,7 @@ func resolveRefsInRule(globals map[Var]*usedRef, rule *Rule) error {

// Object keys cannot be pattern matched so only walk values.
case *object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(_, v *Term) {
vis.Walk(v)
})

Expand Down
4 changes: 2 additions & 2 deletions ast/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func insertIntoObject(o *types.Object, path Ref, tpe types.Type, env *TypeEnv) (

func (n *typeTreeNode) Leafs() map[*Ref]types.Type {
leafs := map[*Ref]types.Type{}
n.children.Iter(func(k, v util.T) bool {
n.children.Iter(func(_, v util.T) bool {
collectLeafs(v.(*typeTreeNode), nil, leafs)
return false
})
Expand All @@ -485,7 +485,7 @@ func collectLeafs(n *typeTreeNode, path Ref, leafs map[*Ref]types.Type) {
leafs[&nPath] = n.Value()
return
}
n.children.Iter(func(k, v util.T) bool {
n.children.Iter(func(_, v util.T) bool {
collectLeafs(v.(*typeTreeNode), nPath, leafs)
return false
})
Expand Down
2 changes: 1 addition & 1 deletion ast/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (i *baseDocEqIndex) Lookup(resolver ValueResolver) (*IndexResult, error) {
return result, nil
}

func (i *baseDocEqIndex) AllRules(resolver ValueResolver) (*IndexResult, error) {
func (i *baseDocEqIndex) AllRules(_ ValueResolver) (*IndexResult, error) {
tr := newTrieTraversalResult()

// Walk over the rule trie and accumulate _all_ rules
Expand Down
2 changes: 1 addition & 1 deletion ast/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestValueMapIter(t *testing.T) {
a.Put(String("y"), String("bar"))
a.Put(String("z"), String("baz"))
values := []string{}
a.Iter(func(k, v Value) bool {
a.Iter(func(_, v Value) bool {
values = append(values, string(v.(String)))
return false
})
Expand Down
7 changes: 4 additions & 3 deletions ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2430,10 +2430,11 @@ func augmentYamlError(err error, comments []*Comment) error {
return err
}

func unwrapPair(pair map[string]interface{}) (k string, v interface{}) {
for k, v = range pair {
func unwrapPair(pair map[string]interface{}) (string, interface{}) {
for k, v := range pair {
return k, v
}
return
return "", nil
}

var errInvalidSchemaRef = fmt.Errorf("invalid schema reference")
Expand Down
8 changes: 4 additions & 4 deletions ast/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ func filterObject(o Value, filter Value) (Value, error) {
other = v
}

err := iterObj.Iter(func(key *Term, value *Term) error {
err := iterObj.Iter(func(key *Term, _ *Term) error {
if other.Get(key) != nil {
filteredValue, err := filterObject(v.Get(key).Value, filteredObj.Get(key).Value)
if err != nil {
Expand Down Expand Up @@ -3091,12 +3091,12 @@ func unmarshalTermSlice(s []interface{}) ([]*Term, error) {
buf := []*Term{}
for _, x := range s {
if m, ok := x.(map[string]interface{}); ok {
if t, err := unmarshalTerm(m); err == nil {
t, err := unmarshalTerm(m)
if err == nil {
buf = append(buf, t)
continue
} else {
return nil, err
}
return nil, err
}
return nil, fmt.Errorf("ast: unable to unmarshal term")
}
Expand Down
2 changes: 1 addition & 1 deletion ast/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ func TestObjectConcurrentReads(t *testing.T) {
go func() {
defer wg.Done()
var retrieved []*Term
o.Foreach(func(k, v *Term) {
o.Foreach(func(k, _ *Term) {
retrieved = append(retrieved, k)
})
// Check for sortedness of retrieved results.
Expand Down
12 changes: 6 additions & 6 deletions ast/visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ func (vis *GenericVisitor) Walk(x interface{}) {
vis.Walk(x[i])
}
case *object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(k, _ *Term) {
vis.Walk(k)
vis.Walk(x.Get(k))
})
case Object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(k, _ *Term) {
vis.Walk(k)
vis.Walk(x.Get(k))
})
Expand Down Expand Up @@ -492,12 +492,12 @@ func (vis *BeforeAfterVisitor) Walk(x interface{}) {
vis.Walk(x[i])
}
case *object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(k, _ *Term) {
vis.Walk(k)
vis.Walk(x.Get(k))
})
case Object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(k, _ *Term) {
vis.Walk(k)
vis.Walk(x.Get(k))
})
Expand Down Expand Up @@ -579,7 +579,7 @@ func (vis *VarVisitor) Vars() VarSet {
func (vis *VarVisitor) visit(v interface{}) bool {
if vis.params.SkipObjectKeys {
if o, ok := v.(Object); ok {
o.Foreach(func(k, v *Term) {
o.Foreach(func(_, v *Term) {
vis.Walk(v)
})
return true
Expand Down Expand Up @@ -741,7 +741,7 @@ func (vis *VarVisitor) Walk(x interface{}) {
vis.Walk(x[i])
}
case *object:
x.Foreach(func(k, v *Term) {
x.Foreach(func(k, _ *Term) {
vis.Walk(k)
vis.Walk(x.Get(k))
})
Expand Down
6 changes: 3 additions & 3 deletions bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,17 +1191,17 @@ func (b *Bundle) SetRegoVersion(v ast.RegoVersion) {
// If there is no defined version for the given path, the default version def is returned.
// If the version does not correspond to ast.RegoV0 or ast.RegoV1, an error is returned.
func (b *Bundle) RegoVersionForFile(path string, def ast.RegoVersion) (ast.RegoVersion, error) {
if version, err := b.Manifest.numericRegoVersionForFile(path); err != nil {
version, err := b.Manifest.numericRegoVersionForFile(path)
if err != nil {
return def, err
} else if version == nil {
return def, nil
} else if *version == 0 {
return ast.RegoV0, nil
} else if *version == 1 {
return ast.RegoV1, nil
} else {
return def, fmt.Errorf("unknown bundle rego-version %d for file '%s'", *version, path)
}
return def, fmt.Errorf("unknown bundle rego-version %d for file '%s'", *version, path)
}

func (m *Manifest) numericRegoVersionForFile(path string) (*int, error) {
Expand Down
2 changes: 1 addition & 1 deletion bundle/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (d *dirLoader) NextFile() (*Descriptor, error) {
// build a list of all files we will iterate over and read, but only one time
if d.files == nil {
d.files = []string{}
err := filepath.Walk(d.root, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(d.root, func(path string, info os.FileInfo, _ error) error {
if info != nil && info.Mode().IsRegular() {
if d.filter != nil && d.filter(filepath.ToSlash(path), info, getdepth(path, false)) {
return nil
Expand Down
2 changes: 1 addition & 1 deletion bundle/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func TestNewDirectoryLoaderNormalizedRoot(t *testing.T) {
}

func getFilter(pattern string, minDepth int) filter.LoaderFilter {
return func(abspath string, info os.FileInfo, depth int) bool {
return func(_ string, info os.FileInfo, depth int) bool {
match, _ := filepath.Match(pattern, info.Name())
return match && depth >= minDepth
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestGeneratePayload(t *testing.T) {

type CustomSigner struct{}

func (*CustomSigner) GenerateSignedToken(files []FileInfo, sc *SigningConfig, keyID string) (string, error) {
func (*CustomSigner) GenerateSignedToken(_ []FileInfo, _ *SigningConfig, _ string) (string, error) {
return "", nil
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func TestVerifyBundleFile(t *testing.T) {

type CustomVerifier struct{}

func (*CustomVerifier) VerifyBundleSignature(sc SignaturesConfig, bvc *VerificationConfig) (map[string]FileInfo, error) {
func (*CustomVerifier) VerifyBundleSignature(_ SignaturesConfig, _ *VerificationConfig) (map[string]FileInfo, error) {
return map[string]FileInfo{}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestBenchMainErrRunningBenchmark(t *testing.T) {
var buf bytes.Buffer

mockRunner := &mockBenchRunner{}
mockRunner.onRun = func(ctx context.Context, ectx *evalContext, params benchmarkCommandParams, f func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
mockRunner.onRun = func(_ context.Context, _ *evalContext, _ benchmarkCommandParams, _ func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
return testing.BenchmarkResult{}, errors.New("error error error")
}

Expand All @@ -405,7 +405,7 @@ func TestBenchMainWithCount(t *testing.T) {

params.count = 25
actualCount := 0
mockRunner.onRun = func(ctx context.Context, ectx *evalContext, params benchmarkCommandParams, f func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
mockRunner.onRun = func(_ context.Context, _ *evalContext, _ benchmarkCommandParams, _ func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
actualCount++
return testing.BenchmarkResult{}, nil
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestBenchMainWithNegativeCount(t *testing.T) {

params.count = -1
actualCount := 0
mockRunner.onRun = func(ctx context.Context, ectx *evalContext, params benchmarkCommandParams, f func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
mockRunner.onRun = func(_ context.Context, _ *evalContext, _ benchmarkCommandParams, _ func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
actualCount++
return testing.BenchmarkResult{}, nil
}
Expand All @@ -458,7 +458,7 @@ func validateBenchMainPrep(t *testing.T, args []string, params benchmarkCommandP

mockRunner := &mockBenchRunner{}

mockRunner.onRun = func(ctx context.Context, ectx *evalContext, params benchmarkCommandParams, f func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {
mockRunner.onRun = func(ctx context.Context, ectx *evalContext, _ benchmarkCommandParams, _ func(context.Context, ...rego.EvalOption) error) (testing.BenchmarkResult, error) {

// cheat and use the ectx to evalute the query to ensure the input setup on it was valid
r := rego.New(ectx.regoArgs...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ against OPA v0.22.0:
}
return env.CmdFlags.CheckEnvironmentVariables(Cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if err := dobuild(buildParams, args); err != nil {
fmt.Println("error:", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Print the capabilities of a capabilities file
}

`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
RunE: func(*cobra.Command, []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ data.policy.is_admin.
}
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if err := deps(args, params, os.Stdout); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ access.
}
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {

defined, err := eval(args, params, os.Stdout)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ func TestPolicyWithStrictFlag(t *testing.T) {
"test.rego": tc.policy,
}

test.WithTempFS(files, func(path string) {
test.WithTempFS(files, func(_ string) {
params := newEvalCommandParams()
params.strict = true

Expand Down
4 changes: 2 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ specifying the --decision argument and pointing at a specific policy decision,
e.g., opa exec --decision /foo/bar/baz ...`,

Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
params.Paths = args
params.BundlePaths = bundlePaths.v
if err := runExec(params); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ to stdout from the 'fmt' command.

If the '--fail' option is supplied, the 'fmt' command will return a non zero exit
code if a file would be reformatted.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
os.Exit(opaFmt(args))
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type errorWriter struct {
ErrMsg string
}

func (ew errorWriter) Write(p []byte) (n int, err error) {
func (ew errorWriter) Write(_ []byte) (n int, err error) {
return 0, fmt.Errorf(ew.ErrMsg)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func mockRootCmd(writer io.Writer) *cobra.Command {
Use: "opa [opts]",
Short: "test root command",
Long: `test root command`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
return CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
fmt.Fprintf(writer, "%v; %v; %v", rootArgs.IntFlag, rootArgs.StrFlag, rootArgs.BoolFlag)
},
}
Expand All @@ -43,10 +43,10 @@ func mockChildCmd(writer io.Writer) *cobra.Command {
Use: "child [opts]",
Short: "test child command",
Long: `test child command`,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
return CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
fmt.Fprintf(writer, "%v; %v; %v", rootArgs.IntFlag, rootArgs.StrFlag, rootArgs.BoolFlag)
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ by the input location.`,
}
return env.CmdFlags.CheckEnvironmentVariables(cmd)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if err := dofindDefinition(findDefinitionParams, os.Stdin, os.Stdout, args); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
Expand Down Expand Up @@ -111,7 +111,7 @@ func dofindDefinition(params findDefinitionParams, stdin io.Reader, stdout io.Wr
}
b, err = loader.NewFileLoader().
WithSkipBundleVerification(true).
WithFilter(func(abspath string, info os.FileInfo, depth int) bool {
WithFilter(func(_ string, info os.FileInfo, _ int) bool {
// While directories may contain other things of interest for OPA (json, yaml..),
// only .rego will work reliably for the purpose of finding definitions
return strings.HasPrefix(info.Name(), ".rego")
Expand Down
Loading