Skip to content

Commit 1211977

Browse files
authored
Fix warnings/errors from staticcheck (#3)
* Fix errors from staticcheck * Run goimports
1 parent c22b372 commit 1211977

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed

jlib/boolean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Boolean(v reflect.Value) bool {
2929

3030
if jtypes.IsArray(v) {
3131
for i := 0; i < v.Len(); i++ {
32-
if Boolean(v.Index(i)) == true {
32+
if Boolean(v.Index(i)) {
3333
return true
3434
}
3535
}

jlib/jlib.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"math/rand"
1111
"reflect"
12-
"regexp"
1312
"time"
1413

1514
"github.com/blues/jsonata-go/jtypes"
@@ -20,7 +19,6 @@ func init() {
2019
rand.Seed(time.Now().UnixNano())
2120
}
2221

23-
var typeRegex = reflect.TypeOf((*regexp.Regexp)(nil))
2422
var typeBool = reflect.TypeOf((*bool)(nil)).Elem()
2523
var typeCallable = reflect.TypeOf((*jtypes.Callable)(nil)).Elem()
2624
var typeString = reflect.TypeOf((*string)(nil)).Elem()

jlib/jxpath/formatnumber.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ func validateSubpictureParts(parts subpictureParts, format *DecimalFormat) error
358358
pos := strings.IndexFunc(parts.Integer, isDecimalDigit)
359359
if pos != -1 {
360360
pos += utf8.RuneLen(format.ZeroDigit)
361-
if strings.IndexRune(parts.Integer[pos:], format.OptionalDigit) != -1 {
361+
if strings.ContainsRune(parts.Integer[pos:], format.OptionalDigit) {
362362
return fmt.Errorf("an integer part cannot contain a decimal digit followed by an optional digit")
363363
}
364364
}
@@ -670,7 +670,7 @@ func splitStringAtRune(s string, r rune) (string, string) {
670670
return s, ""
671671
}
672672

673-
if s2 := s[pos+utf8.RuneLen(r):]; strings.IndexRune(s2, r) == -1 {
673+
if s2 := s[pos+utf8.RuneLen(r):]; !strings.ContainsRune(s2, r) {
674674
return s[:pos], s2
675675
}
676676

jparse/jparse.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ const (
146146
)
147147

148148
func lookupNud(tt tokenType) nud {
149-
if tt < 0 || tt >= nudCount {
149+
if tt >= nudCount {
150150
return nil
151151
}
152152
return nuds[tt]
153153
}
154154

155155
func lookupLed(tt tokenType) led {
156-
if tt < 0 || tt >= ledCount {
156+
if tt >= ledCount {
157157
return nil
158158
}
159159
return leds[tt]
160160
}
161161

162162
func lookupBp(tt tokenType) int {
163-
if tt < 0 || tt >= ledCount {
163+
if tt >= ledCount {
164164
return 0
165165
}
166166
return bps[tt]

jparse/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (n *PathNode) optimize() (Node, error) {
235235
}
236236

237237
func (n PathNode) String() string {
238-
s := fmt.Sprintf("%s", joinNodes(n.Steps, "."))
238+
s := joinNodes(n.Steps, ".")
239239
if n.KeepArrays {
240240
s += "[]"
241241
}

jsonata-server/bench.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"log"
99
"net/http"
1010

11-
jsonata "github.com/blues/jsonata-go"
1211
"encoding/json"
12+
13+
jsonata "github.com/blues/jsonata-go"
1314
)
1415

1516
var (

jsonata-test/main.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func runTest(tc testCase, dataDir string, path string) (bool, error) {
139139

140140
var failed bool
141141
expr, unQuoted := replaceQuotesInPaths(tc.Expr)
142-
got, err := eval(expr, tc.Bindings, data)
142+
got, _ := eval(expr, tc.Bindings, data)
143143

144144
if !equalResults(got, tc.Result) {
145145
failed = true
@@ -161,16 +161,18 @@ func runTest(tc testCase, dataDir string, path string) (bool, error) {
161161
fmt.Fprintf(os.Stderr, "Actual Result: %v [%T]\n", got, got)
162162
}
163163

164-
var exp error
165-
if tc.Undefined {
166-
exp = jsonata.ErrUndefined
167-
} else {
168-
exp = convertError(tc.Error)
169-
}
170-
171-
if !reflect.DeepEqual(err, exp) {
172-
// TODO: Compare actual/expected errors
173-
}
164+
// TODO this block is commented out to make staticcheck happy,
165+
// but we should check that the error is the same as the js one
166+
// var exp error
167+
// if tc.Undefined {
168+
// exp = jsonata.ErrUndefined
169+
// } else {
170+
// exp = convertError(tc.Error)
171+
// }
172+
173+
// if !reflect.DeepEqual(err, exp) {
174+
// TODO: Compare actual/expected errors
175+
// }
174176

175177
return failed, nil
176178
}

0 commit comments

Comments
 (0)