Skip to content

Commit

Permalink
golangci-lint: enable stylecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Dec 26, 2021
1 parent 42588a9 commit 177601d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 50 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ linters:
- "rowserrcheck"
- "staticcheck"
- "structcheck"
- "stylecheck"
- "typecheck"
- "unused"
- "varcheck"
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/common/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ValidateUpdatesToWrite(updates []*v1.RelationshipUpdate) error {

if update.Relationship.Subject.Object.ObjectId == tuple.PublicWildcard && update.Relationship.Subject.OptionalRelation != "" {
return fmt.Errorf(
"Attempt to write a wildcard relationship (`%s`) with a non-empty relation. Please report this bug",
"attempt to write a wildcard relationship (`%s`) with a non-empty relation. Please report this bug",
tuple.RelString(update.Relationship),
)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/datastore/memdb/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (mds *memdbDatastore) WriteNamespace(

if foundRaw != nil {
// Mark the old one as deleted
var toDelete namespace = *(foundRaw.(*namespace))
toDelete := *(foundRaw.(*namespace))
toDelete.deletedTxn = newVersion
if err := txn.Insert(tableNamespace, &toDelete); err != nil {
return datastore.NoRevision, fmt.Errorf(errUnableToWriteConfig, err)
Expand Down Expand Up @@ -144,7 +144,7 @@ func (mds *memdbDatastore) DeleteNamespace(ctx context.Context, nsName string) (
// Mark the namespace as deleted
time.Sleep(mds.simulatedLatency)

var markedDeleted namespace = *found
markedDeleted := *found
markedDeleted.deletedTxn = newChangelogID
err = txn.Insert(tableNamespace, &markedDeleted)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/services/dispatch/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/authzed/spicedb/internal/dispatch"
dispatch_v1 "github.com/authzed/spicedb/internal/services/dispatch/v1"
v1svc "github.com/authzed/spicedb/internal/services/dispatch/v1"
)

// RegisterGrpcServices registers an internal dispatch service with the specified server.
Expand All @@ -18,7 +17,7 @@ func RegisterGrpcServices(
) {
healthSrv := grpcutil.NewAuthlessHealthServer()
healthSrv.SetServicesHealthy(
v1svc.RegisterDispatchServer(srv, dispatch_v1.NewDispatchServer(d)),
dispatch_v1.RegisterDispatchServer(srv, dispatch_v1.NewDispatchServer(d)),
)
healthpb.RegisterHealthServer(srv, healthSrv)
reflection.Register(srv)
Expand Down
3 changes: 1 addition & 2 deletions internal/services/v0/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/authzed/spicedb/internal/datastore/memdb"
"github.com/authzed/spicedb/internal/dispatch/graph"
"github.com/authzed/spicedb/internal/namespace"
"github.com/authzed/spicedb/internal/testfixtures"
tf "github.com/authzed/spicedb/internal/testfixtures"
g "github.com/authzed/spicedb/pkg/graph"
ns "github.com/authzed/spicedb/pkg/namespace"
Expand Down Expand Up @@ -876,7 +875,7 @@ func newACLServicer(

dispatch := graph.NewLocalOnlyDispatcher(ns, ds)
lis := bufconn.Listen(1024 * 1024)
s := testfixtures.NewTestServer()
s := tf.NewTestServer()
v0.RegisterACLServiceServer(s, NewACLServer(ds, ns, dispatch, 50))
go func() {
if err := s.Serve(lis); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/membership/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func populateFoundSubjects(foundSubjectsMap map[string]FoundSubject, rootONR *v0

case v0.SetOperationUserset_INTERSECTION:
if len(typed.IntermediateNode.ChildNodes) == 0 {
return fmt.Errorf("Found intersection with no children")
return fmt.Errorf("found intersection with no children")
}

fsm := map[string]FoundSubject{}
Expand All @@ -139,7 +139,7 @@ func populateFoundSubjects(foundSubjectsMap map[string]FoundSubject, rootONR *v0

case v0.SetOperationUserset_EXCLUSION:
if len(typed.IntermediateNode.ChildNodes) == 0 {
return fmt.Errorf("Found exclusion with no children")
return fmt.Errorf("found exclusion with no children")
}

fsm := map[string]FoundSubject{}
Expand Down
60 changes: 30 additions & 30 deletions pkg/schemadsl/generator/generator_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,63 @@ type sourceGenerator struct {

// ensureBlankLineOrNewScope ensures that there is a blank line or new scope at the tail of the buffer. If not,
// a new line is added.
func (sf *sourceGenerator) ensureBlankLineOrNewScope() {
if !sf.hasBlankline && !sf.hasNewScope {
sf.appendLine()
func (sg *sourceGenerator) ensureBlankLineOrNewScope() {
if !sg.hasBlankline && !sg.hasNewScope {
sg.appendLine()
}
}

// indent increases the current indentation.
func (sf *sourceGenerator) indent() {
sf.indentationLevel = sf.indentationLevel + 1
func (sg *sourceGenerator) indent() {
sg.indentationLevel = sg.indentationLevel + 1
}

// dedent decreases the current indentation.
func (sf *sourceGenerator) dedent() {
sf.indentationLevel = sf.indentationLevel - 1
func (sg *sourceGenerator) dedent() {
sg.indentationLevel = sg.indentationLevel - 1
}

// appendIssue adds an issue found in generation.
func (sf *sourceGenerator) appendIssue(description string) {
sf.append("/* ")
sf.append(description)
sf.append(" */")
sf.hasIssue = true
func (sg *sourceGenerator) appendIssue(description string) {
sg.append("/* ")
sg.append(description)
sg.append(" */")
sg.hasIssue = true
}

// append adds the given value to the buffer, indenting as necessary.
func (sf *sourceGenerator) append(value string) {
func (sg *sourceGenerator) append(value string) {
for _, currentRune := range value {
if currentRune == '\n' {
if sf.hasNewline {
sf.hasBlankline = true
if sg.hasNewline {
sg.hasBlankline = true
}

sf.buf.WriteRune('\n')
sf.hasNewline = true
sf.existingLineLength = 0
sg.buf.WriteRune('\n')
sg.hasNewline = true
sg.existingLineLength = 0
continue
}

sf.hasBlankline = false
sf.hasNewScope = false
sg.hasBlankline = false
sg.hasNewScope = false

if sf.hasNewline {
sf.buf.WriteString(strings.Repeat("\t", sf.indentationLevel))
sf.hasNewline = false
sf.existingLineLength += sf.indentationLevel
if sg.hasNewline {
sg.buf.WriteString(strings.Repeat("\t", sg.indentationLevel))
sg.hasNewline = false
sg.existingLineLength += sg.indentationLevel
}

sf.existingLineLength++
sf.buf.WriteRune(currentRune)
sg.existingLineLength++
sg.buf.WriteRune(currentRune)
}
}

// appendLine adds a newline.
func (sf *sourceGenerator) appendLine() {
sf.append("\n")
func (sg *sourceGenerator) appendLine() {
sg.append("\n")
}

func (sf *sourceGenerator) markNewScope() {
sf.hasNewScope = true
func (sg *sourceGenerator) markNewScope() {
sg.hasNewScope = true
}
6 changes: 3 additions & 3 deletions pkg/schemadsl/input/sourcepositionmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func inclusiveComparator(a, b interface{}) int {
func (spm SourcePositionMapper) RunePositionToLineAndCol(runePosition int) (int, int, error) {
ls, found := spm.rangeTree.Get(inclusiveRange{runePosition, runePosition})
if !found {
return 0, 0, fmt.Errorf("Unknown rune position %v in source file", runePosition)
return 0, 0, fmt.Errorf("unknown rune position %v in source file", runePosition)
}

las := ls.(lineAndStart)
Expand All @@ -84,11 +84,11 @@ func (spm SourcePositionMapper) RunePositionToLineAndCol(runePosition int) (int,
func (spm SourcePositionMapper) LineAndColToRunePosition(lineNumber int, colPosition int) (int, error) {
lineRuneInfo, hasLine := spm.lineMap[lineNumber]
if !hasLine {
return 0, fmt.Errorf("Unknown line %v in source file", lineNumber)
return 0, fmt.Errorf("unknown line %v in source file", lineNumber)
}

if colPosition > lineRuneInfo.end-lineRuneInfo.start {
return 0, fmt.Errorf("Column position %v not found on line %v in source file", colPosition, lineNumber)
return 0, fmt.Errorf("column position %v not found on line %v in source file", colPosition, lineNumber)
}

return lineRuneInfo.start + colPosition, nil
Expand Down
16 changes: 8 additions & 8 deletions pkg/validationfile/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed

parsed, err := ParseValidationFile(fileContents)
if err != nil {
return nil, decimal.Zero, fmt.Errorf("Error when parsing config file %s: %w", filePath, err)
return nil, decimal.Zero, fmt.Errorf("error when parsing config file %s: %w", filePath, err)
}

files = append(files, parsed)
Expand All @@ -60,7 +60,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed
SchemaString: parsed.Schema,
}}, nil)
if err != nil {
return nil, decimal.Zero, fmt.Errorf("Error when parsing schema in config file %s: %w", filePath, err)
return nil, decimal.Zero, fmt.Errorf("error when parsing schema in config file %s: %w", filePath, err)
}

log.Info().Str("filePath", filePath).Int("schemaDefinitionCount", len(defs)).Msg("Loading schema definitions")
Expand All @@ -69,7 +69,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed
log.Info().Str("filePath", filePath).Str("namespaceName", nsDef.Name).Msg("Loading namespace")
_, lnerr := ds.WriteNamespace(context.Background(), nsDef)
if lnerr != nil {
return nil, decimal.Zero, fmt.Errorf("Error when loading namespace config #%v from file %s: %w", index, filePath, lnerr)
return nil, decimal.Zero, fmt.Errorf("error when loading namespace config #%v from file %s: %w", index, filePath, lnerr)
}
}
}
Expand All @@ -80,14 +80,14 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed
nsDef := v0.NamespaceDefinition{}
nerr := prototext.Unmarshal([]byte(namespaceConfig), &nsDef)
if nerr != nil {
return nil, decimal.Zero, fmt.Errorf("Error when parsing namespace config #%v from file %s: %w", index, filePath, nerr)
return nil, decimal.Zero, fmt.Errorf("error when parsing namespace config #%v from file %s: %w", index, filePath, nerr)
}
nsDefs = append(nsDefs, &nsDef)

log.Info().Str("filePath", filePath).Str("namespaceName", nsDef.Name).Msg("Loading namespace")
_, lnerr := ds.WriteNamespace(context.Background(), &nsDef)
if lnerr != nil {
return nil, decimal.Zero, fmt.Errorf("Error when loading namespace config #%v from file %s: %w", index, filePath, lnerr)
return nil, decimal.Zero, fmt.Errorf("error when loading namespace config #%v from file %s: %w", index, filePath, lnerr)
}
}

Expand All @@ -106,7 +106,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed

tpl := tuple.Parse(trimmed)
if tpl == nil {
return nil, decimal.Zero, fmt.Errorf("Error parsing relationship #%v: %s", index, trimmed)
return nil, decimal.Zero, fmt.Errorf("error parsing relationship #%v: %s", index, trimmed)
}

_, ok := seenTuples[tuple.String(tpl)]
Expand All @@ -127,7 +127,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed
for index, validationTuple := range parsed.ValidationTuples {
tpl := tuple.Parse(validationTuple)
if tpl == nil {
return nil, decimal.Zero, fmt.Errorf("Error parsing validation tuple #%v: %s", index, validationTuple)
return nil, decimal.Zero, fmt.Errorf("error parsing validation tuple #%v: %s", index, validationTuple)
}

_, ok := seenTuples[tuple.String(tpl)]
Expand All @@ -145,7 +145,7 @@ func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsed

wrevision, terr := ds.WriteTuples(context.Background(), nil, updates)
if terr != nil {
return nil, decimal.Zero, fmt.Errorf("Error when loading validation tuples from file %s: %w", filePath, terr)
return nil, decimal.Zero, fmt.Errorf("error when loading validation tuples from file %s: %w", filePath, terr)
}

revision = wrevision
Expand Down

0 comments on commit 177601d

Please sign in to comment.