Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve #37: ignore comment directives from nested switches #38

Merged
merged 1 commit into from Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
}
}
}