@@ -64,18 +64,9 @@ fieldD
6464 -> WriteOpts
6565 -> PrettyField FieldAnnotation
6666fieldD fieldName fieldContents fieldComments includeField opts
67- | fieldContents == empty =
68- -- If there is no content, optionally produce a commented out field.
69- fieldSEmptyContents $ CommentBefore fieldComments
70- | otherwise =
71- -- If the "--no-comments" or "--minimal" flag is set, strip comments.
72- let comments
73- | isMinimal = []
74- | hasNoComments = []
75- | otherwise = fieldComments
76-
77- -- If the "--minimal" flag is set, strip comments.
78- in fieldSWithContents comments
67+ -- If the "--no-comments" or "--minimal" flag is set, strip comments.
68+ | hasNoComments || isMinimal = contents NoComment
69+ | otherwise = contents $ commentPositionFor fieldName fieldComments
7970 where
8071 commentPositionFor fn
8172 | fn == " cabal-version" = CommentAfter
@@ -84,6 +75,11 @@ fieldD fieldName fieldContents fieldComments includeField opts
8475 isMinimal = _optMinimal opts
8576 hasNoComments = _optNoComments opts
8677
78+ contents
79+ -- If there is no content, optionally produce a commented out field.
80+ | fieldContents == empty = fieldSEmptyContents
81+ | otherwise = fieldSWithContents
82+
8783 fieldSEmptyContents cs
8884 | not includeField || isMinimal = PrettyEmpty
8985 | otherwise = PrettyField
@@ -92,7 +88,7 @@ fieldD fieldName fieldContents fieldComments includeField opts
9288 empty
9389
9490 fieldSWithContents cs =
95- PrettyField (withComments . commentPositionFor fieldName $ map ( " -- " ++ ) cs) fieldName fieldContents
91+ PrettyField (withComments cs) fieldName fieldContents
9692
9793
9894-- | A field annotation instructing the pretty printer to comment out the field
@@ -104,7 +100,9 @@ commentedOutWithComments NoComment = FieldAnnotation True NoComment
104100
105101-- | A field annotation with the specified comment lines.
106102withComments :: CommentPosition -> FieldAnnotation
107- withComments = FieldAnnotation False
103+ withComments (CommentBefore cs) = FieldAnnotation False . CommentBefore $ map (" -- " ++ ) cs
104+ withComments (CommentAfter cs) = FieldAnnotation False . CommentAfter $ map (" -- " ++ ) cs
105+ withComments NoComment = FieldAnnotation False NoComment
108106
109107-- | A field annotation with no comments.
110108annNoComments :: FieldAnnotation
0 commit comments