1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-10 03:17:11 +02:00

Fix issue19 (#20)

* Adds rule superfluous-else (an extension of indent-error-flow)

* Fix superfluous-else rule struct namming.

* Adds superfuous-else rule to the rules table

* fix issue 19
This commit is contained in:
chavacava 2018-06-13 16:01:31 +02:00 committed by Minko Gechev
parent c9bde6c503
commit 4e19174270
2 changed files with 21 additions and 0 deletions

View File

@ -21,3 +21,20 @@ func g(f func() bool) string {
return "it's NOT okay!"
}
}
func h(f func() bool, x int) string {
if err == author.ErrCourseNotFound {
return
} else if err == author.ErrCourseAccess {
// side effect
} else if err == author.AnotherError {
return "okay"
} else {
if ok := f(); ok {
return "it's okay"
} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)/
return "it's NOT okay!"
}
}
}

View File

@ -39,6 +39,9 @@ func (w lintElse) Visit(node ast.Node) ast.Visitor {
return w
}
if w.ignore[ifStmt] {
if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok {
w.ignore[elseif] = true
}
return w
}
if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok {
@ -74,3 +77,4 @@ func (w lintElse) Visit(node ast.Node) ast.Visitor {
}
return w
}