Skip to content

Commit

Permalink
Small staticcheck fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Sep 23, 2023
1 parent c63ff8a commit 01fb725
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
4 changes: 1 addition & 3 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,7 @@ type (
Slice *InnerArrayString
}
Enum int
InnerString struct{ value string }
InnerInt struct{ value int }
InnerBool struct{ value bool }
InnerArrayString struct{ value []string }
)

Expand Down Expand Up @@ -1234,7 +1232,7 @@ func TestDecodeParallel(t *testing.T) {
defer wg.Done()
err := Unmarshal(doc, new(map[string]any))
if err != nil {
t.Fatal(err)
panic(err)
}
}()
}
Expand Down
33 changes: 11 additions & 22 deletions lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ func lexTopEnd(lx *lexer) stateFn {
lx.emit(itemEOF)
return nil
}
return lx.errorf(
"expected a top-level item to end with a newline, comment, or EOF, but got %q instead",
r)
return lx.errorf("expected a top-level item to end with a newline, comment, or EOF, but got %q instead", r)
}

// lexTable lexes the beginning of a table. Namely, it makes sure that
Expand Down Expand Up @@ -879,10 +877,8 @@ func lexHexEscape(lx *lexer) stateFn {
var r rune
for i := 0; i < 2; i++ {
r = lx.next()
if !isHexadecimal(r) {
return lx.errorf(
`expected two hexadecimal digits after '\x', but got %q instead`,
lx.current())
if !isHex(r) {
return lx.errorf(`expected two hexadecimal digits after '\x', but got %q instead`, lx.current())
}
}
return lx.pop()
Expand All @@ -892,10 +888,8 @@ func lexShortUnicodeEscape(lx *lexer) stateFn {
var r rune
for i := 0; i < 4; i++ {
r = lx.next()
if !isHexadecimal(r) {
return lx.errorf(
`expected four hexadecimal digits after '\u', but got %q instead`,
lx.current())
if !isHex(r) {
return lx.errorf(`expected four hexadecimal digits after '\u', but got %q instead`, lx.current())
}
}
return lx.pop()
Expand All @@ -905,10 +899,8 @@ func lexLongUnicodeEscape(lx *lexer) stateFn {
var r rune
for i := 0; i < 8; i++ {
r = lx.next()
if !isHexadecimal(r) {
return lx.errorf(
`expected eight hexadecimal digits after '\U', but got %q instead`,
lx.current())
if !isHex(r) {
return lx.errorf(`expected eight hexadecimal digits after '\U', but got %q instead`, lx.current())
}
}
return lx.pop()
Expand Down Expand Up @@ -975,7 +967,7 @@ func lexDatetime(lx *lexer) stateFn {
// lexHexInteger consumes a hexadecimal integer after seeing the '0x' prefix.
func lexHexInteger(lx *lexer) stateFn {
r := lx.next()
if isHexadecimal(r) {
if isHex(r) {
return lexHexInteger
}
switch r {
Expand Down Expand Up @@ -1109,7 +1101,7 @@ func lexBaseNumberOrDate(lx *lexer) stateFn {
return lexOctalInteger
case 'x':
r = lx.peek()
if !isHexadecimal(r) {
if !isHex(r) {
lx.errorf("not a hexidecimal number: '%s%c'", lx.current(), r)
}
return lexHexInteger
Expand Down Expand Up @@ -1240,7 +1232,7 @@ func (itype itemType) String() string {
}

func (item item) String() string {
return fmt.Sprintf("(%s, %s)", item.typ.String(), item.val)
return fmt.Sprintf("(%s, %s)", item.typ, item.val)
}

func isWhitespace(r rune) bool { return r == '\t' || r == ' ' }
Expand All @@ -1256,10 +1248,7 @@ func isControl(r rune) bool { // Control characters except \t, \r, \n
func isDigit(r rune) bool { return r >= '0' && r <= '9' }
func isBinary(r rune) bool { return r == '0' || r == '1' }
func isOctal(r rune) bool { return r >= '0' && r <= '7' }
func isHexadecimal(r rune) bool {
return (r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')
}

func isHex(r rune) bool { return (r >= '0' && r <= '9') || (r|0x20 >= 'a' && r|0x20 <= 'f') }
func isBareKeyChar(r rune, tomlNext bool) bool {
if tomlNext {
return (r >= 'A' && r <= 'Z') ||
Expand Down
7 changes: 4 additions & 3 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func parse(data string) (p *parser, err error) {
// it anyway.
if strings.HasPrefix(data, "\xff\xfe") || strings.HasPrefix(data, "\xfe\xff") { // UTF-16
data = data[2:]
//lint:ignore S1017 https://github.com/dominikh/go-tools/issues/1447
} else if strings.HasPrefix(data, "\xef\xbb\xbf") { // UTF-8
data = data[3:]
}
Expand Down Expand Up @@ -486,9 +487,9 @@ func numUnderscoresOK(s string) bool {
}
}

// isHexadecimal is a superset of all the permissable characters
// surrounding an underscore.
accept = isHexadecimal(r)
// isHexis a superset of all the permissable characters surrounding an
// underscore.
accept = isHex(r)
}
return accept
}
Expand Down

0 comments on commit 01fb725

Please sign in to comment.