cabal-fmt 0.1.5 → 0.1.5.1
raw patch · 5 files changed
+59/−8 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- CabalFmt.Prelude: (&) :: () => a -> (a -> b) -> b
+ CabalFmt.Prelude: (&) :: a -> (a -> b) -> b
- CabalFmt.Prelude: catMaybes :: () => [Maybe a] -> [a]
+ CabalFmt.Prelude: catMaybes :: [Maybe a] -> [a]
- CabalFmt.Prelude: fromMaybe :: () => a -> Maybe a -> a
+ CabalFmt.Prelude: fromMaybe :: a -> Maybe a -> a
- CabalFmt.Prelude: intercalate :: () => [a] -> [[a]] -> [a]
+ CabalFmt.Prelude: intercalate :: [a] -> [[a]] -> [a]
- CabalFmt.Prelude: isJust :: () => Maybe a -> Bool
+ CabalFmt.Prelude: isJust :: Maybe a -> Bool
- CabalFmt.Prelude: isNothing :: () => Maybe a -> Bool
+ CabalFmt.Prelude: isNothing :: Maybe a -> Bool
- CabalFmt.Prelude: on :: () => (b -> b -> c) -> (a -> b) -> a -> a -> c
+ CabalFmt.Prelude: on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- CabalFmt.Prelude: over :: () => ASetter s t a b -> (a -> b) -> s -> t
+ CabalFmt.Prelude: over :: ASetter s t a b -> (a -> b) -> s -> t
- CabalFmt.Prelude: partitionEithers :: () => [Either a b] -> ([a], [b])
+ CabalFmt.Prelude: partitionEithers :: [Either a b] -> ([a], [b])
- CabalFmt.Prelude: sortBy :: () => (a -> a -> Ordering) -> [a] -> [a]
+ CabalFmt.Prelude: sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- CabalFmt.Prelude: view :: () => Getting a s a -> s -> a
+ CabalFmt.Prelude: view :: Getting a s a -> s -> a
Files
- Changelog.md +4/−0
- cabal-fmt.cabal +2/−2
- fixtures/simple-example.cabal +14/−0
- fixtures/simple-example.format +21/−0
- src/CabalFmt/Fields/BuildDepends.hs +18/−6
Changelog.md view
@@ -1,3 +1,7 @@+# 0.1.5.1++- Fix bug in pretty printing empty version ranges.+ # 0.1.5 - Don't print redundant `-any` in `impl`
cabal-fmt.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: cabal-fmt-version: 0.1.5+version: 0.1.5.1 synopsis: Format .cabal files category: Development description:@@ -12,7 +12,7 @@ license-file: LICENSE author: Oleg Grenrus <oleg.grenrus@iki.fi> maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>-tested-with: GHC ==8.4.4 || ==8.6.5 || ==8.8.3 || ==8.10.1+tested-with: GHC ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.2 extra-source-files: Changelog.md fixtures/*.cabal
fixtures/simple-example.cabal view
@@ -43,6 +43,20 @@ -- cabal-fmt: glob-files cbits/**/*.c c-sources: + -- empty interval+ if impl(hugs)+ build-depends: unbuildable <0+ build-depends: unbuildable <0, unbuildable2 <0++ -- full interval+ build-depends: text <1 || >=1+ build-depends: containers <1 || >=1, pretty <1 || >=1++ -- only upper bound+ build-depends: foo <1+ build-depends: foo <2+ build-depends: abc <1, def <1, ghj <2+ test-suite doctests type: exitcode-stdio-1.0 main-is: doctests.hs
fixtures/simple-example.format view
@@ -52,6 +52,27 @@ cbits/source2.c cbits/sub/source3.c + -- empty interval+ if impl(hugs)+ build-depends: unbuildable <0+ build-depends:+ unbuildable <0+ , unbuildable2 <0++ -- full interval+ build-depends: text+ build-depends:+ containers+ , pretty++ -- only upper bound+ build-depends: foo ==0.*+ build-depends: foo <2+ build-depends:+ abc <1+ , def <1+ , ghj <2+ test-suite doctests type: exitcode-stdio-1.0 main-is: doctests.hs
src/CabalFmt/Fields/BuildDepends.hs view
@@ -34,15 +34,19 @@ pretty :: Options -> [C.Dependency] -> PP.Doc pretty Options { optSpecVersion = v, optTabular = tab } deps = case deps of- [] -> PP.empty+ [] -> PP.empty [dep] -> C.pretty (C.depPkgName dep) PP.<+> prettyVR vr' where vr' = either (C.fromVersionIntervals . C.mkVersionIntervals) id $ norm (C.asVersionIntervals $ C.depVerRange dep)+ prettyVR vr | vr == C.anyVersion = PP.empty+ | vr == C.noVersion = PP.text "<0" | otherwise = C.pretty vr+ _ -> PP.vcat (zipWith pretty' (True : repeat False) deps') where+ deps' :: [(String, [C.VersionInterval])] deps' = sortOn (map toLower . fst) $ map (C.unPackageName . C.depPkgName &&& C.asVersionIntervals . C.depVerRange) $ C.fromDepMap . C.toDepMap -- this combines duplicate packages@@ -54,7 +58,8 @@ -- we assume cabal-version: 2.2 or higher pretty' :: Bool -> (String, [C.VersionInterval]) -> PP.Doc pretty' isFirst (name, vis)- | empty vis = comma PP.<+> PP.text name+ | empty vis = comma PP.<+> PP.text name PP.<+> PP.text "<0"+ | full vis = comma PP.<+> PP.text name | otherwise = case norm vis of Left [] -> comma PP.<+> PP.text name Left (vi : vis') ->@@ -77,6 +82,9 @@ prettyLowerBound lb PP.<> C.pretty l prettyVi (C.LowerBound l C.InclusiveBound, C.UpperBound u C.InclusiveBound) | l == u = PP.text "==" PP.<> C.pretty l+ prettyVi (C.LowerBound l C.InclusiveBound, C.UpperBound u ub)+ | l == C.version0+ = prettyUpperBound ub PP.<> C.pretty u prettyVi (C.LowerBound l lb, C.UpperBound u ub) = prettyLowerBound lb PP.<> PP.text (lp width' l') PP.<+> PP.text "&&" PP.<+>@@ -100,13 +108,17 @@ prettyUpperBound C.InclusiveBound = PP.text "<=" prettyUpperBound C.ExclusiveBound = PP.text "<" where+ full :: [C.VersionInterval] -> Bool+ full [(C.LowerBound l C.InclusiveBound, C.NoUpperBound)] = l == C.mkVersion [0]+ full _ = False+ empty :: [C.VersionInterval] -> Bool- empty [] = True- empty [(C.LowerBound l C.InclusiveBound, C.NoUpperBound)] = l == C.mkVersion [0]- empty _ = False+ empty [] = True+ empty _ = False norm :: [C.VersionInterval] -> Either [C.VersionInterval] C.VersionRange- norm [] = Right C.anyVersion+ norm [] = Right C.noVersion+ norm [(C.LowerBound l C.InclusiveBound, C.NoUpperBound)] | l == C.version0 = Right C.anyVersion norm (i:is) = maybe (Left $ i:is) Right $ foldr1 C.unionVersionRanges <$> traverse f (i : is) where