diff --git a/bin/src/Bin/FormatOptions.purs b/bin/src/Bin/FormatOptions.purs index 4891496..7494335 100644 --- a/bin/src/Bin/FormatOptions.purs +++ b/bin/src/Bin/FormatOptions.purs @@ -13,7 +13,7 @@ import Data.Argonaut.Encode (assoc, encodeJson, extend) import Data.Either (Either) import Data.Maybe (Maybe(..), fromMaybe, maybe) import Data.Traversable (traverse) -import Tidy (ImportSortOption(..), ImportWrapOption(..), TypeArrowOption(..), UnicodeOption(..)) +import Tidy (ImportSortOption(..), ImportWrapOption(..), ThenPlacementOption(..), TypeArrowOption(..), UnicodeOption(..)) type FormatOptions = { importSort :: ImportSortOption @@ -21,6 +21,7 @@ type FormatOptions = , indent :: Int , operatorsFile :: Maybe String , ribbon :: Number + , thenPlacement :: ThenPlacementOption , typeArrowPlacement :: TypeArrowOption , unicode :: UnicodeOption , width :: Maybe Int @@ -33,6 +34,7 @@ defaults = , indent: 2 , operatorsFile: Nothing , ribbon: 1.0 + , thenPlacement: ThenSameLine , typeArrowPlacement: TypeArrowFirst , unicode: UnicodeSource , width: Nothing @@ -76,6 +78,16 @@ formatOptions = "The ratio of printable width to maximum width.\nFrom 0 to 1. Defaults to 1." # Arg.number # Arg.default defaults.ribbon + , thenPlacement: + Arg.choose "then placement" + [ Arg.flag [ "--then-same-line", "-tsl" ] + "Then keyword is placed on the same line as the if condition.\nDefault." + $> ThenSameLine + , Arg.flag [ "--then-new-line", "-tnl" ] + "Then keyword is placed on a new line." + $> ThenNewLine + ] + # Arg.default defaults.thenPlacement , typeArrowPlacement: Arg.choose "type arrow placement" [ Arg.flag [ "--arrow-first", "-af" ] @@ -117,6 +129,7 @@ fromJson json = do indent <- obj .:? "indent" operatorsFile <- obj .:? "operatorsFile" ribbon <- obj .:? "ribbon" + thenPlacement <- traverse thenPlacementFromString =<< obj .:? "thenPlacement" typeArrowPlacement <- traverse typeArrowPlacementFromString =<< obj .:? "typeArrowPlacement" unicode <- traverse unicodeFromString =<< obj .:? "unicode" width <- obj .:? "width" @@ -126,6 +139,7 @@ fromJson json = do , indent: fromMaybe defaults.indent indent , operatorsFile: operatorsFile <|> defaults.operatorsFile , ribbon: fromMaybe defaults.ribbon ribbon + , thenPlacement: fromMaybe defaults.thenPlacement thenPlacement , typeArrowPlacement: fromMaybe defaults.typeArrowPlacement typeArrowPlacement , unicode: fromMaybe defaults.unicode unicode , width: width <|> defaults.width @@ -139,10 +153,22 @@ toJson options = # extend (assoc "indent" options.indent) # extend (assoc "operatorsFile" (maybe jsonNull encodeJson options.operatorsFile)) # extend (assoc "ribbon" options.ribbon) + # extend (assoc "thenPlacement" (thenPlacementToString options.thenPlacement)) # extend (assoc "typeArrowPlacement" (typeArrowPlacementToString options.typeArrowPlacement)) # extend (assoc "unicode" (unicodeToString options.unicode)) # extend (assoc "width" (maybe jsonNull encodeJson options.width)) +thenPlacementFromString :: String -> Either JsonDecodeError ThenPlacementOption +thenPlacementFromString = case _ of + "same-line" -> pure ThenSameLine + "new-line" -> pure ThenNewLine + other -> throwError $ UnexpectedValue (Json.fromString other) + +thenPlacementToString :: ThenPlacementOption -> String +thenPlacementToString = case _ of + ThenSameLine -> "same-line" + ThenNewLine -> "new-line" + typeArrowPlacementFromString :: String -> Either JsonDecodeError TypeArrowOption typeArrowPlacementFromString = case _ of "first" -> pure TypeArrowFirst diff --git a/bin/src/Bin/Worker.purs b/bin/src/Bin/Worker.purs index 1602cba..ed4da08 100644 --- a/bin/src/Bin/Worker.purs +++ b/bin/src/Bin/Worker.purs @@ -37,6 +37,7 @@ type WorkerConfig = , indent :: Int , operatorsFile :: String , ribbon :: Number + , thenPlacement :: String , typeArrowPlacement :: String , unicode :: String , width :: Int @@ -49,6 +50,7 @@ toWorkerConfig options = , indent: options.indent , operatorsFile: fromMaybe ".tidyoperators.default" options.operatorsFile , ribbon: options.ribbon + , thenPlacement: FormatOptions.thenPlacementToString options.thenPlacement , typeArrowPlacement: FormatOptions.typeArrowPlacementToString options.typeArrowPlacement , unicode: FormatOptions.unicodeToString options.unicode , width: fromMaybe top options.width @@ -88,6 +90,7 @@ formatCommand args operators contents = do { importSort = args.importSort , importWrap = args.importWrap , operators = remapOperators operators ok + , thenPlacement = args.thenPlacement , typeArrowPlacement = args.typeArrowPlacement , unicode = args.unicode } @@ -115,6 +118,9 @@ formatInPlaceCommand shouldCheck operators { filePath, config } = do , indent: config.indent , operatorsFile: Nothing , ribbon: config.ribbon + , thenPlacement: + fromRight' (\_ -> unsafeCrashWith "Unknown thenPlacement value") do + FormatOptions.thenPlacementFromString config.thenPlacement , typeArrowPlacement: fromRight' (\_ -> unsafeCrashWith "Unknown typeArrowPlacement value") do FormatOptions.typeArrowPlacementFromString config.typeArrowPlacement diff --git a/src/Tidy.purs b/src/Tidy.purs index 72361be..f885f59 100644 --- a/src/Tidy.purs +++ b/src/Tidy.purs @@ -2,6 +2,7 @@ module Tidy ( FormatOptions , defaultFormatOptions , TypeArrowOption(..) + , ThenPlacementOption(..) , ImportSortOption(..) , ImportWrapOption(..) , Format @@ -50,6 +51,12 @@ data TypeArrowOption derive instance eqTypeArrowOption :: Eq TypeArrowOption +data ThenPlacementOption + = ThenSameLine + | ThenNewLine + +derive instance eqThenPlacementOption :: Eq ThenPlacementOption + data ImportWrapOption = ImportWrapSource | ImportWrapAuto @@ -66,6 +73,7 @@ type FormatOptions e a = { formatError :: e -> FormatDoc a , unicode :: UnicodeOption , typeArrowPlacement :: TypeArrowOption + , thenPlacement :: ThenPlacementOption , operators :: PrecedenceMap , importSort :: ImportSortOption , importWrap :: ImportWrapOption @@ -76,6 +84,7 @@ defaultFormatOptions = { formatError , unicode: UnicodeSource , typeArrowPlacement: TypeArrowFirst + , thenPlacement: ThenSameLine , operators: Map.empty , importSort: ImportSortSource , importWrap: ImportWrapSource @@ -991,19 +1000,37 @@ toElseIfChain ifte = go (pure (IfThen ifte.keyword ifte.cond ifte.then ifte.true formatElseIfChain :: forall e a. Format (NonEmptyArray (ElseIfChain e)) e a formatElseIfChain conf = flexGroup <<< joinWithMap spaceBreak case _ of IfThen kw1 cond kw2 expr -> - formatToken conf kw1 - `flexSpaceBreak` - indent (anchor (flexGroup (formatExpr conf cond))) - `space` - Hang.toFormatDoc (anchor (formatToken conf kw2) `hang` formatHangingExpr conf expr) + case conf.thenPlacement of + ThenSameLine -> + formatToken conf kw1 + `flexSpaceBreak` + indent (anchor (flexGroup (formatExpr conf cond))) + `space` + Hang.toFormatDoc (anchor (formatToken conf kw2) `hang` formatHangingExpr conf expr) + ThenNewLine -> + formatToken conf kw1 + `flexSpaceBreak` + indent (anchor (flexGroup (formatExpr conf cond))) + `break` + Hang.toFormatDoc (anchor (formatToken conf kw2) `hang` formatHangingExpr conf expr) ElseIfThen kw1 kw2 cond kw3 expr -> - formatToken conf kw1 - `space` - indent (anchor (formatToken conf kw2)) - `flexSpaceBreak` - indent (anchor (flexGroup (formatExpr conf cond))) - `space` - Hang.toFormatDoc (anchor (formatToken conf kw3) `hang` formatHangingExpr conf expr) + case conf.thenPlacement of + ThenSameLine -> + formatToken conf kw1 + `space` + indent (anchor (formatToken conf kw2)) + `flexSpaceBreak` + indent (anchor (flexGroup (formatExpr conf cond))) + `space` + Hang.toFormatDoc (anchor (formatToken conf kw3) `hang` formatHangingExpr conf expr) + ThenNewLine -> + formatToken conf kw1 + `space` + indent (anchor (formatToken conf kw2)) + `flexSpaceBreak` + indent (anchor (flexGroup (formatExpr conf cond))) + `break` + Hang.toFormatDoc (anchor (formatToken conf kw3) `hang` formatHangingExpr conf expr) Else kw1 expr -> Hang.toFormatDoc (formatToken conf kw1 `hang` formatHangingExpr conf expr) diff --git a/test/FormatDirective.purs b/test/FormatDirective.purs index 4de84ca..5a286d8 100644 --- a/test/FormatDirective.purs +++ b/test/FormatDirective.purs @@ -111,6 +111,7 @@ parseDirectivesFromModule (Module { header: ModuleHeader header, body }) = { formatError: default.formatError , operators: default.operators , unicode: opts.unicode + , thenPlacement: opts.thenPlacement , typeArrowPlacement: opts.typeArrowPlacement , importSort: opts.importSort , importWrap: opts.importWrap diff --git a/test/snapshots/ThenPlacementComparison.input b/test/snapshots/ThenPlacementComparison.input new file mode 100644 index 0000000..d37d2f0 --- /dev/null +++ b/test/snapshots/ThenPlacementComparison.input @@ -0,0 +1,16 @@ +-- @format --then-same-line --width 40 +module ThenPlacementComparison where + +-- This should trigger the difference with narrow width +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrap + then shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition + then if secondLongCondition + then result1 + else result2 + else alternativeResult diff --git a/test/snapshots/ThenPlacementComparison.output b/test/snapshots/ThenPlacementComparison.output new file mode 100644 index 0000000..aa48bf7 --- /dev/null +++ b/test/snapshots/ThenPlacementComparison.output @@ -0,0 +1,29 @@ +module ThenPlacementComparison where + +-- This should trigger the difference with narrow width +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrap then shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition then + if secondLongCondition then result1 + else result2 + else alternativeResult +-- @format --then-same-line --width 40 +module ThenPlacementComparison where + +-- This should trigger the difference with narrow width +test1 = + if + someVeryLongConditionExpressionThatWillDefinitelyWrap then + shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition then + if secondLongCondition then result1 + else result2 + else alternativeResult diff --git a/test/snapshots/ThenPlacementDifference.input b/test/snapshots/ThenPlacementDifference.input new file mode 100644 index 0000000..14e56cf --- /dev/null +++ b/test/snapshots/ThenPlacementDifference.input @@ -0,0 +1,16 @@ +-- @format --then-new-line --width 40 +module ThenPlacementDifference where + +-- This should trigger the difference with narrow width +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrap + then shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition + then if secondLongCondition + then result1 + else result2 + else alternativeResult diff --git a/test/snapshots/ThenPlacementDifference.output b/test/snapshots/ThenPlacementDifference.output new file mode 100644 index 0000000..f71939e --- /dev/null +++ b/test/snapshots/ThenPlacementDifference.output @@ -0,0 +1,31 @@ +module ThenPlacementDifference where + +-- This should trigger the difference with narrow width +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrap then shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition then + if secondLongCondition then result1 + else result2 + else alternativeResult +-- @format --then-new-line --width 40 +module ThenPlacementDifference where + +-- This should trigger the difference with narrow width +test1 = + if + someVeryLongConditionExpressionThatWillDefinitelyWrap + then shortResult + else alternativeValue + +-- This should also show the difference +test2 = + if firstLongCondition + then + if secondLongCondition + then result1 + else result2 + else alternativeResult diff --git a/test/snapshots/ThenPlacementNewLine.input b/test/snapshots/ThenPlacementNewLine.input new file mode 100644 index 0000000..c7a0646 --- /dev/null +++ b/test/snapshots/ThenPlacementNewLine.input @@ -0,0 +1,56 @@ +-- @format --then-new-line +module ThenPlacementNewLine where + +-- Simple if-then-else +simple = if condition then result else alternative + +-- Nested if-then-else +nested = if a then b else if x then y else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap + then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition + then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition + then if secondCondition + then firstResult + else if thirdCondition + then secondResult + else thirdResult + else if fourthCondition + then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = if guard then guardedResult else defaultResult + | otherwise = if alternativeGuard then alternativeResult else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value + then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) + then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) diff --git a/test/snapshots/ThenPlacementNewLine.output b/test/snapshots/ThenPlacementNewLine.output new file mode 100644 index 0000000..fcfcf5a --- /dev/null +++ b/test/snapshots/ThenPlacementNewLine.output @@ -0,0 +1,119 @@ +module ThenPlacementNewLine where + +-- Simple if-then-else +simple = if condition then result else alternative + +-- Nested if-then-else +nested = if a then b else if x then y else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition then + if secondCondition then firstResult + else if thirdCondition then secondResult + else thirdResult + else if fourthCondition then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = if guard then guardedResult else defaultResult + | otherwise = if alternativeGuard then alternativeResult else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) +-- @format --then-new-line +module ThenPlacementNewLine where + +-- Simple if-then-else +simple = + if condition + then result + else alternative + +-- Nested if-then-else +nested = + if a + then b + else if x + then y + else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap + then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition + then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition + then + if secondCondition + then firstResult + else if thirdCondition + then secondResult + else thirdResult + else if fourthCondition + then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = + if guard + then guardedResult + else defaultResult + | otherwise = + if alternativeGuard + then alternativeResult + else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value + then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) + then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) diff --git a/test/snapshots/ThenPlacementNewLineDetailed.input b/test/snapshots/ThenPlacementNewLineDetailed.input new file mode 100644 index 0000000..5257e0d --- /dev/null +++ b/test/snapshots/ThenPlacementNewLineDetailed.input @@ -0,0 +1,28 @@ +-- @format --then-new-line +module ThenPlacementNewLineDetailed where + +-- Case that should show difference: multi-line condition with then on new line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine + then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition + then if secondCondition + then firstResult + else secondAlternative + else if thirdCondition + then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 + then value1 + else if condition2 + then value2 + else if condition3 + then value3 + else defaultValue diff --git a/test/snapshots/ThenPlacementNewLineDetailed.output b/test/snapshots/ThenPlacementNewLineDetailed.output new file mode 100644 index 0000000..a83f435 --- /dev/null +++ b/test/snapshots/ThenPlacementNewLineDetailed.output @@ -0,0 +1,50 @@ +module ThenPlacementNewLineDetailed where + +-- Case that should show difference: multi-line condition with then on new line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition then + if secondCondition then firstResult + else secondAlternative + else if thirdCondition then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 then value1 + else if condition2 then value2 + else if condition3 then value3 + else defaultValue +-- @format --then-new-line +module ThenPlacementNewLineDetailed where + +-- Case that should show difference: multi-line condition with then on new line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine + then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition + then + if secondCondition + then firstResult + else secondAlternative + else if thirdCondition + then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 + then value1 + else if condition2 + then value2 + else if condition3 + then value3 + else defaultValue diff --git a/test/snapshots/ThenPlacementSameLine.input b/test/snapshots/ThenPlacementSameLine.input new file mode 100644 index 0000000..3f38614 --- /dev/null +++ b/test/snapshots/ThenPlacementSameLine.input @@ -0,0 +1,56 @@ +-- @format --then-same-line +module ThenPlacementSameLine where + +-- Simple if-then-else +simple = if condition then result else alternative + +-- Nested if-then-else +nested = if a then b else if x then y else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap + then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition + then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition + then if secondCondition + then firstResult + else if thirdCondition + then secondResult + else thirdResult + else if fourthCondition + then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = if guard then guardedResult else defaultResult + | otherwise = if alternativeGuard then alternativeResult else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value + then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) + then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) diff --git a/test/snapshots/ThenPlacementSameLine.output b/test/snapshots/ThenPlacementSameLine.output new file mode 100644 index 0000000..0ceae2b --- /dev/null +++ b/test/snapshots/ThenPlacementSameLine.output @@ -0,0 +1,97 @@ +module ThenPlacementSameLine where + +-- Simple if-then-else +simple = if condition then result else alternative + +-- Nested if-then-else +nested = if a then b else if x then y else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition then + if secondCondition then firstResult + else if thirdCondition then secondResult + else thirdResult + else if fourthCondition then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = if guard then guardedResult else defaultResult + | otherwise = if alternativeGuard then alternativeResult else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) +-- @format --then-same-line +module ThenPlacementSameLine where + +-- Simple if-then-else +simple = if condition then result else alternative + +-- Nested if-then-else +nested = if a then b else if x then y else z + +-- Multi-line condition +multilineCondition = + if someVeryLongConditionThatSpansMultipleLinesAndNeedsToWrap then shortResult + else alternativeResult + +-- Multi-line then/else branches +multilineBranches = + if condition then do + action1 + action2 + result + else do + alternativeAction1 + alternativeAction2 + alternativeResult + +-- Complex nested case +complexNested = + if firstCondition then + if secondCondition then firstResult + else if thirdCondition then secondResult + else thirdResult + else if fourthCondition then fourthResult + else finalResult + +-- With guards +withGuards x y + | condition = if guard then guardedResult else defaultResult + | otherwise = if alternativeGuard then alternativeResult else fallback + +-- In do blocks +inDoBlock = do + value <- computation + if isValid value then pure value + else throwError "Invalid value" + +-- With complex expressions +complexExpressions = + if (someFunction arg1 arg2 >>= anotherFunction) then (complexResult >>= transform >>= validate) + else (fallbackComputation >>= handleError) diff --git a/test/snapshots/ThenPlacementSameLineDetailed.input b/test/snapshots/ThenPlacementSameLineDetailed.input new file mode 100644 index 0000000..3e334b1 --- /dev/null +++ b/test/snapshots/ThenPlacementSameLineDetailed.input @@ -0,0 +1,28 @@ +-- @format --then-same-line +module ThenPlacementSameLineDetailed where + +-- Case that should show difference: multi-line condition with then on same line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine + then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition + then if secondCondition + then firstResult + else secondAlternative + else if thirdCondition + then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 + then value1 + else if condition2 + then value2 + else if condition3 + then value3 + else defaultValue diff --git a/test/snapshots/ThenPlacementSameLineDetailed.output b/test/snapshots/ThenPlacementSameLineDetailed.output new file mode 100644 index 0000000..9baccdf --- /dev/null +++ b/test/snapshots/ThenPlacementSameLineDetailed.output @@ -0,0 +1,43 @@ +module ThenPlacementSameLineDetailed where + +-- Case that should show difference: multi-line condition with then on same line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition then + if secondCondition then firstResult + else secondAlternative + else if thirdCondition then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 then value1 + else if condition2 then value2 + else if condition3 then value3 + else defaultValue +-- @format --then-same-line +module ThenPlacementSameLineDetailed where + +-- Case that should show difference: multi-line condition with then on same line +test1 = + if someVeryLongConditionExpressionThatWillDefinitelyWrapToNextLine then result + else alternative + +-- Nested case that should show the difference +test2 = + if firstCondition then + if secondCondition then firstResult + else secondAlternative + else if thirdCondition then thirdResult + else finalAlternative + +-- Chain of if-then-else that should trigger the placement difference +test3 = + if condition1 then value1 + else if condition2 then value2 + else if condition3 then value3 + else defaultValue