From ec8d82a88cc12a787e0c81b9ce4d85d90f6291ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=B6ck?= Date: Mon, 21 Aug 2023 08:43:28 +0200 Subject: [PATCH] [ style ] adhere to coding style (#5) --- src/Fix.idr | 34 ++++++++------- src/Main.idr | 15 ++++--- src/Options.idr | 112 +++++++++++++++++++++++++----------------------- 3 files changed, 86 insertions(+), 75 deletions(-) diff --git a/src/Fix.idr b/src/Fix.idr index aee80a0..69033a6 100644 --- a/src/Fix.idr +++ b/src/Fix.idr @@ -22,9 +22,11 @@ noTrailingNewlines = reverse . dropWhile1 (\x => null x) . cons [] . reverse unlinesImpl : List1 (List Char) -> List Char unlinesImpl ([] ::: []) = [NL] unlinesImpl (h ::: t) = h ++ run t - where run : List (List Char) -> List Char - run [] = [] - run (cs :: css) = NL :: cs ++ run css + + where + run : List (List Char) -> List Char + run [] = [] + run (cs :: css) = NL :: cs ++ run css removeCRLF : List Char -> List Char @@ -33,11 +35,12 @@ removeCRLF ('\r' :: '\n' :: xs) = '\n' :: removeCRLF xs removeCRLF (x :: xs) = x :: removeCRLF xs transformImpl : List Char -> List Char -transformImpl = unlinesImpl - . noTrailingNewlines - . map noTrailingSpace - . split isNL - . removeCRLF +transformImpl = + unlinesImpl + . noTrailingNewlines + . map noTrailingSpace + . split isNL + . removeCRLF ||| Transforms the given string in the following way: ||| * on every line, trailing whitespace characters are removed @@ -89,13 +92,14 @@ transTest5 : TestTransformImpl "test\r\ntrailing" = "test\ntrailing\n" transTest5 = Refl Empties : List String -Empties = [ "" - , "\n" - , "\n\n" - , "\n\n\n" - , " \n \n\n" - , " \n \n\n\t" - ] +Empties = + [ "" + , "\n" + , "\n\n" + , "\n\n\n" + , " \n \n\n" + , " \n \n\n\t" + ] testEmpties : map TestTransformImpl Empties = replicate (length Empties) "\n" testEmpties = Refl diff --git a/src/Main.idr b/src/Main.idr index cfe25dc..7f7bbb0 100644 --- a/src/Main.idr +++ b/src/Main.idr @@ -20,9 +20,9 @@ Prog : Type -> Type Prog t = ReaderT Config (EitherT (List String) IO) t run : Config -> Prog () -> IO () -run c (MkReaderT f) = do Right () <- runEitherT (f c) - | Left es => traverse_ putStrLn es - pure () +run c (MkReaderT f) = do + Right () <- runEitherT (f c) | Left es => traverse_ putStrLn es + pure () -------------------------------------------------------------------------------- -- Logging @@ -54,10 +54,11 @@ throwOne e = throwError [e] -- File Handling -------------------------------------------------------------------------------- -tryFile : (mod : String) - -> (String -> Prog (Either FileError a)) - -> (pth : FilePath) - -> Prog a +tryFile : + (mod : String) + -> (String -> Prog (Either FileError a)) + -> (pth : FilePath) + -> Prog a tryFile mod p pth = do trace $ "\{mod} \{pth}" Right a <- p (interpolate pth) diff --git a/src/Options.idr b/src/Options.idr index 670d122..734c5fd 100644 --- a/src/Options.idr +++ b/src/Options.idr @@ -60,15 +60,16 @@ record Config where %runElab derive "Config" [Show,Eq,Pretty] init : List String -> Config -init fs = MkConfig { - printHelp = False - , verbosity = 2 - , checkOnly = True - , includeAll = False - , includeHidden = False - , files = case fs of [] => ["."]; _ => map fromString fs - , extensions = ["idr"] - } +init fs = + MkConfig + { printHelp = False + , verbosity = 2 + , checkOnly = True + , includeAll = False + , includeHidden = False + , files = case fs of [] => ["."]; _ => map fromString fs + , extensions = ["idr"] + } ||| Tests, whether a file or directory is hidden and should ||| still be included. @@ -107,42 +108,46 @@ setHidden : Config -> Config setHidden = {includeHidden := True} descs : List $ OptDescr (Config -> Config) -descs = [ MkOpt ['h'] ["help"] (NoArg help) - "prints this help text\n " - , MkOpt ['v'] ["verbose"] (NoArg $ adjVerbosity S) - "increase verbosity (default verbosity is 2)\n " - , MkOpt ['q'] ["quiet"] (NoArg $ adjVerbosity pred) - "decrease verbosity (default verbosity is 2)\n " - , MkOpt ['c'] ["check"] (NoArg $ doFix False) - "check and list files with issues (default)\n " - , MkOpt ['f'] ["fix"] (NoArg $ doFix True) - "check and fix files with issues\n " - , MkOpt ['e'] ["ext"] (ReqArg setExts "") - $ unlines [ "comma separated list of extensions of files" - , "to be included when traversing directories" - , "(default is \"idr\")." - , "Note: Files whose name starts with a dot will be" - , "ignored unless '--includeHidden' is set." - , "" - ] - , MkOpt ['a'] ["all"] (NoArg setAll) - "include all non-hidden files when traversing directories\n " - , MkOpt [] ["includeHidden"] (NoArg setHidden) - $ unlines [ "include hidden files (name starts with a dot)" - , "when traversing directories" - , "" - ] +descs = + [ MkOpt ['h'] ["help"] (NoArg help) + "prints this help text\n " + , MkOpt ['v'] ["verbose"] (NoArg $ adjVerbosity S) + "increase verbosity (default verbosity is 2)\n " + , MkOpt ['q'] ["quiet"] (NoArg $ adjVerbosity pred) + "decrease verbosity (default verbosity is 2)\n " + , MkOpt ['c'] ["check"] (NoArg $ doFix False) + "check and list files with issues (default)\n " + , MkOpt ['f'] ["fix"] (NoArg $ doFix True) + "check and fix files with issues\n " + , MkOpt ['e'] ["ext"] (ReqArg setExts "") $ + unlines + [ "comma separated list of extensions of files" + , "to be included when traversing directories" + , "(default is \"idr\")." + , "Note: Files whose name starts with a dot will be" + , "ignored unless '--includeHidden' is set." + , "" ] + , MkOpt ['a'] ["all"] (NoArg setAll) + "include all non-hidden files when traversing directories\n " + , MkOpt [] ["includeHidden"] (NoArg setHidden) $ + unlines + [ "include hidden files (name starts with a dot)" + , "when traversing directories" + , "" + ] + ] export applyArgs : List String -> Either (List String) Config applyArgs args = case getOpt RequireOrder descs args of - MkResult os n [] [] => Right $ foldl (flip apply) (init n) os - MkResult _ _ u e => Left $ map unknown u ++ e + MkResult os n [] [] => Right $ foldl (flip apply) (init n) os + MkResult _ _ u e => Left $ map unknown u ++ e - where unknown : String -> String - unknown = ("Unknown option: " ++) + where + unknown : String -> String + unknown = ("Unknown option: " ++) -------------------------------------------------------------------------------- -- Usage Info @@ -158,21 +163,22 @@ usage : String usage = "Usage: " ++ progName ++ " [options] [FILES]\n\nOptions:\n" synopsis : String -synopsis = unlines [ - progName ++ " version " ++ version - , "" - , " Removes trailing whitespace characters from the specified" - , " text files making sure every text file ends with exactly one" - , " newline character. Windows style line breaks are replaced" - , " by Unix newline characters." - , "" - , " If the passed file list contains directories, " ++ progName - , " will recursively adjust all files with the given extensions" - , " (see option --ext) in those directories. If no files are" - , " specified, the current directory will be traversed instead." - , "" - , usage - ] +synopsis = + unlines + [ progName ++ " version " ++ version + , "" + , " Removes trailing whitespace characters from the specified" + , " text files making sure every text file ends with exactly one" + , " newline character. Windows style line breaks are replaced" + , " by Unix newline characters." + , "" + , " If the passed file list contains directories, " ++ progName + , " will recursively adjust all files with the given extensions" + , " (see option --ext) in those directories. If no files are" + , " specified, the current directory will be traversed instead." + , "" + , usage + ] export info : String