Skip to content

Commit fa5bdad

Browse files
committed
Fix #622 Handle multi-line value for field description
1 parent 32c4986 commit fa5bdad

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
## Changes in 0.38.3
1+
## Changes in 0.38.4
22
- Accept a list for `category` (see #624)
33

4+
## Changes in 0.38.3
5+
- Handle a multi-line value for the `description` key of a flag (see #623)
6+
47
## Changes in 0.38.2
58
- Infer `cabal-version: 3.12` when `PackageInfo_*` is used (see #620)
69

hpack.cabal

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
spec-version: 0.36.0
22
name: hpack
3-
version: 0.38.3
3+
version: 0.38.4
44
synopsis: A modern format for Haskell packages
55
description: See README at <https://github.com/sol/hpack#readme>
66
author: Simon Hengel <[email protected]>

src/Hpack/Render.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ renderPackageWith settings headerFieldsAlignment existingFieldOrder sectionsFiel
104104
return $ concat [
105105
sourceRepository
106106
, customSetup
107-
, map renderFlag packageFlags
107+
, map (renderFlag packageCabalVersion) packageFlags
108108
, library
109109
, internalLibraries
110110
, executables
@@ -151,13 +151,16 @@ sortStanzaFields sectionsFieldOrder = go
151151
Stanza name fields : xs | Just fieldOrder <- lookup name sectionsFieldOrder -> Stanza name (sortFieldsBy fieldOrder fields) : go xs
152152
x : xs -> x : go xs
153153

154+
descriptionFieldSize :: Int
155+
descriptionFieldSize = length ("description: " :: String)
156+
154157
formatDescription :: CabalVersion -> Alignment -> String -> String
155158
formatDescription cabalVersion (Alignment alignment) description = case map emptyLineToDot $ lines description of
156159
x : xs -> intercalate "\n" (x : indent xs)
157160
[] -> ""
158161
where
159162
n :: Int
160-
n = max alignment (length ("description: " :: String))
163+
n = max alignment descriptionFieldSize
161164

162165
indentation :: String
163166
indentation = replicate n ' '
@@ -185,13 +188,17 @@ renderSourceRepository SourceRepository{..} = Stanza "source-repository head" [
185188
, Field "subdir" (maybe "" Literal sourceRepositorySubdir)
186189
]
187190

188-
renderFlag :: Flag -> Element
189-
renderFlag Flag {..} = Stanza ("flag " ++ flagName) $ description ++ [
191+
renderFlag :: CabalVersion -> Flag -> Element
192+
renderFlag cabalVersion Flag {..} = Stanza ("flag " ++ flagName) $ description ++ [
190193
Field "manual" (Literal $ show flagManual)
191194
, Field "default" (Literal $ show flagDefault)
192195
]
193196
where
194-
description = maybe [] (return . Field "description" . Literal) flagDescription
197+
description = maybe [] (return . Field "description" . Literal) formattedFlagDescription
198+
-- We have to 'hard code' that the flag stanza's description field is
199+
-- indented by two spaces:
200+
alignment = Alignment (descriptionFieldSize + 2)
201+
formattedFlagDescription = formatDescription cabalVersion alignment <$> flagDescription
195202

196203
renderInternalLibraries :: Map String (Section Library) -> RenderM [Element]
197204
renderInternalLibraries = traverse renderInternalLibrary . Map.toList

test/Hpack/RenderSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ spec = do
274274
describe "renderFlag" $ do
275275
it "renders flags" $ do
276276
let flag = (Flag "foo" (Just "some flag") True False)
277-
render defaultRenderSettings 0 (renderFlag flag) `shouldBe` [
277+
render defaultRenderSettings 0 (renderFlag cabalVersion flag) `shouldBe` [
278278
"flag foo"
279279
, " description: some flag"
280280
, " manual: True"

0 commit comments

Comments
 (0)