File tree Expand file tree Collapse file tree 4 files changed +41
-9
lines changed
Expand file tree Collapse file tree 4 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -352,7 +352,8 @@ on relevant lines:
352352
353353``` go
354354// errtrace:skip
355- // errtrace:skip explanation
355+ // errtrace:skip(explanation)
356+ // errtrace:skip // explanation
356357```
357358
358359This can be especially useful if the returned error
@@ -367,7 +368,7 @@ type myReader struct{/* ... */}
367368
368369func (*myReader ) Read (bs []byte ) (int , error ) {
369370 // ...
370- return 0 , io.EOF // errtrace:skip (io.Reader requires io.EOF)
371+ return 0 , io.EOF // errtrace:skip(io.Reader expects io.EOF)
371372}
372373```
373374
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import (
3434 "io"
3535 "log"
3636 "os"
37+ "regexp"
3738 "sort"
3839 "strconv"
3940 "strings"
@@ -866,6 +867,8 @@ func setOf[T comparable](xs []T) map[T]struct{} {
866867 return set
867868}
868869
870+ var _errtraceSkip = regexp .MustCompile (`(^| )//errtrace:skip($|[ \(])` )
871+
869872// optoutLines returns the line numbers
870873// that have a comment in the form:
871874//
@@ -880,11 +883,15 @@ func optoutLines(
880883) map [int ]int {
881884 lines := make (map [int ]int )
882885 for _ , cg := range comments {
883- for _ , c := range cg .List {
884- if strings .Contains (c .Text , "//errtrace:skip" ) {
885- lineNo := fset .Position (c .Pos ()).Line
886- lines [lineNo ] = 0
887- }
886+ if len (cg .List ) > 1 {
887+ // skip multiline comments which are full line comments, not tied to a return.
888+ continue
889+ }
890+
891+ c := cg .List [0 ]
892+ if _errtraceSkip .MatchString (c .Text ) {
893+ lineNo := fset .Position (c .Pos ()).Line
894+ lines [lineNo ] = 0
888895 }
889896 }
890897 return lines
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ func Try(problem bool) (int, error) {
1515 return errors .New ("great sadness" )
1616 }
1717
18- return io .EOF //errtrace:skip // expects io.EOF
18+ return io .EOF //nolint:errwrap //errtrace:skip( expects io.EOF)
1919 })
2020 if err != nil {
2121 return 0 , err
@@ -32,3 +32,15 @@ func multipleReturns() (a, b error) {
3232 return errors .New ("a" ),
3333 errors .New ("b" ) //errtrace:skip
3434}
35+
36+ func multipleReturnsSkipped () (a , b error ) {
37+ return errors .New ("a" ), //errtrace:skip
38+ errors .New ("b" ) //errtrace:skip
39+ }
40+
41+ // Explanation of why this function
42+ // is not using //errtrace:skip should not
43+ // trip up the warning.
44+ func notUsingSkip () error {
45+ return nil
46+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ func Try(problem bool) (int, error) {
1515 return errtrace.Wrap(errors.New("great sadness"))
1616 }
1717
18- return io.EOF //errtrace:skip // expects io.EOF
18+ return io.EOF //nolint:errwrap //errtrace:skip( expects io.EOF)
1919 })
2020 if err != nil {
2121 return 0, errtrace.Wrap(err)
@@ -32,3 +32,15 @@ func multipleReturns() (a, b error) {
3232 return errtrace.Wrap(errors.New("a")),
3333 errors.New("b") //errtrace:skip
3434}
35+
36+ func multipleReturnsSkipped() (a, b error) {
37+ return errors.New("a"), //errtrace:skip
38+ errors.New("b") //errtrace:skip
39+ }
40+
41+ // Explanation of why this function
42+ // is not using //errtrace:skip should not
43+ // trip up the warning.
44+ func notUsingSkip() error {
45+ return nil
46+ }
You can’t perform that action at this time.
0 commit comments