File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -30,18 +30,19 @@ func ParseIgnore(doc *ast.CommentGroup) *Ignore {
3030 }
3131
3232 for _ , comment := range doc .List {
33- if ! strings .HasPrefix (comment .Text , "//iface:ignore" ) {
34- continue
33+ text := strings .TrimSpace (comment .Text )
34+ if text == "//iface:ignore" {
35+ return & Ignore {}
3536 }
3637
3738 // parse the Names if exists
38- if strings .Contains ( comment . Text , "=" ) {
39- parts : = strings .Split ( comment . Text , "=" )
40- if len ( parts ) != 2 {
41- continue
39+ if val , found := strings .CutPrefix ( text , "//iface:ignore =" ); found {
40+ val = strings .TrimSpace ( val )
41+ if val == "" {
42+ return & Ignore {}
4243 }
4344
44- names := strings .Split (parts [ 1 ] , "," )
45+ names := strings .Split (val , "," )
4546 if len (names ) == 0 {
4647 continue
4748 }
@@ -53,9 +54,9 @@ func ParseIgnore(doc *ast.CommentGroup) *Ignore {
5354 if len (names ) > 0 {
5455 return & Ignore {Names : names }
5556 }
56- }
5757
58- return & Ignore {}
58+ return & Ignore {}
59+ }
5960 }
6061
6162 return nil
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ func TestParseIgnore(t *testing.T) {
3232 },
3333 },
3434 },
35+ dir : nil ,
3536 },
3637 "directive with one name" : {
3738 doc : & ast.CommentGroup {
@@ -57,6 +58,26 @@ func TestParseIgnore(t *testing.T) {
5758 Names : []string {"unused" , "identical" },
5859 },
5960 },
61+ "directive with weird assignment" : {
62+ doc : & ast.CommentGroup {
63+ List : []* ast.Comment {
64+ {
65+ Text : "//iface:ignore-asd=unused" ,
66+ },
67+ },
68+ },
69+ dir : nil ,
70+ },
71+ "directive empty val" : {
72+ doc : & ast.CommentGroup {
73+ List : []* ast.Comment {
74+ {
75+ Text : "//iface:ignore=" ,
76+ },
77+ },
78+ },
79+ dir : & directive.Ignore {},
80+ },
6081 }
6182
6283 for name , tc := range testCases {
You can’t perform that action at this time.
0 commit comments