hfmt 0.2.3.1 → 0.3.0.0
raw patch · 10 files changed
+230/−144 lines, 10 filesdep ~basedep ~hlintdep ~stylish-haskellPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hlint, stylish-haskell
API changes (from Hackage documentation)
- Language.Haskell.Format: Formatter :: HaskellSource -> Either ErrorString Reformatted -> Formatter
+ Language.Haskell.Format: Formatter :: (HaskellSource -> Either ErrorString Reformatted) -> Formatter
Files
- app/ExitCode.hs +4/−4
- app/Options.hs +23/−17
- app/Types.hs +6/−10
- hfmt.cabal +170/−83
- src/Language/Haskell/Format/HIndent.hs +1/−2
- src/Language/Haskell/Format/HLint.hs +8/−9
- src/Language/Haskell/Format/Internal.hs +1/−1
- src/Language/Haskell/Format/Types.hs +10/−9
- src/Language/Haskell/Format/Utilities.hs +3/−5
- stack.yaml +4/−4
app/ExitCode.hs view
@@ -17,11 +17,11 @@ -- assume we are being run in a context where non-zero exit indicates -- failure of the tool to operate properly. exitCode :: Action -> RunResult -> ExitCode-exitCode _ NoDifferences = ExitSuccess+exitCode _ NoDifferences = ExitSuccess exitCode PrintDiffs HadDifferences = ExitFailure formattedCodeDiffersFailureCode-exitCode _ HadDifferences = ExitSuccess-exitCode _ SourceParseFailure = ExitFailure sourceParseFailureCode-exitCode _ OperationalFailure = ExitFailure operationalFailureCode+exitCode _ HadDifferences = ExitSuccess+exitCode _ SourceParseFailure = ExitFailure sourceParseFailureCode+exitCode _ OperationalFailure = ExitFailure operationalFailureCode helpDoc :: Doc helpDoc =
app/Options.hs view
@@ -15,13 +15,14 @@ import Options.Applicative.Extra import Text.PrettyPrint.ANSI.Leijen as Leijen hiding ((<$>), (<>)) -data Options = Options- { optPrintDiffs :: Bool- , optPrintSources :: Bool- , optPrintFilePaths :: Bool- , optWriteSources :: Bool- , optPaths :: [FilePath]- }+data Options =+ Options+ { optPrintDiffs :: Bool+ , optPrintSources :: Bool+ , optPrintFilePaths :: Bool+ , optWriteSources :: Bool+ , optPaths :: [FilePath]+ } optAction :: Options -> Action optAction options@@ -36,24 +37,28 @@ optionParser = Options <$> switch- (long "print-diffs" <> short 'd' <>- help "If a file's formatting is different, print a diff.") <*>+ (long "print-diffs" <>+ short 'd' <> help "If a file's formatting is different, print a diff.") <*> switch- (long "print-sources" <> short 's' <> hidden <>- help "If a file's formatting is different, print its source.") <*>+ (long "print-sources" <>+ short 's' <>+ hidden <> help "If a file's formatting is different, print its source.") <*> switch- (long "print-paths" <> short 'l' <> hidden <>- help "If a file's formatting is different, print its path.") <*>+ (long "print-paths" <>+ short 'l' <>+ hidden <> help "If a file's formatting is different, print its path.") <*> switch- (long "write-sources" <> short 'w' <> hidden <>- help "If a file's formatting is different, overwrite it.") <*>+ (long "write-sources" <>+ short 'w' <>+ hidden <> help "If a file's formatting is different, overwrite it.") <*> many pathOption where pathOption = strArgument (metavar "FILE" <> pathOptionHelp) pathOptionHelp = helpDoc $ Just $- text "Explicit paths to process." <> line <>+ text "Explicit paths to process." <>+ line <> unorderdedList " - " [ text "A single '-' will process standard input."@@ -73,7 +78,8 @@ optionParserInfo = info (helper <*> optionParser)- (fullDesc <> header "hfmt - Format Haskell programs" <>+ (fullDesc <>+ header "hfmt - Format Haskell programs" <> progDesc "Reformats Haskell source files by applying HLint, hindent, and stylish-haskell." <> footerDoc (Just ExitCode.helpDoc) <>
app/Types.hs view
@@ -28,23 +28,19 @@ show StdinSource = "-" data SourceFileWithContents =- SourceFileWithContents SourceFile- HaskellSource+ SourceFileWithContents SourceFile HaskellSource type FormatResult = Either FormatError Formatted data FormatError =- FormatError SourceFile- String+ FormatError SourceFile String instance Show FormatError where show (FormatError input errorString) = "Error reformatting " ++ show input ++ ": " ++ errorString data Formatted =- Formatted SourceFile- HaskellSource- Reformatted+ Formatted SourceFile HaskellSource Reformatted data RunResult = OperationalFailure@@ -53,11 +49,11 @@ | NoDifferences instance Semigroup RunResult where- x <> NoDifferences = x- NoDifferences <> x = x+ x <> NoDifferences = x+ NoDifferences <> x = x OperationalFailure <> _ = OperationalFailure SourceParseFailure <> _ = SourceParseFailure- HadDifferences <> _ = HadDifferences+ HadDifferences <> _ = HadDifferences instance Monoid RunResult where mempty = NoDifferences
hfmt.cabal view
@@ -1,89 +1,176 @@-name: hfmt-version: 0.2.3.1-synopsis: Haskell source code formatter-description: Inspired by gofmt. Built using hlint, hindent, and stylish-haskell.-license: MIT-license-file: LICENSE-author: Daniel Stiner-maintainer: Daniel Stiner <daniel.stiner@gmail.com>-stability: Experimental-homepage: http://github.com/danstiner/hfmt-bug-reports: http://github.com/danstiner/hfmt/issues-category: Language-build-type: Simple-extra-source-files: README.md, .stylish-haskell.yaml, stack.yaml-cabal-version: >=1.9.2-tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.2, GHC == 8.5+cabal-version: 1.12 +-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack+--+-- hash: 6d7853478e04459c8a1deaa7ed7c777a0697daa58c4618b217fde3c1d58d0d18++name: hfmt+version: 0.3.0.0+synopsis: Haskell source code formatter+description: Inspired by gofmt. Built using hlint, hindent, and stylish-haskell.+category: Language+stability: Experimental+homepage: https://github.com/danstiner/hfmt#readme+bug-reports: https://github.com/danstiner/hfmt/issues+author: Daniel Stiner+maintainer: Daniel Stiner <daniel.stiner@gmail.com>+license: MIT+license-file: LICENSE+tested-with:+ GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.2, GHC == 8.5+build-type: Simple+extra-source-files:+ .stylish-haskell.yaml+ LICENSE+ README.md+ stack.yaml++source-repository head+ type: git+ location: https://github.com/danstiner/hfmt+ library- Hs-Source-Dirs: src- Exposed-Modules: Language.Haskell.Format- , Language.Haskell.Format.Utilities- , Language.Haskell.Source.Enumerator- Other-Modules: Language.Haskell.Format.Internal- , Language.Haskell.Format.HIndent- , Language.Haskell.Format.HLint- , Language.Haskell.Format.Stylish- , Language.Haskell.Format.Types- , Path.Find- GHC-Options: -Wall- Build-Depends: base >= 4.8 && < 5- , bytestring- , Cabal- , conduit- , conduit-combinators- , Diff- , directory- , exceptions- , filepath- , haskell-src-exts > 1.20- , hindent == 5.*- , hlint == 2.*- , HUnit- , path- , path-io- , pretty- , stylish-haskell == 0.9.*- , text- , transformers- , yaml+ exposed-modules:+ Language.Haskell.Format+ Language.Haskell.Format.Utilities+ Language.Haskell.Source.Enumerator+ other-modules:+ Language.Haskell.Format.HIndent+ Language.Haskell.Format.HLint+ Language.Haskell.Format.Internal+ Language.Haskell.Format.Stylish+ Language.Haskell.Format.Types+ Path.Find+ Paths_hfmt+ hs-source-dirs:+ src+ ghc-options: -Wall+ build-depends:+ Cabal+ , Diff+ , HUnit+ , base >=4.8 && <5+ , bytestring+ , conduit+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , haskell-src-exts >1.20+ , hindent ==5.*+ , hlint ==3.*+ , path+ , path-io+ , pretty+ , stylish-haskell+ , text+ , transformers+ , yaml+ default-language: Haskell2010 executable hfmt- Hs-Source-Dirs: app- Main-Is: Main.hs- Other-Modules: Actions- , ExitCode- , Options- , Types- GHC-Options: -Wall- Build-Depends: base >= 4.8 && < 5- , conduit- , conduit-combinators- , directory- , hfmt- , ansi-wl-pprint- , optparse-applicative--test-suite self-formatting-test- Type: exitcode-stdio-1.0- Hs-Source-Dirs: test/self-formatting- Main-Is: Spec.hs- Build-Depends: base == 4.*- , hfmt- , HUnit- , test-framework- , test-framework-hunit+ main-is: Main.hs+ other-modules:+ Actions+ ExitCode+ Options+ Types+ Paths_hfmt+ hs-source-dirs:+ app+ ghc-options: -Wall+ build-depends:+ Cabal+ , Diff+ , HUnit+ , ansi-wl-pprint+ , base >=4.8 && <5+ , bytestring+ , conduit+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , haskell-src-exts >1.20+ , hfmt+ , hindent ==5.*+ , hlint ==3.*+ , optparse-applicative+ , path+ , path-io+ , pretty+ , stylish-haskell+ , text+ , transformers+ , yaml+ default-language: Haskell2010 -test-suite pure-test- Type: exitcode-stdio-1.0- Hs-Source-Dirs: test/pure- Main-Is: Spec.hs- Build-Depends: base == 4.*- , hfmt- , HUnit- , test-framework- , test-framework-hunit+test-suite pure+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_hfmt+ hs-source-dirs:+ test/pure+ ghc-options: -Wall+ build-depends:+ Cabal+ , Diff+ , HUnit+ , base >=4.8 && <5+ , bytestring+ , conduit+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , haskell-src-exts >1.20+ , hfmt+ , hindent ==5.*+ , hlint ==3.*+ , path+ , path-io+ , pretty+ , stylish-haskell+ , test-framework+ , test-framework-hunit+ , text+ , transformers+ , yaml+ default-language: Haskell2010 -source-repository head- type: git- location: git://github.com:danstiner/hfmt.git+test-suite self-formatting-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_hfmt+ hs-source-dirs:+ test/self-formatting+ ghc-options: -Wall+ build-depends:+ Cabal+ , Diff+ , HUnit+ , base >=4.8 && <5+ , bytestring+ , conduit+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , haskell-src-exts >1.20+ , hfmt+ , hindent ==5.*+ , hlint ==3.*+ , path+ , path-io+ , pretty+ , stylish-haskell+ , test-framework+ , test-framework-hunit+ , text+ , transformers+ , yaml+ default-language: Haskell2010
src/Language/Haskell/Format/HIndent.hs view
@@ -20,8 +20,7 @@ import Language.Haskell.Format.Types data Settings =- Settings Config- (Maybe [Extension])+ Settings Config (Maybe [Extension]) defaultFormatter :: IO Formatter defaultFormatter = formatter <$> autoSettings
src/Language/Haskell/Format/HLint.hs view
@@ -3,14 +3,13 @@ , suggester ) where -import Language.Haskell.Format.Internal-import Language.Haskell.Format.Types+import Language.Haskell.Format.Internal+import Language.Haskell.Format.Types -import Language.Haskell.HLint3 (Classify, Hint,- ParseError (..), ParseFlags,- applyHints, parseModuleEx)-import qualified Language.Haskell.HLint3 as HLint3-import System.IO.Unsafe (unsafePerformIO)+import Language.Haskell.HLint (Classify, Hint, Idea, ParseError (..),+ ParseFlags, applyHints, argsSettings,+ parseModuleEx)+import System.IO.Unsafe (unsafePerformIO) suggester :: (ParseFlags, [Classify], Hint) -> Formatter suggester = mkSuggester . hlint@@ -27,7 +26,7 @@ ideas m = applyHints classify hint [m] autoSettings :: IO (ParseFlags, [Classify], Hint)-autoSettings = HLint3.argsSettings []+autoSettings = argsSettings [] -ideaToSuggestion :: HLint3.Idea -> Suggestion+ideaToSuggestion :: Idea -> Suggestion ideaToSuggestion = Suggestion . show
src/Language/Haskell/Format/Internal.hs view
@@ -6,7 +6,7 @@ import Language.Haskell.Format.Types mkFormatter :: (HaskellSource -> Either String HaskellSource) -> Formatter-mkFormatter f = Formatter (fmap (\source -> Reformatted source []) . f)+mkFormatter f = Formatter (fmap (`Reformatted` []) . f) mkSuggester :: (HaskellSource -> Either String [Suggestion]) -> Formatter mkSuggester f = Formatter $ \source -> Reformatted source <$> f source
src/Language/Haskell/Format/Types.hs view
@@ -11,8 +11,7 @@ type ErrorString = String data HaskellSource =- HaskellSource FilePath- String+ HaskellSource FilePath String deriving (Eq) newtype Suggestion =@@ -21,10 +20,11 @@ instance Show Suggestion where show (Suggestion text) = text -data Reformatted = Reformatted- { reformattedSource :: HaskellSource- , suggestions :: [Suggestion]- }+data Reformatted =+ Reformatted+ { reformattedSource :: HaskellSource+ , suggestions :: [Suggestion]+ } instance Semigroup Reformatted where (Reformatted _ suggestionsA) <> (Reformatted sourceB suggestionsB) =@@ -34,9 +34,10 @@ mempty = Reformatted undefined [] mappend = (<>) -newtype Formatter = Formatter- { unFormatter :: HaskellSource -> Either ErrorString Reformatted- }+newtype Formatter =+ Formatter+ { unFormatter :: HaskellSource -> Either ErrorString Reformatted+ } instance Semigroup Formatter where (Formatter f) <> (Formatter g) = Formatter (asReformatter g <=< f)
src/Language/Haskell/Format/Utilities.hs view
@@ -21,10 +21,8 @@ type ErrorString = String data CheckResult- = InvalidCheckResult HaskellSource- ErrorString- | CheckResult HaskellSource- Reformatted+ = InvalidCheckResult HaskellSource ErrorString+ | CheckResult HaskellSource Reformatted checkResultPath :: CheckResult -> FilePath checkResultPath (InvalidCheckResult (HaskellSource filepath _) _) = filepath@@ -68,7 +66,7 @@ (hasSuggestions reformatted) (concatMap show (suggestions reformatted)) whenMaybe :: Bool -> a -> Maybe a- whenMaybe cond val = const val <$> guard cond+ whenMaybe cond val = val <$ guard cond showDiff :: HaskellSource -> HaskellSource -> String showDiff (HaskellSource _ a) (HaskellSource _ b) = render (toDoc diff)
stack.yaml view
@@ -1,7 +1,7 @@-resolver: lts-12.6+resolver: lts-17.2 flags: {} packages:-- '.'+ - '.' extra-deps:- - stylish-haskell-0.9.2.0- - hindent-5.2.7+ - hindent-5.3.2+ - stylish-haskell-0.12.0.0