Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rule/useless_fallthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (w *lintUselessFallthrough) Visit(node ast.Node) ast.Visitor {

confidence := 1.0
if nextCaseClause := switchStmt.Body.List[i+1].(*ast.CaseClause); nextCaseClause.List == nil {
// the next case clause is the default clause, report with lower confidence.
confidence = 0.8
// The next clause is 'default:', and this is a valid pattern.
// Skip reporting this fallthrough.
continue
}
if _, ok := w.commentsMap[branchStmt]; ok {
// The fallthrough has a comment, report with lower confidence.
Expand Down
9 changes: 4 additions & 5 deletions testdata/useless_fallthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func uselessFallthrough() {

switch a {
case 0:
fallthrough // json:{"MATCH": "this \"fallthrough\" can be removed by consolidating this case clause with the next one","Confidence": 0.8}
fallthrough
default:
println()
}

switch a {
case 0:
fallthrough // json:{"MATCH": "this \"fallthrough\" can be removed by consolidating this case clause with the next one","Confidence": 0.8}
fallthrough
default:
println()
case 1:
Expand All @@ -47,8 +47,7 @@ func uselessFallthrough() {

switch a {
case 0:
// This a comment on the case, the confidence must be 0.5
fallthrough // json:{"MATCH": "this \"fallthrough\" can be removed by consolidating this case clause with the next one","Confidence": 0.5}
fallthrough
default:
println()
}
Expand All @@ -71,7 +70,7 @@ func uselessFallthrough() {
switch a {
case 0:
//foo:bar
fallthrough // json:{"MATCH": "this \"fallthrough\" can be removed by consolidating this case clause with the next one","Confidence": 0.5}
fallthrough
default:
println()
}
Expand Down