Skip to content

Commit c8d4046

Browse files
authored
resolve #37: ignore comment directives from nested switches (#38)
1 parent c61cda0 commit c8d4046

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

switch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func switchStmtChecker(pass *analysis.Pass, cfg config) nodeVisitor {
7070
if _, ok := comments[file]; !ok {
7171
comments[file] = ast.NewCommentMap(pass.Fset, file, file.Comments)
7272
}
73-
if containsIgnoreDirective(comments[file].Filter(sw).Comments()) {
73+
if containsIgnoreDirective(comments[file][sw]) {
7474
// Skip checking of this switch statement due to ignore directive comment.
7575
// Still return true because there may be nested switch statements
7676
// that are not to be ignored.

testdata/src/ignore-comment/ignore_comment.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func _b() {
2727
var d Direction
2828

2929
// this should not report.
30-
switch d { //exhaustive:ignore
30+
//exhaustive:ignore
31+
switch d {
3132
case N:
3233
case S:
3334
case W:
@@ -47,7 +48,8 @@ func _nested() {
4748
var d Direction
4849

4950
// this should not report.
50-
switch d { //exhaustive:ignore
51+
//exhaustive:ignore
52+
switch d {
5153
case N:
5254
case S:
5355
case W:
@@ -61,3 +63,23 @@ func _nested() {
6163
}
6264
}
6365
}
66+
67+
func _reverse_nested() {
68+
var d Direction
69+
70+
// this should report.
71+
switch d { // want "^missing cases in switch of type Direction: E, directionInvalid$"
72+
case N:
73+
case S:
74+
case W:
75+
default:
76+
// this should not report.
77+
//exhaustive:ignore
78+
switch d {
79+
case N:
80+
case S:
81+
case W:
82+
default:
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)