Skip to content

Commit ee2f8c6

Browse files
committed
Fix further go lint ./... warnings
1 parent 9b137fd commit ee2f8c6

File tree

8 files changed

+80
-99
lines changed

8 files changed

+80
-99
lines changed

examples/todo/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ var rootMutation = graphql.NewObject(graphql.ObjectConfig{
7575
text, _ := params.Args["text"].(string)
7676

7777
// figure out new id
78-
newId := RandStringRunes(8)
78+
newID := RandStringRunes(8)
7979

8080
// perform mutation operation here
8181
// for e.g. create a Todo and save to DB.
8282
newTodo := Todo{
83-
ID: newId,
83+
ID: newID,
8484
Text: text,
8585
Done: false,
8686
}

gqlerrors/located.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/graphql-go/graphql/language/ast"
66
)
77

8-
// NewLocatedError
8+
// NewLocatedError creates a graphql.Error with location info
99
// @deprecated 0.4.18
1010
// Already exists in `graphql.NewLocatedError()`
1111
func NewLocatedError(err interface{}, nodes []ast.Node) *Error {

language/lexer/lexer.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func readName(source *source.Source, position int) Token {
121121
code >= 48 && code <= 57 || // 0-9
122122
code >= 65 && code <= 90 || // A-Z
123123
code >= 97 && code <= 122) { // a-z
124-
end += 1
124+
end++
125125
continue
126126
} else {
127127
break
@@ -140,11 +140,11 @@ func readNumber(s *source.Source, start int, firstCode rune) (Token, error) {
140140
position := start
141141
isFloat := false
142142
if code == 45 { // -
143-
position += 1
143+
position++
144144
code = charCodeAt(body, position)
145145
}
146146
if code == 48 { // 0
147-
position += 1
147+
position++
148148
code = charCodeAt(body, position)
149149
if code >= 48 && code <= 57 {
150150
description := fmt.Sprintf("Invalid number, unexpected digit after 0: %v.", printCharCode(code))
@@ -160,7 +160,7 @@ func readNumber(s *source.Source, start int, firstCode rune) (Token, error) {
160160
}
161161
if code == 46 { // .
162162
isFloat = true
163-
position += 1
163+
position++
164164
code = charCodeAt(body, position)
165165
p, err := readDigits(s, position, code)
166166
if err != nil {
@@ -171,10 +171,10 @@ func readNumber(s *source.Source, start int, firstCode rune) (Token, error) {
171171
}
172172
if code == 69 || code == 101 { // E e
173173
isFloat = true
174-
position += 1
174+
position++
175175
code = charCodeAt(body, position)
176176
if code == 43 || code == 45 { // + -
177-
position += 1
177+
position++
178178
code = charCodeAt(body, position)
179179
}
180180
p, err := readDigits(s, position, code)
@@ -198,7 +198,7 @@ func readDigits(s *source.Source, start int, firstCode rune) (int, error) {
198198
if code >= 48 && code <= 57 { // 0 - 9
199199
for {
200200
if code >= 48 && code <= 57 { // 0 - 9
201-
position += 1
201+
position++
202202
code = charCodeAt(body, position)
203203
continue
204204
} else {
@@ -230,7 +230,7 @@ func readString(s *source.Source, start int) (Token, error) {
230230
if code < 0x0020 && code != 0x0009 {
231231
return Token{}, gqlerrors.NewSyntaxError(s, position, fmt.Sprintf(`Invalid character within String: %v.`, printCharCode(code)))
232232
}
233-
position += 1
233+
position++
234234
if code == 92 { // \
235235
value += body[chunkStart : position-1]
236236
code = charCodeAt(body, position)
@@ -278,7 +278,7 @@ func readString(s *source.Source, start int) (Token, error) {
278278
return Token{}, gqlerrors.NewSyntaxError(s, position,
279279
fmt.Sprintf(`Invalid character escape sequence: \\%c.`, code))
280280
}
281-
position += 1
281+
position++
282282
chunkStart = position
283283
}
284284
continue
@@ -313,11 +313,11 @@ func char2hex(a rune) int {
313313
return int(a) - 48
314314
} else if a >= 65 && a <= 70 { // A-F
315315
return int(a) - 55
316-
} else if a >= 97 && a <= 102 { // a-f
316+
} else if a >= 97 && a <= 102 {
317+
// a-f
317318
return int(a) - 87
318-
} else {
319-
return -1
320319
}
320+
return -1
321321
}
322322

323323
func makeToken(kind int, start int, end int, value string) Token {
@@ -409,9 +409,8 @@ func readToken(s *source.Source, fromPosition int) (Token, error) {
409409
token, err := readNumber(s, position, code)
410410
if err != nil {
411411
return token, err
412-
} else {
413-
return token, nil
414412
}
413+
return token, nil
415414
// "
416415
case 34:
417416
token, err := readString(s, position)
@@ -428,9 +427,9 @@ func charCodeAt(body string, position int) rune {
428427
r := []rune(body)
429428
if len(r) > position {
430429
return r[position]
431-
} else {
432-
return -1
433430
}
431+
return -1
432+
434433
}
435434

436435
// Reads from body starting at startPosition until it finds a non-whitespace
@@ -453,16 +452,16 @@ func positionAfterWhitespace(body string, startPosition int) int {
453452
code == 0x000D || // carriage return
454453
// Comma
455454
code == 0x002C {
456-
position += 1
455+
position++
457456
} else if code == 35 { // #
458-
position += 1
457+
position++
459458
for {
460459
code := charCodeAt(body, position)
461460
if position < bodyLength &&
462461
code != 0 &&
463462
// SourceCharacter but not LineTerminator
464463
(code > 0x001F || code == 0x0009) && code != 0x000A && code != 0x000D {
465-
position += 1
464+
position++
466465
continue
467466
} else {
468467
break
@@ -482,9 +481,8 @@ func positionAfterWhitespace(body string, startPosition int) int {
482481
func GetTokenDesc(token Token) string {
483482
if token.Value == "" {
484483
return GetTokenKindDesc(token.Kind)
485-
} else {
486-
return fmt.Sprintf("%s \"%s\"", GetTokenKindDesc(token.Kind), token.Value)
487484
}
485+
return fmt.Sprintf("%s \"%s\"", GetTokenKindDesc(token.Kind), token.Value)
488486
}
489487

490488
func GetTokenKindDesc(kind int) string {

language/location/location.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func GetLocation(s *source.Source, position int) SourceLocation {
2323
for _, match := range matches {
2424
matchIndex := match[0]
2525
if matchIndex < position {
26-
line += 1
26+
line++
2727
l := len(s.Body[match[0]:match[1]])
2828
column = position + 1 - (matchIndex + l)
2929
continue

language/parser/parser.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,8 @@ func parseSelection(parser *Parser) (interface{}, error) {
363363
if peek(parser, lexer.TokenKind[lexer.SPREAD]) {
364364
r, err := parseFragment(parser)
365365
return r, err
366-
} else {
367-
return parseField(parser)
368366
}
367+
return parseField(parser)
369368
}
370369

371370
/**
@@ -1241,9 +1240,8 @@ func skip(parser *Parser, Kind int) (bool, error) {
12411240
if parser.Token.Kind == Kind {
12421241
err := advance(parser)
12431242
return true, err
1244-
} else {
1245-
return false, nil
12461243
}
1244+
return false, nil
12471245
}
12481246

12491247
// If the next token is of the given kind, return that token after advancing

language/type_info/type_info.go renamed to language/typeInfo/type_info.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
package type_info
1+
package typeInfo
22

33
import (
44
"github.com/graphql-go/graphql/language/ast"
55
)
66

7-
/**
8-
* TypeInfoI defines the interface for TypeInfo
9-
* Implementation
10-
*/
7+
// TypeInfoI defines the interface for TypeInfo Implementation
118
type TypeInfoI interface {
129
Enter(node ast.Node)
1310
Leave(node ast.Node)

language/visitor/visitor.go

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"github.com/graphql-go/graphql/language/ast"
7-
"github.com/graphql-go/graphql/language/type_info"
7+
"github.com/graphql-go/graphql/language/typeInfo"
88
"reflect"
99
)
1010

@@ -18,7 +18,7 @@ const (
1818
type KeyMap map[string][]string
1919

2020
// note that the keys are in Capital letters, equivalent to the ast.Node field Names
21-
var QueryDocumentKeys KeyMap = KeyMap{
21+
var QueryDocumentKeys = KeyMap{
2222
"Name": []string{},
2323
"Document": []string{"Definitions"},
2424
"OperationDefinition": []string{
@@ -621,10 +621,9 @@ func updateNodeField(value interface{}, fieldName string, fieldValue interface{}
621621
if isPtr == true {
622622
retVal = val.Addr().Interface()
623623
return retVal
624-
} else {
625-
retVal = val.Interface()
626-
return retVal
627624
}
625+
retVal = val.Interface()
626+
return retVal
628627

629628
}
630629
}
@@ -710,12 +709,10 @@ func isNilNode(node interface{}) bool {
710709
return val.Interface() == nil
711710
}
712711

713-
/**
714-
* Creates a new visitor instance which delegates to many visitors to run in
715-
* parallel. Each visitor will be visited for each node before moving on.
716-
*
717-
* If a prior visitor edits a node, no following visitors will see that node.
718-
*/
712+
// VisitInParallel Creates a new visitor instance which delegates to many visitors to run in
713+
// parallel. Each visitor will be visited for each node before moving on.
714+
//
715+
// If a prior visitor edits a node, no following visitors will see that node.
719716
func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
720717
skipping := map[int]interface{}{}
721718

@@ -768,23 +765,21 @@ func VisitInParallel(visitorOptsSlice ...*VisitorOptions) *VisitorOptions {
768765
}
769766
}
770767

771-
/**
772-
* Creates a new visitor instance which maintains a provided TypeInfo instance
773-
* along with visiting visitor.
774-
*/
775-
func VisitWithTypeInfo(typeInfo type_info.TypeInfoI, visitorOpts *VisitorOptions) *VisitorOptions {
768+
// VisitWithTypeInfo Creates a new visitor instance which maintains a provided TypeInfo instance
769+
// along with visiting visitor.
770+
func VisitWithTypeInfo(ttypeInfo typeInfo.TypeInfoI, visitorOpts *VisitorOptions) *VisitorOptions {
776771
return &VisitorOptions{
777772
Enter: func(p VisitFuncParams) (string, interface{}) {
778773
if node, ok := p.Node.(ast.Node); ok {
779-
typeInfo.Enter(node)
774+
ttypeInfo.Enter(node)
780775
fn := GetVisitFn(visitorOpts, node.GetKind(), false)
781776
if fn != nil {
782777
action, result := fn(p)
783778
if action == ActionUpdate {
784-
typeInfo.Leave(node)
779+
ttypeInfo.Leave(node)
785780
if isNode(result) {
786781
if result, ok := result.(ast.Node); ok {
787-
typeInfo.Enter(result)
782+
ttypeInfo.Enter(result)
788783
}
789784
}
790785
}
@@ -801,17 +796,15 @@ func VisitWithTypeInfo(typeInfo type_info.TypeInfoI, visitorOpts *VisitorOptions
801796
if fn != nil {
802797
action, result = fn(p)
803798
}
804-
typeInfo.Leave(node)
799+
ttypeInfo.Leave(node)
805800
}
806801
return action, result
807802
},
808803
}
809804
}
810805

811-
/**
812-
* Given a visitor instance, if it is leaving or not, and a node kind, return
813-
* the function the visitor runtime should call.
814-
*/
806+
// GetVisitFn Given a visitor instance, if it is leaving or not, and a node kind, return
807+
// the function the visitor runtime should call.
815808
func GetVisitFn(visitorOpts *VisitorOptions, kind string, isLeaving bool) VisitFunc {
816809
if visitorOpts == nil {
817810
return nil
@@ -825,35 +818,31 @@ func GetVisitFn(visitorOpts *VisitorOptions, kind string, isLeaving bool) VisitF
825818
if isLeaving {
826819
// { Kind: { leave() {} } }
827820
return kindVisitor.Leave
828-
} else {
829-
// { Kind: { enter() {} } }
830-
return kindVisitor.Enter
831821
}
832-
} else {
833-
834-
if isLeaving {
835-
// { enter() {} }
836-
specificVisitor := visitorOpts.Leave
837-
if specificVisitor != nil {
838-
return specificVisitor
839-
}
840-
if specificKindVisitor, ok := visitorOpts.LeaveKindMap[kind]; ok {
841-
// { leave: { Kind() {} } }
842-
return specificKindVisitor
843-
}
822+
// { Kind: { enter() {} } }
823+
return kindVisitor.Enter
844824

845-
} else {
846-
// { leave() {} }
847-
specificVisitor := visitorOpts.Enter
848-
if specificVisitor != nil {
849-
return specificVisitor
850-
}
851-
if specificKindVisitor, ok := visitorOpts.EnterKindMap[kind]; ok {
852-
// { enter: { Kind() {} } }
853-
return specificKindVisitor
854-
}
855-
}
856825
}
826+
if isLeaving {
827+
// { enter() {} }
828+
specificVisitor := visitorOpts.Leave
829+
if specificVisitor != nil {
830+
return specificVisitor
831+
}
832+
if specificKindVisitor, ok := visitorOpts.LeaveKindMap[kind]; ok {
833+
// { leave: { Kind() {} } }
834+
return specificKindVisitor
835+
}
857836

837+
}
838+
// { leave() {} }
839+
specificVisitor := visitorOpts.Enter
840+
if specificVisitor != nil {
841+
return specificVisitor
842+
}
843+
if specificKindVisitor, ok := visitorOpts.EnterKindMap[kind]; ok {
844+
// { enter: { Kind() {} } }
845+
return specificKindVisitor
846+
}
858847
return nil
859848
}

0 commit comments

Comments
 (0)