1
0
mirror of https://github.com/mgechev/revive.git synced 2025-10-30 23:37:49 +02:00

useless-fallthrough: do not report fallthrough before default (#1549)

Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
This commit is contained in:
Anupriya
2025-10-24 22:05:19 +05:30
committed by GitHub
parent 26d803fc96
commit cc04b177a4
2 changed files with 7 additions and 7 deletions

View File

@@ -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.

View File

@@ -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:
@@ -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()
}
@@ -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()
}