Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
153 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
errorlint: | ||
errorf: false | ||
asserts: true | ||
comparison: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
errorlint: | ||
errorf: false | ||
asserts: false | ||
comparison: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
errorlint: | ||
errorf: true | ||
asserts: false | ||
comparison: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//args: -Eerrorlint | ||
//config_path: testdata/configs/errorlint_asserts.yml | ||
package testdata | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
) | ||
|
||
type myError struct{} | ||
|
||
func (*myError) Error() string { | ||
return "foo" | ||
} | ||
|
||
func errorLintDoAnotherThing() error { | ||
return &myError{} | ||
} | ||
|
||
func errorLintAsserts() { | ||
err := errorLintDoAnotherThing() | ||
var me *myError | ||
if errors.As(err, &me) { | ||
log.Println("myError") | ||
} | ||
_, ok := err.(*myError) // ERROR "type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors" | ||
if ok { | ||
log.Println("myError") | ||
} | ||
switch err.(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" | ||
case *myError: | ||
log.Println("myError") | ||
} | ||
switch errorLintDoAnotherThing().(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" | ||
case *myError: | ||
log.Println("myError") | ||
} | ||
switch t := err.(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" | ||
case *myError: | ||
log.Println("myError", t) | ||
} | ||
switch t := errorLintDoAnotherThing().(type) { // ERROR "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" | ||
case *myError: | ||
log.Println("myError", t) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//args: -Eerrorlint | ||
//config_path: testdata/configs/errorlint_comparison.yml | ||
package testdata | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
) | ||
|
||
var errCompare = errors.New("foo") | ||
|
||
func errorLintDoThing() error { | ||
return errCompare | ||
} | ||
|
||
func errorLintComparison() { | ||
err := errorLintDoThing() | ||
if errors.Is(err, errCompare) { | ||
log.Println("errCompare") | ||
} | ||
if err == nil { | ||
log.Println("nil") | ||
} | ||
if err != nil { | ||
log.Println("nil") | ||
} | ||
if nil == err { | ||
log.Println("nil") | ||
} | ||
if nil != err { | ||
log.Println("nil") | ||
} | ||
if err == errCompare { // ERROR "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" | ||
log.Println("errCompare") | ||
} | ||
if err != errCompare { // ERROR "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" | ||
log.Println("not errCompare") | ||
} | ||
if errCompare == err { // ERROR "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error" | ||
log.Println("errCompare") | ||
} | ||
if errCompare != err { // ERROR "comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error" | ||
log.Println("not errCompare") | ||
} | ||
switch err { // ERROR "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" | ||
case errCompare: | ||
log.Println("errCompare") | ||
} | ||
switch errorLintDoThing() { // ERROR "switch on an error will fail on wrapped errors. Use errors.Is to check for specific errors" | ||
case errCompare: | ||
log.Println("errCompare") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters