Skip to content

Commit

Permalink
resolve #37: ignore comment directives from nested switches (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
FastNav committed Mar 7, 2022
1 parent c61cda0 commit c8d4046
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion switch.go
Expand Up @@ -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.
Expand Down
26 changes: 24 additions & 2 deletions testdata/src/ignore-comment/ignore_comment.go
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
}
}
}

0 comments on commit c8d4046

Please sign in to comment.