Update module spf13/viper to v1.7.0 (#494)
Update module spf13/viper to v1.7.0 Reviewed-on: https://kolaente.dev/vikunja/api/pulls/494
This commit is contained in:
223
vendor/honnef.co/go/tools/simple/analysis.go
vendored
Normal file
223
vendor/honnef.co/go/tools/simple/analysis.go
vendored
Normal file
@ -0,0 +1,223 @@
|
||||
package simple
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/analysis/passes/inspect"
|
||||
"honnef.co/go/tools/facts"
|
||||
"honnef.co/go/tools/internal/passes/buildssa"
|
||||
"honnef.co/go/tools/lint/lintutil"
|
||||
)
|
||||
|
||||
func newFlagSet() flag.FlagSet {
|
||||
fs := flag.NewFlagSet("", flag.PanicOnError)
|
||||
fs.Var(lintutil.NewVersionFlag(), "go", "Target Go version")
|
||||
return *fs
|
||||
}
|
||||
|
||||
var Analyzers = map[string]*analysis.Analyzer{
|
||||
"S1000": {
|
||||
Name: "S1000",
|
||||
Run: LintSingleCaseSelect,
|
||||
Doc: Docs["S1000"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1001": {
|
||||
Name: "S1001",
|
||||
Run: LintLoopCopy,
|
||||
Doc: Docs["S1001"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1002": {
|
||||
Name: "S1002",
|
||||
Run: LintIfBoolCmp,
|
||||
Doc: Docs["S1002"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1003": {
|
||||
Name: "S1003",
|
||||
Run: LintStringsContains,
|
||||
Doc: Docs["S1003"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1004": {
|
||||
Name: "S1004",
|
||||
Run: LintBytesCompare,
|
||||
Doc: Docs["S1004"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1005": {
|
||||
Name: "S1005",
|
||||
Run: LintUnnecessaryBlank,
|
||||
Doc: Docs["S1005"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1006": {
|
||||
Name: "S1006",
|
||||
Run: LintForTrue,
|
||||
Doc: Docs["S1006"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1007": {
|
||||
Name: "S1007",
|
||||
Run: LintRegexpRaw,
|
||||
Doc: Docs["S1007"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1008": {
|
||||
Name: "S1008",
|
||||
Run: LintIfReturn,
|
||||
Doc: Docs["S1008"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1009": {
|
||||
Name: "S1009",
|
||||
Run: LintRedundantNilCheckWithLen,
|
||||
Doc: Docs["S1009"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1010": {
|
||||
Name: "S1010",
|
||||
Run: LintSlicing,
|
||||
Doc: Docs["S1010"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1011": {
|
||||
Name: "S1011",
|
||||
Run: LintLoopAppend,
|
||||
Doc: Docs["S1011"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1012": {
|
||||
Name: "S1012",
|
||||
Run: LintTimeSince,
|
||||
Doc: Docs["S1012"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1016": {
|
||||
Name: "S1016",
|
||||
Run: LintSimplerStructConversion,
|
||||
Doc: Docs["S1016"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1017": {
|
||||
Name: "S1017",
|
||||
Run: LintTrim,
|
||||
Doc: Docs["S1017"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1018": {
|
||||
Name: "S1018",
|
||||
Run: LintLoopSlide,
|
||||
Doc: Docs["S1018"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1019": {
|
||||
Name: "S1019",
|
||||
Run: LintMakeLenCap,
|
||||
Doc: Docs["S1019"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1020": {
|
||||
Name: "S1020",
|
||||
Run: LintAssertNotNil,
|
||||
Doc: Docs["S1020"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1021": {
|
||||
Name: "S1021",
|
||||
Run: LintDeclareAssign,
|
||||
Doc: Docs["S1021"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1023": {
|
||||
Name: "S1023",
|
||||
Run: LintRedundantBreak,
|
||||
Doc: Docs["S1023"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1024": {
|
||||
Name: "S1024",
|
||||
Run: LintTimeUntil,
|
||||
Doc: Docs["S1024"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1025": {
|
||||
Name: "S1025",
|
||||
Run: LintRedundantSprintf,
|
||||
Doc: Docs["S1025"].String(),
|
||||
Requires: []*analysis.Analyzer{buildssa.Analyzer, inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1028": {
|
||||
Name: "S1028",
|
||||
Run: LintErrorsNewSprintf,
|
||||
Doc: Docs["S1028"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1029": {
|
||||
Name: "S1029",
|
||||
Run: LintRangeStringRunes,
|
||||
Doc: Docs["S1029"].String(),
|
||||
Requires: []*analysis.Analyzer{buildssa.Analyzer},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1030": {
|
||||
Name: "S1030",
|
||||
Run: LintBytesBufferConversions,
|
||||
Doc: Docs["S1030"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1031": {
|
||||
Name: "S1031",
|
||||
Run: LintNilCheckAroundRange,
|
||||
Doc: Docs["S1031"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1032": {
|
||||
Name: "S1032",
|
||||
Run: LintSortHelpers,
|
||||
Doc: Docs["S1032"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1033": {
|
||||
Name: "S1033",
|
||||
Run: LintGuardedDelete,
|
||||
Doc: Docs["S1033"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
"S1034": {
|
||||
Name: "S1034",
|
||||
Run: LintSimplifyTypeSwitch,
|
||||
Doc: Docs["S1034"].String(),
|
||||
Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated},
|
||||
Flags: newFlagSet(),
|
||||
},
|
||||
}
|
629
vendor/honnef.co/go/tools/simple/doc.go
vendored
629
vendor/honnef.co/go/tools/simple/doc.go
vendored
@ -1,426 +1,425 @@
|
||||
package simple
|
||||
|
||||
var docS1000 = `Use plain channel send or receive
|
||||
import "honnef.co/go/tools/lint"
|
||||
|
||||
Select statements with a single case can be replaced with a simple send or receive.
|
||||
var Docs = map[string]*lint.Documentation{
|
||||
"S1000": &lint.Documentation{
|
||||
Title: `Use plain channel send or receive instead of single-case select`,
|
||||
Text: `Select statements with a single case can be replaced with a simple
|
||||
send or receive.
|
||||
|
||||
Before:
|
||||
|
||||
select {
|
||||
case x := <-ch:
|
||||
fmt.Println(x)
|
||||
}
|
||||
select {
|
||||
case x := <-ch:
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
x := <-ch
|
||||
fmt.Println(x)
|
||||
x := <-ch
|
||||
fmt.Println(x)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1001 = `Replace with copy()
|
||||
|
||||
Use copy() for copying elements from one slice to another.
|
||||
"S1001": &lint.Documentation{
|
||||
Title: `Replace for loop with call to copy`,
|
||||
Text: `Use copy() for copying elements from one slice to another.
|
||||
|
||||
Before:
|
||||
|
||||
for i, x := range src {
|
||||
dst[i] = x
|
||||
}
|
||||
for i, x := range src {
|
||||
dst[i] = x
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
copy(dst, src)
|
||||
copy(dst, src)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1002": &lint.Documentation{
|
||||
Title: `Omit comparison with boolean constant`,
|
||||
Text: `Before:
|
||||
|
||||
var docS1002 = `Omit comparison with boolean constant
|
||||
if x == true {}
|
||||
|
||||
After:
|
||||
|
||||
if x {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1003": &lint.Documentation{
|
||||
Title: `Replace call to strings.Index with strings.Contains`,
|
||||
Text: `Before:
|
||||
|
||||
if strings.Index(x, y) != -1 {}
|
||||
|
||||
After:
|
||||
|
||||
if strings.Contains(x, y) {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1004": &lint.Documentation{
|
||||
Title: `Replace call to bytes.Compare with bytes.Equal`,
|
||||
Text: `Before:
|
||||
|
||||
if bytes.Compare(x, y) == 0 {}
|
||||
|
||||
After:
|
||||
|
||||
if bytes.Equal(x, y) {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1005": &lint.Documentation{
|
||||
Title: `Drop unnecessary use of the blank identifier`,
|
||||
Text: `In many cases, assigning to the blank identifier is unnecessary.
|
||||
|
||||
Before:
|
||||
|
||||
if x == true {}
|
||||
for _ = range s {}
|
||||
x, _ = someMap[key]
|
||||
_ = <-ch
|
||||
|
||||
After:
|
||||
|
||||
if x {}
|
||||
for range s{}
|
||||
x = someMap[key]
|
||||
<-ch`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1006": &lint.Documentation{
|
||||
Title: `Use for { ... } for infinite loops`,
|
||||
Text: `For infinite loops, using for { ... } is the most idiomatic choice.`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
var docS1003 = `Replace with strings.Contains
|
||||
"S1007": &lint.Documentation{
|
||||
Title: `Simplify regular expression by using raw string literal`,
|
||||
Text: `Raw string literals use ` + "`" + ` instead of " and do not support
|
||||
any escape sequences. This means that the backslash (\) can be used
|
||||
freely, without the need of escaping.
|
||||
|
||||
Since regular expressions have their own escape sequences, raw strings
|
||||
can improve their readability.
|
||||
|
||||
Before:
|
||||
|
||||
if strings.Index(x, y) != -1 {}
|
||||
regexp.Compile("\\A(\\w+) profile: total \\d+\\n\\z")
|
||||
|
||||
After:
|
||||
|
||||
if strings.Contains(x, y) {}
|
||||
regexp.Compile(` + "`" + `\A(\w+) profile: total \d+\n\z` + "`" + `)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1008": &lint.Documentation{
|
||||
Title: `Simplify returning boolean expression`,
|
||||
Text: `Before:
|
||||
|
||||
var docS1004 = `Replace with bytes.Equal
|
||||
if <expr> {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
After:
|
||||
|
||||
return <expr>`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1009": &lint.Documentation{
|
||||
Title: `Omit redundant nil check on slices`,
|
||||
Text: `The len function is defined for all slices, even nil ones, which have
|
||||
a length of zero. It is not necessary to check if a slice is not nil
|
||||
before checking that its length is not zero.
|
||||
|
||||
Before:
|
||||
|
||||
if bytes.Compare(x, y) == 0 {}
|
||||
if x != nil && len(x) != 0 {}
|
||||
|
||||
After:
|
||||
|
||||
if bytes.Equal(x, y) {}
|
||||
if len(x) != 0 {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1010": &lint.Documentation{
|
||||
Title: `Omit default slice index`,
|
||||
Text: `When slicing, the second index defaults to the length of the value,
|
||||
making s[n:len(s)] and s[n:] equivalent.`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
var docS1005 = `Drop unnecessary use of the blank identifier
|
||||
"S1011": &lint.Documentation{
|
||||
Title: `Use a single append to concatenate two slices`,
|
||||
Text: `Before:
|
||||
|
||||
In many cases, assigning to the blank identifier is unnecessary.
|
||||
for _, e := range y {
|
||||
x = append(x, e)
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
x = append(x, y...)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1012": &lint.Documentation{
|
||||
Title: `Replace time.Now().Sub(x) with time.Since(x)`,
|
||||
Text: `The time.Since helper has the same effect as using time.Now().Sub(x)
|
||||
but is easier to read.
|
||||
|
||||
Before:
|
||||
|
||||
for _ = range s {}
|
||||
x, _ = someMap[key]
|
||||
_ = <-ch
|
||||
time.Now().Sub(x)
|
||||
|
||||
After:
|
||||
|
||||
for range s{}
|
||||
x = someMap[key]
|
||||
<-ch
|
||||
time.Since(x)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1006 = `Replace with for { ... }
|
||||
|
||||
For infinite loops, using for { ... } is the most idiomatic choice.
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1007 = `Simplify regular expression by using raw string literal
|
||||
|
||||
Raw string literals use ` + "`" + ` instead of " and do not support any escape sequences. This means that the backslash (\) can be used freely, without the need of escaping.
|
||||
|
||||
Since regular expressions have their own escape sequences, raw strings can improve their readability.
|
||||
"S1016": &lint.Documentation{
|
||||
Title: `Use a type conversion instead of manually copying struct fields`,
|
||||
Text: `Two struct types with identical fields can be converted between each
|
||||
other. In older versions of Go, the fields had to have identical
|
||||
struct tags. Since Go 1.8, however, struct tags are ignored during
|
||||
conversions. It is thus not necessary to manually copy every field
|
||||
individually.
|
||||
|
||||
Before:
|
||||
|
||||
regexp.Compile("\\A(\\w+) profile: total \\d+\\n\\z")
|
||||
var x T1
|
||||
y := T2{
|
||||
Field1: x.Field1,
|
||||
Field2: x.Field2,
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
regexp.Compile(` + "`" + `\A(\w+) profile: total \d+\n\z` + "`" + `)
|
||||
var x T1
|
||||
y := T2(x)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1008 = `Simplify returning boolean expression
|
||||
"S1017": &lint.Documentation{
|
||||
Title: `Replace manual trimming with strings.TrimPrefix`,
|
||||
Text: `Instead of using strings.HasPrefix and manual slicing, use the
|
||||
strings.TrimPrefix function. If the string doesn't start with the
|
||||
prefix, the original string will be returned. Using strings.TrimPrefix
|
||||
reduces complexity, and avoids common bugs, such as off-by-one
|
||||
mistakes.
|
||||
|
||||
Before:
|
||||
|
||||
if <expr> {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
if strings.HasPrefix(str, prefix) {
|
||||
str = str[len(prefix):]
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
return <expr>
|
||||
str = strings.TrimPrefix(str, prefix)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1009 = `Omit redundant nil check on slices
|
||||
|
||||
The len function is defined for all slices, even nil ones, which have a length of zero. It is not necessary to check if a slice is not nil before checking that its length is not zero.
|
||||
"S1018": &lint.Documentation{
|
||||
Title: `Use copy for sliding elements`,
|
||||
Text: `copy() permits using the same source and destination slice, even with
|
||||
overlapping ranges. This makes it ideal for sliding elements in a
|
||||
slice.
|
||||
|
||||
Before:
|
||||
|
||||
if x != nil && len(x) != 0 {}
|
||||
for i := 0; i < n; i++ {
|
||||
bs[i] = bs[offset+i]
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
if len(x) != 0 {}
|
||||
copy(bs[:n], bs[offset:])`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1019": &lint.Documentation{
|
||||
Title: `Simplify make call by omitting redundant arguments`,
|
||||
Text: `The make function has default values for the length and capacity
|
||||
arguments. For channels and maps, the length defaults to zero.
|
||||
Additionally, for slices the capacity defaults to the length.`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
var docS1010 = `Omit default slice index
|
||||
"S1020": &lint.Documentation{
|
||||
Title: `Omit redundant nil check in type assertion`,
|
||||
Text: `Before:
|
||||
|
||||
When slicing, the second index defaults to the length of the value, making s[n:len(s)] and s[n:] equivalent.
|
||||
if _, ok := i.(T); ok && i != nil {}
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
After:
|
||||
|
||||
var docS1011 = `Use a single append to concatenate two slices
|
||||
if _, ok := i.(T); ok {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1021": &lint.Documentation{
|
||||
Title: `Merge variable declaration and assignment`,
|
||||
Text: `Before:
|
||||
|
||||
var x uint
|
||||
x = 1
|
||||
|
||||
After:
|
||||
|
||||
var x uint = 1`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1023": &lint.Documentation{
|
||||
Title: `Omit redundant control flow`,
|
||||
Text: `Functions that have no return value do not need a return statement as
|
||||
the final statement of the function.
|
||||
|
||||
Switches in Go do not have automatic fallthrough, unlike languages
|
||||
like C. It is not necessary to have a break statement as the final
|
||||
statement in a case block.`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1024": &lint.Documentation{
|
||||
Title: `Replace x.Sub(time.Now()) with time.Until(x)`,
|
||||
Text: `The time.Until helper has the same effect as using x.Sub(time.Now())
|
||||
but is easier to read.
|
||||
|
||||
Before:
|
||||
|
||||
for _, e := range y {
|
||||
x = append(x, e)
|
||||
}
|
||||
x.Sub(time.Now())
|
||||
|
||||
After:
|
||||
|
||||
x = append(x, y...)
|
||||
time.Until(x)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1012 = `Replace with time.Since(x)
|
||||
|
||||
The time.Since helper has the same effect as using time.Now().Sub(x) but is easier to read.
|
||||
|
||||
Before:
|
||||
|
||||
time.Now().Sub(x)
|
||||
|
||||
After:
|
||||
|
||||
time.Since(x)
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1016 = `Use a type conversion
|
||||
|
||||
Two struct types with identical fields can be converted between each other. In older versions of Go, the fields had to have identical struct tags. Since Go 1.8, however, struct tags are ignored during conversions. It is thus not necessary to manually copy every field individually.
|
||||
|
||||
Before:
|
||||
|
||||
var x T1
|
||||
y := T2{
|
||||
Field1: x.Field1,
|
||||
Field2: x.Field2,
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
var x T1
|
||||
y := T2(x)
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1017 = `Replace with strings.TrimPrefix
|
||||
|
||||
Instead of using strings.HasPrefix and manual slicing, use the strings.TrimPrefix function. If the string doesn't start with the prefix, the original string will be returned. Using strings.TrimPrefix reduces complexity, and avoids common bugs, such as off-by-one mistakes.
|
||||
|
||||
Before:
|
||||
|
||||
if strings.HasPrefix(str, prefix) {
|
||||
str = str[len(prefix):]
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
str = strings.TrimPrefix(str, prefix)
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1018 = `Replace with copy()
|
||||
|
||||
copy() permits using the same source and destination slice, even with overlapping ranges. This makes it ideal for sliding elements in a slice.
|
||||
|
||||
Before:
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
bs[i] = bs[offset+i]
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
copy(bs[:n], bs[offset:])
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1019 = `Simplify make call
|
||||
|
||||
The make function has default values for the length and capacity arguments. For channels and maps, the length defaults to zero. Additionally, for slices the capacity defaults to the length.
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1020 = `Omit redundant nil check in type assertion
|
||||
|
||||
Before:
|
||||
|
||||
if _, ok := i.(T); ok && i != nil {}
|
||||
|
||||
After:
|
||||
|
||||
if _, ok := i.(T); ok {}
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1021 = `Merge variable declaration and assignment
|
||||
|
||||
Before:
|
||||
|
||||
var x uint
|
||||
x = 1
|
||||
|
||||
After:
|
||||
|
||||
var x uint = 1
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
var docS1023 = `Omit redundant control flow
|
||||
|
||||
Functions that have no return value do not need a return statement as the final statement of the function.
|
||||
|
||||
Switches in Go do not have automatic fallthrough, unlike languages like C. It is not necessary to have a break statement as the final statement in a case block.
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1024 = `Replace with time.Until(x)
|
||||
|
||||
The time.Until helper has the same effect as using x.Sub(time.Now()) but is easier to read.
|
||||
|
||||
Before:
|
||||
|
||||
x.Sub(time.Now())
|
||||
|
||||
After:
|
||||
|
||||
time.Until(x)
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1025 = `Don't use fmt.Sprintf("%s", x) unnecessarily
|
||||
|
||||
In many instances, there are easier and more efficient ways of getting a value's string representation. Whenever a value's underlying type is a string already, or the type has a String method, they should be used directly.
|
||||
"S1025": &lint.Documentation{
|
||||
Title: `Don't use fmt.Sprintf("%s", x) unnecessarily`,
|
||||
Text: `In many instances, there are easier and more efficient ways of getting
|
||||
a value's string representation. Whenever a value's underlying type is
|
||||
a string already, or the type has a String method, they should be used
|
||||
directly.
|
||||
|
||||
Given the following shared definitions
|
||||
|
||||
type T1 string
|
||||
type T2 int
|
||||
type T1 string
|
||||
type T2 int
|
||||
|
||||
func (T2) String() string { return "Hello, world" }
|
||||
func (T2) String() string { return "Hello, world" }
|
||||
|
||||
var x string
|
||||
var y T1
|
||||
var z T2
|
||||
var x string
|
||||
var y T1
|
||||
var z T2
|
||||
|
||||
we can simplify the following
|
||||
|
||||
fmt.Sprintf("%s", x)
|
||||
fmt.Sprintf("%s", y)
|
||||
fmt.Sprintf("%s", z)
|
||||
fmt.Sprintf("%s", x)
|
||||
fmt.Sprintf("%s", y)
|
||||
fmt.Sprintf("%s", z)
|
||||
|
||||
to
|
||||
|
||||
x
|
||||
string(y)
|
||||
z.String()
|
||||
x
|
||||
string(y)
|
||||
z.String()`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1028": &lint.Documentation{
|
||||
Title: `Simplify error construction with fmt.Errorf`,
|
||||
Text: `Before:
|
||||
|
||||
var docS1028 = `replace with fmt.Errorf
|
||||
|
||||
Before:
|
||||
|
||||
errors.New(fmt.Sprintf(...))
|
||||
errors.New(fmt.Sprintf(...))
|
||||
|
||||
After:
|
||||
|
||||
fmt.Errorf(...)
|
||||
fmt.Errorf(...)`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1029 = `Range over the string
|
||||
|
||||
Ranging over a string will yield byte offsets and runes. If the offset isn't used, this is functionally equivalent to converting the string to a slice of runes and ranging over that. Ranging directly over the string will be more performant, however, as it avoids allocating a new slice, the size of which depends on the length of the string.
|
||||
"S1029": &lint.Documentation{
|
||||
Title: `Range over the string directly`,
|
||||
Text: `Ranging over a string will yield byte offsets and runes. If the offset
|
||||
isn't used, this is functionally equivalent to converting the string
|
||||
to a slice of runes and ranging over that. Ranging directly over the
|
||||
string will be more performant, however, as it avoids allocating a new
|
||||
slice, the size of which depends on the length of the string.
|
||||
|
||||
Before:
|
||||
|
||||
for _, r := range []rune(s) {}
|
||||
for _, r := range []rune(s) {}
|
||||
|
||||
After:
|
||||
|
||||
for _, r := range s {}
|
||||
for _, r := range s {}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
"S1030": &lint.Documentation{
|
||||
Title: `Use bytes.Buffer.String or bytes.Buffer.Bytes`,
|
||||
Text: `bytes.Buffer has both a String and a Bytes method. It is never
|
||||
necessary to use string(buf.Bytes()) or []byte(buf.String()) – simply
|
||||
use the other method.`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
var docS1030 = `Use bytes.Buffer.String or bytes.Buffer.Bytes
|
||||
|
||||
bytes.Buffer has both a String and a Bytes method. It is never necessary to use string(buf.Bytes()) or []byte(buf.String()) – simply use the other method.
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1031 = `Omit redundant nil check around loop
|
||||
|
||||
You can use range on nil slices and maps, the loop will simply never execute. This makes an additional nil check around the loop unnecessary.
|
||||
"S1031": &lint.Documentation{
|
||||
Title: `Omit redundant nil check around loop`,
|
||||
Text: `You can use range on nil slices and maps, the loop will simply never
|
||||
execute. This makes an additional nil check around the loop
|
||||
unnecessary.
|
||||
|
||||
Before:
|
||||
|
||||
if s != nil {
|
||||
for _, x := range s {
|
||||
...
|
||||
}
|
||||
if s != nil {
|
||||
for _, x := range s {
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
for _, x := range s {
|
||||
...
|
||||
}`,
|
||||
Since: "2017.1",
|
||||
},
|
||||
|
||||
"S1032": &lint.Documentation{
|
||||
Title: `Use sort.Ints(x), sort.Float64s(x), and sort.Strings(x)`,
|
||||
Text: `The sort.Ints, sort.Float64s and sort.Strings functions are easier to
|
||||
read than sort.Sort(sort.IntSlice(x)), sort.Sort(sort.Float64Slice(x))
|
||||
and sort.Sort(sort.StringSlice(x)).
|
||||
|
||||
Before:
|
||||
|
||||
sort.Sort(sort.StringSlice(x))
|
||||
|
||||
After:
|
||||
|
||||
sort.Strings(x)`,
|
||||
Since: "2019.1",
|
||||
},
|
||||
|
||||
"S1033": &lint.Documentation{
|
||||
Title: `Unnecessary guard around call to delete`,
|
||||
Text: `Calling delete on a nil map is a no-op.`,
|
||||
Since: "2019.2",
|
||||
},
|
||||
|
||||
"S1034": &lint.Documentation{
|
||||
Title: `Use result of type assertion to simplify cases`,
|
||||
Since: "2019.2",
|
||||
},
|
||||
}
|
||||
|
||||
After:
|
||||
|
||||
for _, x := range s {
|
||||
...
|
||||
}
|
||||
|
||||
Available since
|
||||
2017.1
|
||||
`
|
||||
|
||||
var docS1032 = `Replace with sort.Ints(x), sort.Float64s(x), sort.Strings(x)
|
||||
|
||||
The sort.Ints, sort.Float64s and sort.Strings functions are easier to read than sort.Sort(sort.IntSlice(x)), sort.Sort(sort.Float64Slice(x)) and sort.Sort(sort.StringSlice(x)).
|
||||
|
||||
Before:
|
||||
|
||||
sort.Sort(sort.StringSlice(x))
|
||||
|
||||
After:
|
||||
|
||||
sort.Strings(x)
|
||||
|
||||
Available since
|
||||
2019.1
|
||||
`
|
||||
|
525
vendor/honnef.co/go/tools/simple/lint.go
vendored
525
vendor/honnef.co/go/tools/simple/lint.go
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user