definition:
|
checkIfThenElse' :: SpanInfo -> SpanInfo -> SpanInfo -> SpanInfo -> CSM ()
checkIfThenElse' sI0 sI1 sI2 sI3 = case (sI0, sI1, sI2, sI3) of
(SpanInfo sp [ Span (Position lpi pi) _, Span (Position lpt pt) _, Span (Position lpe pe) _],
SpanInfo (Span _ (Position li _)) _,
SpanInfo (Span _ (Position lt _)) _,
SpanInfo (Span _ (Position le _)) _)
| lpi == le -> return ()
| lpi == lpe -> do report (Message
sp
( text "wrong formatting"
<+> colorizeKey "else expression"
)
( text "do not break"
<+> colorizeKey " else expression"
<+> text "if writing"
<+> colorizeKey "if-then-else"
<+> text "in one line"
))
| lpi == lpt && lt /= lpe -> do checkIfThenElseInTwoLines sp pt pe
checkBreakIndent "then" lpt pt sI2
checkBreakIndent "else" lpe pe sI3
| lt == lpe -> do report (Message
sp
( text "wrong formatting"
<+> colorizeKey "else"
)
( colorizeKey "else"
<+> text " should start in seperate line"
))
| li == lpt -> do report (Message
sp
( text "wrong formatting"
<+> colorizeKey "then"
)
( colorizeKey "then"
<+> text " should start in seperate line"
))
| li /= lpt && lt /= lpe -> do checkIfThenElseInThreeLines sp pi pt pe
checkBreakIndent "if" lpi pi sI1
checkBreakIndent "then" lpt pt sI2
checkBreakIndent "else" lpe pe sI3
_ -> return ()
|
documentation:
|
-- Checks for various situations:
-- all in one line
-- if - else in one line, else expression not
-- if - then in one line, else and else expression in another -> twolines
-- if - then in one line, then expression and else in one
-- if and then not in one line, if expression and then in one
-- if then else in different lines, if and then expressions not right in front
-- if then and else
|