Skip to content

Commit

Permalink
Fix some minor issues reported by IntelliJ (#1159)
Browse files Browse the repository at this point in the history
Would be good to know why golangci-lint fails to report
these, as some were fairly obvious. But oh well!

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored Oct 2, 2024
1 parent f7acfda commit a55d2f4
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 59 deletions.
6 changes: 3 additions & 3 deletions e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ test_allow {
}

for file, content := range initialState {
mustWriteToFile(t, filepath.Join(td, file), string(content))
mustWriteToFile(t, filepath.Join(td, file), content)
}

// --force is required to make the changes when there is no git repo
Expand Down Expand Up @@ -917,7 +917,7 @@ import rego.v1
}

for file, content := range initialState {
mustWriteToFile(t, filepath.Join(td, file), string(content))
mustWriteToFile(t, filepath.Join(td, file), content)
}

// --force is required to make the changes when there is no git repo
Expand Down Expand Up @@ -989,7 +989,7 @@ import rego.v1
}

for file, content := range initialState {
mustWriteToFile(t, filepath.Join(td, file), string(content))
mustWriteToFile(t, filepath.Join(td, file), content)
}

// --force is required to make the changes when there is no git repo
Expand Down
4 changes: 2 additions & 2 deletions internal/capabilities/capabilities.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package capabilities provides convenient access to OPA capabilities
// Package capabilities provides convenient access to OPA capabilities
// definitions that are embedded within Regal.
package capabilities

Expand All @@ -17,7 +17,7 @@ import (

"github.com/open-policy-agent/opa/ast"

embedded "github.com/styrainc/regal/internal/capabilities/embedded"
"github.com/styrainc/regal/internal/capabilities/embedded"
)

const (
Expand Down
7 changes: 3 additions & 4 deletions internal/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package compile

import (
"github.com/open-policy-agent/opa/ast"
opa_util "github.com/open-policy-agent/opa/util"
opaUtil "github.com/open-policy-agent/opa/util"

"github.com/styrainc/regal/internal/embeds"
"github.com/styrainc/regal/internal/util"
Expand All @@ -26,14 +26,13 @@ func Capabilities() *ast.Capabilities {

func RegalSchemaSet() *ast.SchemaSet {
schemaSet := ast.NewSchemaSet()

astSchema := util.Must(embeds.SchemasFS.ReadFile("schemas/regal-ast.json"))

schemaSet.Put(ast.MustParseRef("schema.regal.ast"), opa_util.MustUnmarshalJSON(astSchema))
schemaSet.Put(ast.MustParseRef("schema.regal.ast"), opaUtil.MustUnmarshalJSON(astSchema))

aggregateSchema := util.Must(embeds.SchemasFS.ReadFile("schemas/aggregate.json"))

schemaSet.Put(ast.MustParseRef("schema.regal.aggregate"), opa_util.MustUnmarshalJSON(aggregateSchema))
schemaSet.Put(ast.MustParseRef("schema.regal.aggregate"), opaUtil.MustUnmarshalJSON(aggregateSchema))

return schemaSet
}
Expand Down
4 changes: 0 additions & 4 deletions internal/embeds/embeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package embeds

import (
"embed"

"github.com/styrainc/regal/bundle"
)

var EmbedBundleFS = bundle.Bundle

//go:embed templates
var EmbedTemplatesFS embed.FS

Expand Down
2 changes: 1 addition & 1 deletion internal/explorer/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type stage struct{ name, metricName string }
// NOTE(sr): copied from 0.68.0.
//
//nolint:gochecknoglobals
var stages []stage = []stage{
var stages = []stage{
{"ResolveRefs", "compile_stage_resolve_refs"},
{"InitLocalVarGen", "compile_stage_init_local_var_gen"},
{"RewriteRuleHeadRefs", "compile_stage_rewrite_rule_head_refs"},
Expand Down
6 changes: 0 additions & 6 deletions internal/lsp/opa/tokens/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,3 @@ func Keywords() map[string]Token {
}
return cpy
}

// IsKeyword returns if a token is a keyword
func IsKeyword(tok Token) bool {
_, ok := keywords[strings[tok]]
return ok
}
22 changes: 0 additions & 22 deletions internal/lsp/server_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lsp

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -36,27 +35,6 @@ const defaultTimeout = 20 * time.Second

const defaultBufferedChannelSize = 5

// InMemoryReadWriteCloser is an in-memory implementation of jsonrpc2.ReadWriteCloser.
type InMemoryReadWriteCloser struct {
Buffer bytes.Buffer
}

func (m *InMemoryReadWriteCloser) Read(p []byte) (int, error) {
c, err := m.Buffer.Read(p)

return c, fmt.Errorf("in memory read failed with error: %w", err)
}

func (m *InMemoryReadWriteCloser) Write(p []byte) (int, error) {
c, err := m.Buffer.Write(p)

return c, fmt.Errorf("in memory write failed with error: %w", err)
}

func (*InMemoryReadWriteCloser) Close() error {
return nil // No-op for in-memory implementation
}

const fileURIScheme = "file://"

// TestLanguageServerSingleFile tests that changes to a single file and Regal config are handled correctly by the
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
package mode

// Standalone lets us change the output of some commands when Regal
// us used as a binary, as opposed to when it's embedded via its
// is used as a binary, as opposed to when it's embedded via its
// Go module.
const Standalone = false
10 changes: 0 additions & 10 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ func Map[T, U any](f func(T) U, a []T) []U {
return b
}

// MapInvert inverts a map (swaps keys and values).
func MapInvert[K comparable, V comparable](m map[K]V) map[V]K {
n := make(map[V]K, len(m))
for k, v := range m {
n[v] = k
}

return n
}

// FindClosestMatchingRoot finds the closest matching root for a given path.
// If no matching root is found, an empty string is returned.
func FindClosestMatchingRoot(path string, roots []string) string {
Expand Down
8 changes: 2 additions & 6 deletions pkg/fixer/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func (r *PrettyReporter) ReportConflicts(fixReport *Report) error {
if len(roots) > 0 {
fmt.Fprintln(r.outputWriter, "Source file conflicts:")

i := 0

for _, rootKey := range roots {
for i, rootKey := range roots {
if i > 0 {
fmt.Fprintln(r.outputWriter)
}
Expand Down Expand Up @@ -90,9 +88,7 @@ func (r *PrettyReporter) ReportConflicts(fixReport *Report) error {

fmt.Fprintln(r.outputWriter, "Many to one conflicts:")

i := 0

for _, rootKey := range roots {
for i, rootKey := range roots {
if i > 0 {
fmt.Fprintln(r.outputWriter)
}
Expand Down

0 comments on commit a55d2f4

Please sign in to comment.