diff --git a/fixtures/golint/indent-error-flow.go b/fixtures/golint/indent-error-flow.go index e0a7d8c..5d2fa19 100644 --- a/fixtures/golint/indent-error-flow.go +++ b/fixtures/golint/indent-error-flow.go @@ -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!" + } + } +} + diff --git a/rule/indent-error-flow.go b/rule/indent-error-flow.go index 3a02ba5..c4621ea 100644 --- a/rule/indent-error-flow.go +++ b/rule/indent-error-flow.go @@ -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 } +