Skip to content

Commit

Permalink
build: Ban extra elses (#366)
Browse files Browse the repository at this point in the history
* Add superfluous-else rule to revive linter

* Remove default revive linter rules

Do not want to enable these now

* Remove extra else from CreateDescriptions

If also inverted as it clarifies that the error is secondary to the continue

* Remove extra else from generate code

* Enable revive linter
  • Loading branch information
AndrewSisley committed Apr 20, 2022
1 parent deb2ffd commit 726d0d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
5 changes: 2 additions & 3 deletions query/graphql/schema/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ func (g *Generator) CreateDescriptions(
if _, exists := desc.GetField(fname); exists {
// lets make sure its an _id field, otherwise
// we might have an error here
if strings.HasSuffix(fname, "_id") {
continue
} else {
if !strings.HasSuffix(fname, "_id") {
return nil, fmt.Errorf("Error: found a duplicate field '%s' for type %s", fname, t.Name())
}
continue
}

fd := client.FieldDescription{
Expand Down
7 changes: 3 additions & 4 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func (g *Generator) expandInputArgument(obj *gql.Object) error {
case *gql.Object:
if _, complete := g.expandedFields[fieldKey]; complete {
continue
} else {
g.expandedFields[fieldKey] = true
}
g.expandedFields[fieldKey] = true

// make sure all the sub fields are expanded first
if err := g.expandInputArgument(t); err != nil {
return err
Expand All @@ -242,9 +242,8 @@ func (g *Generator) expandInputArgument(obj *gql.Object) error {
listType := t.OfType
if _, complete := g.expandedFields[fieldKey]; complete {
continue
} else {
g.expandedFields[fieldKey] = true
}
g.expandedFields[fieldKey] = true

if listObjType, ok := listType.(*gql.Object); ok {
if err := g.expandInputArgument(listObjType); err != nil {
Expand Down
12 changes: 3 additions & 9 deletions tools/configs/golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ linters:
- errcheck
- forbidigo
- lll
- revive
# - wrapcheck
# - errorlint
# - gci
Expand Down Expand Up @@ -653,15 +654,8 @@ linters-settings:
ignore-generated-header: true
severity: warning
rules:
- name: indent-error-flow
severity: warning
- name: add-constant
severity: warning
arguments:
- maxLitCount: "3"
allowStrs: '""'
allowInts: "0,1,2"
allowFloats: "0.0,0.,1.0,1.,2.0,2."
- name: superfluous-else
severity: error

staticcheck:
# Select the Go version to target. The default is '1.13'.
Expand Down

0 comments on commit 726d0d3

Please sign in to comment.