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 {
30
30
}
31
31
32
32
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 {}
35
36
}
36
37
37
38
// 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 {}
42
43
}
43
44
44
- names := strings .Split (parts [ 1 ] , "," )
45
+ names := strings .Split (val , "," )
45
46
if len (names ) == 0 {
46
47
continue
47
48
}
@@ -53,9 +54,9 @@ func ParseIgnore(doc *ast.CommentGroup) *Ignore {
53
54
if len (names ) > 0 {
54
55
return & Ignore {Names : names }
55
56
}
56
- }
57
57
58
- return & Ignore {}
58
+ return & Ignore {}
59
+ }
59
60
}
60
61
61
62
return nil
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ func TestParseIgnore(t *testing.T) {
32
32
},
33
33
},
34
34
},
35
+ dir : nil ,
35
36
},
36
37
"directive with one name" : {
37
38
doc : & ast.CommentGroup {
@@ -57,6 +58,26 @@ func TestParseIgnore(t *testing.T) {
57
58
Names : []string {"unused" , "identical" },
58
59
},
59
60
},
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
+ },
60
81
}
61
82
62
83
for name , tc := range testCases {
You can’t perform that action at this time.
0 commit comments