Compare commits
6 Commits
03e578f72c
...
b9b15eed4b
Author | SHA1 | Date |
---|---|---|
|
b9b15eed4b | |
|
f985c6df69 | |
|
043b554a89 | |
|
4818566c83 | |
|
6b7526c360 | |
|
62fe073305 |
|
@ -1,27 +0,0 @@
|
|||
#group feature/minimize-parens
|
||||
|
||||
#golden minimize parens basic test
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func (abc) (def)
|
||||
#expected
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func abc def
|
||||
|
||||
#test minimize parens test that it keep necessary parens
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func (abc False) ("asd" ++ "def")
|
||||
|
||||
|
||||
#golden minimize nested parens 1
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func ((((((((nested))))))))
|
||||
#expected
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func nested
|
||||
|
||||
#golden minimize nested parens 2
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func ((((((((nested + expression))))))))
|
||||
#expected
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func (nested + expression)
|
|
@ -1060,6 +1060,13 @@ func = do
|
|||
)
|
||||
`shouldReturn` thing
|
||||
|
||||
#golden minimize parens basic test
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func (abc) (def)
|
||||
#expected
|
||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||
func = func abc def
|
||||
|
||||
#test wandering comment at end of datadecl
|
||||
data ReformatParenMode
|
||||
= ReformatParenModeKeep -- don't modify parens at all
|
||||
|
|
|
@ -184,14 +184,9 @@ addAllParens topLevelParen = \case
|
|||
|
||||
remSuperfluousParens :: Int -> OpTree -> OpTree
|
||||
remSuperfluousParens outerFixity = \case
|
||||
x@OpLeaf{} -> x
|
||||
OpUnknown _ locO locC c@(OpLeaf doc) [] | isLit doc ->
|
||||
OpUnknown NoParen locO locC c []
|
||||
OpUnknown _ locO locC c@(OpUnknown ParenWithSpace _ _ _ _) [] ->
|
||||
OpUnknown NoParen locO locC (remSuperfluousParens 11 c) []
|
||||
OpUnknown _ locO locC c@(OpUnknown ParenNoSpace _ _ _ _) [] ->
|
||||
OpUnknown NoParen locO locC (remSuperfluousParens 11 c) []
|
||||
x@OpUnknown{} -> x
|
||||
x@OpLeaf{} -> x
|
||||
OpUnknown _ locO locC c [] -> OpUnknown NoParen locO locC c []
|
||||
x@OpUnknown{} -> x
|
||||
OpKnown paren locO locC fixity c cs ->
|
||||
OpKnown
|
||||
-- We do not support removing superfluous parens around
|
||||
|
@ -205,22 +200,7 @@ remSuperfluousParens outerFixity = \case
|
|||
fixity
|
||||
(remSuperfluousParens (fixLevel fixity) c)
|
||||
[ (op, remSuperfluousParens (fixLevel fixity) tree) | (op, tree) <- cs ]
|
||||
where
|
||||
fixLevel (Fixity _ i _) = i
|
||||
isLit = \case
|
||||
(_, BDFlushCommentsPrior _ x ) -> isLit x
|
||||
(_, BDFlushCommentsPost _ _ x) -> isLit x
|
||||
(_, BDQueueComments _ x ) -> isLit x
|
||||
(_, BDEntryDelta _ x ) -> isLit x
|
||||
(_, BDForceAlt _ x ) -> isLit x
|
||||
(_, BDDebug _ x ) -> isLit x
|
||||
(_, BDAddBaseY _ x ) -> isLit x
|
||||
(_, BDBaseYPushCur x ) -> isLit x
|
||||
(_, BDIndentLevelPushCur x ) -> isLit x
|
||||
(_, BDIndentLevelPop x ) -> isLit x
|
||||
(_, BDLit{} ) -> True
|
||||
_ -> False
|
||||
|
||||
where fixLevel (Fixity _ i _) = i
|
||||
|
||||
hardcodedFixity :: Bool -> String -> Maybe Fixity
|
||||
hardcodedFixity allowUnqualify = \case
|
||||
|
|
|
@ -165,8 +165,8 @@ processOpTree (unknownTree, hasComments) = do
|
|||
PRMMinimize -> remSuperfluousParens 11 balancedTree
|
||||
PRMMaximize -> addAllParens NoParen balancedTree
|
||||
-- tellDebugMess $ displayOpTree unknownTree
|
||||
-- tellDebugMess $ displayOpTree balancedTree
|
||||
-- tellDebugMess $ displayOpTree processedTree
|
||||
tellDebugMess $ displayOpTree balancedTree
|
||||
tellDebugMess $ displayOpTree processedTree
|
||||
layoutOpTree (not hasComments) processedTree
|
||||
|
||||
layoutOpTree :: Bool -> OpTree -> ToBriDocM BriDocNumbered
|
||||
|
|
Loading…
Reference in New Issue