Upgrade to golangci-lint v2 (#1008)
This commit is contained in:
+4
-4
@@ -83,7 +83,7 @@ func (n *Node) Next() *Node {
|
||||
if n.next == 0 {
|
||||
return nil
|
||||
}
|
||||
ptr := unsafe.Pointer(n)
|
||||
ptr := unsafe.Pointer(n) // #nosec G103
|
||||
size := unsafe.Sizeof(Node{})
|
||||
return (*Node)(danger.Stride(ptr, size, n.next))
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (n *Node) Child() *Node {
|
||||
if n.child == 0 {
|
||||
return nil
|
||||
}
|
||||
ptr := unsafe.Pointer(n)
|
||||
ptr := unsafe.Pointer(n) // #nosec G103
|
||||
size := unsafe.Sizeof(Node{})
|
||||
return (*Node)(danger.Stride(ptr, size, n.child))
|
||||
}
|
||||
@@ -113,13 +113,13 @@ func (n *Node) Key() Iterator {
|
||||
case KeyValue:
|
||||
value := n.Child()
|
||||
if !value.Valid() {
|
||||
panic(fmt.Errorf("KeyValue should have at least two children"))
|
||||
panic("KeyValue should have at least two children")
|
||||
}
|
||||
return Iterator{node: value.Next()}
|
||||
case Table, ArrayTable:
|
||||
return Iterator{node: n.Child()}
|
||||
default:
|
||||
panic(fmt.Errorf("Key() is not supported on a %s", n.Kind))
|
||||
panic(fmt.Errorf("key is not supported on a %s", n.Kind))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-14
@@ -5,12 +5,14 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var valid10Ascii = []byte("1234567890")
|
||||
var valid10Utf8 = []byte("日本語a")
|
||||
var valid1kUtf8 = bytes.Repeat([]byte("0123456789日本語日本語日本語日abcdefghijklmnopqrstuvwx"), 16)
|
||||
var valid1MUtf8 = bytes.Repeat(valid1kUtf8, 1024)
|
||||
var valid1kAscii = bytes.Repeat([]byte("012345678998jhjklasDJKLAAdjdfjsdklfjdslkabcdefghijklmnopqrstuvwx"), 16)
|
||||
var valid1MAscii = bytes.Repeat(valid1kAscii, 1024)
|
||||
var (
|
||||
valid10ASCII = []byte("1234567890")
|
||||
valid10Utf8 = []byte("日本語a")
|
||||
valid1kUtf8 = bytes.Repeat([]byte("0123456789日本語日本語日本語日abcdefghijklmnopqrstuvwx"), 16)
|
||||
valid1MUtf8 = bytes.Repeat(valid1kUtf8, 1024)
|
||||
valid1kASCII = bytes.Repeat([]byte("012345678998jhjklasDJKLAAdjdfjsdklfjdslkabcdefghijklmnopqrstuvwx"), 16)
|
||||
valid1MASCII = bytes.Repeat(valid1kASCII, 1024)
|
||||
)
|
||||
|
||||
func BenchmarkScanComments(b *testing.B) {
|
||||
wrap := func(x []byte) []byte {
|
||||
@@ -18,9 +20,9 @@ func BenchmarkScanComments(b *testing.B) {
|
||||
}
|
||||
|
||||
inputs := map[string][]byte{
|
||||
"10Valid": wrap(valid10Ascii),
|
||||
"1kValid": wrap(valid1kAscii),
|
||||
"1MValid": wrap(valid1MAscii),
|
||||
"10Valid": wrap(valid10ASCII),
|
||||
"1kValid": wrap(valid1kASCII),
|
||||
"1MValid": wrap(valid1MASCII),
|
||||
"10ValidUtf8": wrap(valid10Utf8),
|
||||
"1kValidUtf8": wrap(valid1kUtf8),
|
||||
"1MValidUtf8": wrap(valid1MUtf8),
|
||||
@@ -33,7 +35,7 @@ func BenchmarkScanComments(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
scanComment(input)
|
||||
_, _, _ = scanComment(input)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -45,9 +47,9 @@ func BenchmarkParseLiteralStringValid(b *testing.B) {
|
||||
}
|
||||
|
||||
inputs := map[string][]byte{
|
||||
"10Valid": wrap(valid10Ascii),
|
||||
"1kValid": wrap(valid1kAscii),
|
||||
"1MValid": wrap(valid1MAscii),
|
||||
"10Valid": wrap(valid10ASCII),
|
||||
"1kValid": wrap(valid1kASCII),
|
||||
"1MValid": wrap(valid1MASCII),
|
||||
"10ValidUtf8": wrap(valid10Utf8),
|
||||
"1kValidUtf8": wrap(valid1kUtf8),
|
||||
"1MValidUtf8": wrap(valid1MUtf8),
|
||||
@@ -63,7 +65,7 @@ func BenchmarkParseLiteralStringValid(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _, _, err := p.parseLiteralString(input)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+16
-4
@@ -6,28 +6,40 @@ import "fmt"
|
||||
type Kind int
|
||||
|
||||
const (
|
||||
// Meta
|
||||
// Invalid represents an invalid meta node.
|
||||
Invalid Kind = iota
|
||||
// Comment represents a comment meta node.
|
||||
Comment
|
||||
// Key represents a key meta node.
|
||||
Key
|
||||
|
||||
// Top level structures
|
||||
// Table represents a top-level table.
|
||||
Table
|
||||
// ArrayTable represents a top-level array table.
|
||||
ArrayTable
|
||||
// KeyValue represents a top-level key value.
|
||||
KeyValue
|
||||
|
||||
// Containers values
|
||||
// Array represents an array container value.
|
||||
Array
|
||||
// InlineTable represents an inline table container value.
|
||||
InlineTable
|
||||
|
||||
// Values
|
||||
// String represents a string value.
|
||||
String
|
||||
// Bool represents a boolean value.
|
||||
Bool
|
||||
// Float represents a floating point value.
|
||||
Float
|
||||
// Integer represents an integer value.
|
||||
Integer
|
||||
// LocalDate represents a a local date value.
|
||||
LocalDate
|
||||
// LocalTime represents a local time value.
|
||||
LocalTime
|
||||
// LocalDateTime represents a local date/time value.
|
||||
LocalDateTime
|
||||
// DateTime represents a data/time value.
|
||||
DateTime
|
||||
)
|
||||
|
||||
|
||||
+15
-21
@@ -70,8 +70,8 @@ func (p *Parser) Data() []byte {
|
||||
// panics.
|
||||
func (p *Parser) Range(b []byte) Range {
|
||||
return Range{
|
||||
Offset: uint32(danger.SubsliceOffset(p.data, b)),
|
||||
Length: uint32(len(b)),
|
||||
Offset: uint32(danger.SubsliceOffset(p.data, b)), // #nosec G115
|
||||
Length: uint32(len(b)), // #nosec G115
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +351,6 @@ func (p *Parser) parseKeyval(b []byte) (reference, []byte, error) {
|
||||
return ref, b, err
|
||||
}
|
||||
|
||||
//nolint:cyclop,funlen
|
||||
func (p *Parser) parseVal(b []byte) (reference, []byte, error) {
|
||||
// val = string / boolean / array / inline-table / date-time / float / integer
|
||||
ref := invalidReference
|
||||
@@ -509,7 +508,6 @@ func (p *Parser) parseInlineTable(b []byte) (reference, []byte, error) {
|
||||
return parent, rest, err
|
||||
}
|
||||
|
||||
//nolint:funlen,cyclop
|
||||
func (p *Parser) parseValArray(b []byte) (reference, []byte, error) {
|
||||
// array = array-open [ array-values ] ws-comment-newline array-close
|
||||
// array-open = %x5B ; [
|
||||
@@ -542,7 +540,7 @@ func (p *Parser) parseValArray(b []byte) (reference, []byte, error) {
|
||||
|
||||
var err error
|
||||
for len(b) > 0 {
|
||||
cref := invalidReference
|
||||
var cref reference
|
||||
cref, b, err = p.parseOptionalWhitespaceCommentNewline(b)
|
||||
if err != nil {
|
||||
return parent, nil, err
|
||||
@@ -611,12 +609,13 @@ func (p *Parser) parseOptionalWhitespaceCommentNewline(b []byte) (reference, []b
|
||||
latestCommentRef := invalidReference
|
||||
|
||||
addComment := func(ref reference) {
|
||||
if rootCommentRef == invalidReference {
|
||||
switch {
|
||||
case rootCommentRef == invalidReference:
|
||||
rootCommentRef = ref
|
||||
} else if latestCommentRef == invalidReference {
|
||||
case latestCommentRef == invalidReference:
|
||||
p.builder.AttachChild(rootCommentRef, ref)
|
||||
latestCommentRef = ref
|
||||
} else {
|
||||
default:
|
||||
p.builder.Chain(latestCommentRef, ref)
|
||||
latestCommentRef = ref
|
||||
}
|
||||
@@ -672,7 +671,6 @@ func (p *Parser) parseMultilineLiteralString(b []byte) ([]byte, []byte, []byte,
|
||||
return token, token[i : len(token)-3], rest, err
|
||||
}
|
||||
|
||||
//nolint:funlen,gocognit,cyclop
|
||||
func (p *Parser) parseMultilineBasicString(b []byte) ([]byte, []byte, []byte, error) {
|
||||
// ml-basic-string = ml-basic-string-delim [ newline ] ml-basic-body
|
||||
// ml-basic-string-delim
|
||||
@@ -704,11 +702,11 @@ func (p *Parser) parseMultilineBasicString(b []byte) ([]byte, []byte, []byte, er
|
||||
|
||||
if !escaped {
|
||||
str := token[startIdx:endIdx]
|
||||
verr := characters.Utf8TomlValidAlreadyEscaped(str)
|
||||
if verr.Zero() {
|
||||
highlight := characters.Utf8TomlValidAlreadyEscaped(str)
|
||||
if len(highlight) == 0 {
|
||||
return token, str, rest, nil
|
||||
}
|
||||
return nil, nil, nil, NewParserError(str[verr.Index:verr.Index+verr.Size], "invalid UTF-8")
|
||||
return nil, nil, nil, NewParserError(highlight, "invalid UTF-8")
|
||||
}
|
||||
|
||||
var builder bytes.Buffer
|
||||
@@ -718,7 +716,6 @@ func (p *Parser) parseMultilineBasicString(b []byte) ([]byte, []byte, []byte, er
|
||||
for i < len(token)-3 {
|
||||
c := token[i]
|
||||
|
||||
//nolint:nestif
|
||||
if c == '\\' {
|
||||
// When the last non-whitespace character on a line is an unescaped \,
|
||||
// it will be trimmed along with all whitespace (including newlines) up
|
||||
@@ -744,7 +741,7 @@ func (p *Parser) parseMultilineBasicString(b []byte) ([]byte, []byte, []byte, er
|
||||
i += j
|
||||
for ; i < len(token)-3; i++ {
|
||||
c := token[i]
|
||||
if !(c == '\n' || c == '\r' || c == ' ' || c == '\t') {
|
||||
if c != '\n' && c != '\r' && c != ' ' && c != '\t' {
|
||||
i--
|
||||
break
|
||||
}
|
||||
@@ -868,7 +865,6 @@ func (p *Parser) parseSimpleKey(b []byte) (raw, key, rest []byte, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:funlen,cyclop
|
||||
func (p *Parser) parseBasicString(b []byte) ([]byte, []byte, []byte, error) {
|
||||
// basic-string = quotation-mark *basic-char quotation-mark
|
||||
// quotation-mark = %x22 ; "
|
||||
@@ -897,11 +893,11 @@ func (p *Parser) parseBasicString(b []byte) ([]byte, []byte, []byte, error) {
|
||||
// validate the string and return a direct reference to the buffer.
|
||||
if !escaped {
|
||||
str := token[startIdx:endIdx]
|
||||
verr := characters.Utf8TomlValidAlreadyEscaped(str)
|
||||
if verr.Zero() {
|
||||
highlight := characters.Utf8TomlValidAlreadyEscaped(str)
|
||||
if len(highlight) == 0 {
|
||||
return token, str, rest, nil
|
||||
}
|
||||
return nil, nil, nil, NewParserError(str[verr.Index:verr.Index+verr.Size], "invalid UTF-8")
|
||||
return nil, nil, nil, NewParserError(highlight, "invalid UTF-8")
|
||||
}
|
||||
|
||||
i := startIdx
|
||||
@@ -972,7 +968,7 @@ func hexToRune(b []byte, length int) (rune, error) {
|
||||
|
||||
var r uint32
|
||||
for i, c := range b {
|
||||
d := uint32(0)
|
||||
var d uint32
|
||||
switch {
|
||||
case '0' <= c && c <= '9':
|
||||
d = uint32(c - '0')
|
||||
@@ -1002,7 +998,6 @@ func (p *Parser) parseWhitespace(b []byte) []byte {
|
||||
return rest
|
||||
}
|
||||
|
||||
//nolint:cyclop
|
||||
func (p *Parser) parseIntOrFloatOrDateTime(b []byte) (reference, []byte, error) {
|
||||
switch b[0] {
|
||||
case 'i':
|
||||
@@ -1118,7 +1113,6 @@ byteLoop:
|
||||
}), b[i:], nil
|
||||
}
|
||||
|
||||
//nolint:funlen,gocognit,cyclop
|
||||
func (p *Parser) scanIntOrFloat(b []byte) (reference, []byte, error) {
|
||||
i := 0
|
||||
|
||||
|
||||
@@ -196,7 +196,6 @@ func compareIterator(t *testing.T, expected []astNode, actual Iterator) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:funlen
|
||||
func TestParser_AST(t *testing.T) {
|
||||
examples := []struct {
|
||||
desc string
|
||||
@@ -358,7 +357,7 @@ func BenchmarkParseBasicStringWithUnicode(b *testing.B) {
|
||||
b.SetBytes(int64(len(input)))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.parseBasicString(input)
|
||||
_, _, _, _ = p.parseBasicString(input)
|
||||
}
|
||||
})
|
||||
b.Run("8", func(b *testing.B) {
|
||||
@@ -367,7 +366,7 @@ func BenchmarkParseBasicStringWithUnicode(b *testing.B) {
|
||||
b.SetBytes(int64(len(input)))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.parseBasicString(input)
|
||||
_, _, _, _ = p.parseBasicString(input)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -383,7 +382,7 @@ func BenchmarkParseBasicStringsEasy(b *testing.B) {
|
||||
b.SetBytes(int64(len(input)))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.parseBasicString(input)
|
||||
_, _, _, _ = p.parseBasicString(input)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user