diff options
author | Łukasz Gołębiewski <lukasz.golebiewski@gmail.com> | 2020-01-26 11:36:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-26 11:36:49 +0000 |
commit | b501e5c92dac8b89ff0c1f962a4be4ecbc261e97 (patch) | |
tree | ab882893d57edad78ce6de5ae68f274c83404ae9 /lib | |
parent | 5eb4902883d9d3937641d6a2c6249993242bf098 (diff) | |
download | stylish-haskell-b501e5c92dac8b89ff0c1f962a4be4ecbc261e97.tar.gz |
Expose "format" function in Sylish.hs (#259)
* Expose "format" function in Sylish.hs
It's going to be needed for the haskell-ide integration
* Update tests/Language/Haskell/StylishSpec.hs
Co-Authored-By: Jasper Van der Jeugt <jaspervdj@gmail.com>
* Remove empty line
Co-authored-by: Jasper Van der Jeugt <jaspervdj@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Language/Haskell/Stylish.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Language/Haskell/Stylish.hs b/lib/Language/Haskell/Stylish.hs index a40a7d2..4f6aa1f 100644 --- a/lib/Language/Haskell/Stylish.hs +++ b/lib/Language/Haskell/Stylish.hs @@ -16,6 +16,8 @@ module Language.Haskell.Stylish -- * Misc , module Language.Haskell.Stylish.Verbose , version + , format + , ConfigPath(..) , Lines , Step ) where @@ -91,3 +93,13 @@ runStep exts mfp ls step = runSteps :: Extensions -> Maybe FilePath -> [Step] -> Lines -> Either String Lines runSteps exts mfp steps ls = foldM (runStep exts mfp) ls steps + +newtype ConfigPath = ConfigPath { unConfigPath :: FilePath } + +-- |Formats given contents optionally using the config provided as first param. +-- The second file path is the location from which the contents were read. +-- If provided, it's going to be printed out in the error message. +format :: Maybe ConfigPath -> Maybe FilePath -> String -> IO (Either String Lines) +format maybeConfigPath maybeFilePath contents = do + conf <- loadConfig (makeVerbose True) (fmap unConfigPath maybeConfigPath) + pure $ runSteps (configLanguageExtensions conf) maybeFilePath (configSteps conf) $ lines contents |