Fixes for import Handler indentation
This commit is contained in:
parent
245041bc92
commit
21a7d47f3b
@ -1,13 +1,13 @@
|
||||
{-# LANGUAGE PatternGuards #-}
|
||||
module AddHandler (addHandler) where
|
||||
|
||||
import Prelude hiding (readFile)
|
||||
import System.IO (hFlush, stdout)
|
||||
import Data.Char (isLower, toLower, isSpace)
|
||||
import Data.List (isPrefixOf, isSuffixOf)
|
||||
import Data.List (isPrefixOf, isSuffixOf, stripPrefix)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as TIO
|
||||
import System.Directory (getDirectoryContents, doesFileExist)
|
||||
import Control.Monad (when)
|
||||
|
||||
-- strict readFile
|
||||
readFile :: FilePath -> IO String
|
||||
@ -62,18 +62,18 @@ fixApp :: String -> String -> String
|
||||
fixApp name =
|
||||
unlines . reverse . go . reverse . lines
|
||||
where
|
||||
l = "import Handler." ++ name
|
||||
l spaces = "import " ++ spaces ++ "Handler." ++ name
|
||||
|
||||
go [] = [l]
|
||||
go [] = [l ""]
|
||||
go (x:xs)
|
||||
| "import Handler." `isPrefixOf` x = l : x : xs
|
||||
| Just y <- stripPrefix "import " x, "Handler." `isPrefixOf` dropWhile (== ' ') y = l (takeWhile (== ' ') y) : x : xs
|
||||
| otherwise = x : go xs
|
||||
|
||||
fixCabal :: String -> String -> String
|
||||
fixCabal name =
|
||||
unlines . reverse . go . reverse . lines
|
||||
where
|
||||
l = "import Handler." ++ name
|
||||
l = " Handler." ++ name
|
||||
|
||||
go [] = [l]
|
||||
go (x:xs)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user