cabal-gild 1.3.4.0 → 1.4.0.0
raw patch · 3 files changed
+38/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ CabalGild.Unstable.Action.FormatFields: collectComments :: [FieldLine (p, [c])] -> [c]
+ CabalGild.Unstable.Action.FormatFields: floatComments :: p -> [FieldLine (p, [c])] -> [FieldLine (p, [c])]
Files
- cabal-gild.cabal +1/−1
- source/library/CabalGild/Unstable/Action/FormatFields.hs +24/−10
- source/test-suite/Main.hs +13/−3
cabal-gild.cabal view
@@ -11,7 +11,7 @@ maintainer: Taylor Fausak name: cabal-gild synopsis: Formats package descriptions.-version: 1.3.4.0+version: 1.4.0.0 source-repository head type: git
source/library/CabalGild/Unstable/Action/FormatFields.hs view
@@ -47,13 +47,13 @@ Fields.Field (p, [c]) -> Fields.Field (p, [c]) field csv f = case f of- Fields.Field n fls -> case Map.lookup (Name.value n) parsers of- Nothing -> f- Just spp ->- let position =- maybe (fst $ Name.annotation n) (fst . FieldLine.annotation) $- Maybe.listToMaybe fls- in Fields.Field n $ fieldLines csv position fls spp+ Fields.Field n fls ->+ let position =+ maybe (fst $ Name.annotation n) (fst . FieldLine.annotation) $+ Maybe.listToMaybe fls+ in Fields.Field n $ case Map.lookup (Name.value n) parsers of+ Nothing -> floatComments position fls+ Just spp -> fieldLines csv position fls spp Fields.Section n sas fs -> let result = Parsec.runParsecParser' csv (Condition.parseCondition Variable.parseVariable) "<conditional>"@@ -93,13 +93,27 @@ [Fields.FieldLine (p, [c])] fieldLines csv position fls SPP.SomeParsecParser {SPP.parsec = parsec, SPP.pretty = pretty} = case Parsec.runParsecParser' csv parsec "" $ FieldLine.toFieldLineStream fls of- Left _ -> fls+ Left _ -> floatComments position fls Right r ->- fmap (\(c, l) -> Fields.FieldLine c $ String.toUtf8 l)- . zip ((,) position <$> concatMap (snd . FieldLine.annotation) fls : repeat [])+ zipWith+ (\b l -> Fields.FieldLine (position, if b then collectComments fls else []) $ String.toUtf8 l)+ (True : repeat False) . lines . PrettyPrint.renderStyle style $ pretty csv r++floatComments ::+ p ->+ [Fields.FieldLine (p, [c])] ->+ [Fields.FieldLine (p, [c])]+floatComments p fls =+ zipWith+ (\b -> Fields.FieldLine (p, if b then collectComments fls else []) . FieldLine.value)+ (True : repeat False)+ fls++collectComments :: [Fields.FieldLine (p, [c])] -> [c]+collectComments = concatMap (snd . FieldLine.annotation) -- | This style attempts to force everything to be on its own line. style :: PrettyPrint.Style
source/test-suite/Main.hs view
@@ -419,7 +419,7 @@ Hspec.it "formats a comment in a field's value" $ do expectGilded "f:\n 1\n -- c\n 2"- "f:\n 1\n -- c\n 2\n"+ "f:\n -- c\n 1\n 2\n" Hspec.it "formats a comment after a field's value" $ do expectGilded@@ -512,12 +512,12 @@ Hspec.it "does not insert extra blank lines before comments" $ do expectGilded "cabal-version: 3.0\ndescription:\n -- c\n 1\n -- d\n 2"- "cabal-version: 3.0\ndescription:\n -- c\n 1\n -- d\n 2\n"+ "cabal-version: 3.0\ndescription:\n -- c\n -- d\n 1\n 2\n" Hspec.it "does not consider comments for indentation" $ do expectGilded "cabal-version: 3.0\ndescription:\n 1\n -- c\n 2"- "cabal-version: 3.0\ndescription:\n 1\n -- c\n 2\n"+ "cabal-version: 3.0\ndescription:\n -- c\n 1\n 2\n" Hspec.it "properly formats conditionals" $ do expectGilded@@ -1516,6 +1516,16 @@ [["example.txt"]] "-- cabal-gild: discover\nlicense-files:" "-- cabal-gild: discover\nlicense-files: example.txt\n"++ Hspec.it "floats comments on unknown fields" $ do+ expectGilded+ "unknown-field:\n the\n -- some comment\n value"+ "unknown-field:\n -- some comment\n the\n value\n"++ Hspec.it "floats comments when parsing field fails" $ do+ expectGilded+ "build-depends:\n >> no\n -- comment\n parse"+ "build-depends:\n -- comment\n >> no\n parse\n" Hspec.around_ withTemporaryDirectory . Hspec.it "discovers modules on the file system"