diff --git a/switch.go b/switch.go index e8e6ad5..c3e3b55 100644 --- a/switch.go +++ b/switch.go @@ -70,7 +70,7 @@ func switchStmtChecker(pass *analysis.Pass, cfg config) nodeVisitor { if _, ok := comments[file]; !ok { comments[file] = ast.NewCommentMap(pass.Fset, file, file.Comments) } - if containsIgnoreDirective(comments[file].Filter(sw).Comments()) { + if containsIgnoreDirective(comments[file][sw]) { // Skip checking of this switch statement due to ignore directive comment. // Still return true because there may be nested switch statements // that are not to be ignored. diff --git a/testdata/src/ignore-comment/ignore_comment.go b/testdata/src/ignore-comment/ignore_comment.go index a6c6e5c..4a48f51 100644 --- a/testdata/src/ignore-comment/ignore_comment.go +++ b/testdata/src/ignore-comment/ignore_comment.go @@ -27,7 +27,8 @@ func _b() { var d Direction // this should not report. - switch d { //exhaustive:ignore + //exhaustive:ignore + switch d { case N: case S: case W: @@ -47,7 +48,8 @@ func _nested() { var d Direction // this should not report. - switch d { //exhaustive:ignore + //exhaustive:ignore + switch d { case N: case S: case W: @@ -61,3 +63,23 @@ func _nested() { } } } + +func _reverse_nested() { + var d Direction + + // this should report. + switch d { // want "^missing cases in switch of type Direction: E, directionInvalid$" + case N: + case S: + case W: + default: + // this should not report. + //exhaustive:ignore + switch d { + case N: + case S: + case W: + default: + } + } +}