From 64c31d91422e3c48cc7ed0176b069fa11456cee8 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 5 Apr 2020 22:13:39 -0400 Subject: [PATCH 1/2] Use fromRight instead of reimplementing it --- src/ShellCheck/Formatter/GCC.hs | 3 ++- src/ShellCheck/Formatter/JSON1.hs | 3 ++- src/ShellCheck/Formatter/TTY.hs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Formatter/GCC.hs b/src/ShellCheck/Formatter/GCC.hs index 9c5fa5f..a7307a9 100644 --- a/src/ShellCheck/Formatter/GCC.hs +++ b/src/ShellCheck/Formatter/GCC.hs @@ -22,6 +22,7 @@ module ShellCheck.Formatter.GCC (format) where import ShellCheck.Interface import ShellCheck.Formatter.Format +import Data.Either import Data.List import GHC.Exts import System.IO @@ -44,7 +45,7 @@ outputAll cr sys = mapM_ f groups f group = do let filename = sourceFile (head group) result <- (siReadFile sys) filename - let contents = either (const "") id result + let contents = fromRight "" result outputResult filename contents group outputResult filename contents warnings = do diff --git a/src/ShellCheck/Formatter/JSON1.hs b/src/ShellCheck/Formatter/JSON1.hs index 7335d8c..edc1974 100644 --- a/src/ShellCheck/Formatter/JSON1.hs +++ b/src/ShellCheck/Formatter/JSON1.hs @@ -24,6 +24,7 @@ import ShellCheck.Interface import ShellCheck.Formatter.Format import Data.Aeson +import Data.Either import Data.IORef import Data.Monoid import GHC.Exts @@ -118,7 +119,7 @@ collectResult ref cr sys = mapM_ f groups f group = do let filename = sourceFile (head group) result <- siReadFile sys filename - let contents = either (const "") id result + let contents = fromRight "" result let comments' = makeNonVirtual comments contents modifyIORef ref (\x -> comments' ++ x) diff --git a/src/ShellCheck/Formatter/TTY.hs b/src/ShellCheck/Formatter/TTY.hs index 4dabf45..ddf36aa 100644 --- a/src/ShellCheck/Formatter/TTY.hs +++ b/src/ShellCheck/Formatter/TTY.hs @@ -25,6 +25,7 @@ import ShellCheck.Formatter.Format import Control.Monad import Data.Array +import Data.Either import Data.Foldable import Data.Ord import Data.IORef @@ -122,7 +123,7 @@ outputResult options ref result sys = do outputForFile color sys comments = do let fileName = sourceFile (head comments) result <- (siReadFile sys) fileName - let contents = either (const "") id result + let contents = fromRight "" result let fileLinesList = lines contents let lineCount = length fileLinesList let fileLines = listArray (1, lineCount) fileLinesList From 1c6202dba4d31feb1a4e483df849a74f39e790e3 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 5 Apr 2020 22:25:19 -0400 Subject: [PATCH 2/2] Avoid some awkward parentheses with forM_ --- src/ShellCheck/Formatter/TTY.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Formatter/TTY.hs b/src/ShellCheck/Formatter/TTY.hs index ddf36aa..44bda1e 100644 --- a/src/ShellCheck/Formatter/TTY.hs +++ b/src/ShellCheck/Formatter/TTY.hs @@ -128,7 +128,7 @@ outputForFile color sys comments = do let lineCount = length fileLinesList let fileLines = listArray (1, lineCount) fileLinesList let groups = groupWith lineNo comments - mapM_ (\commentsForLine -> do + forM_ groups $ \commentsForLine -> do let lineNum = fromIntegral $ lineNo (head commentsForLine) let line = if lineNum < 1 || lineNum > lineCount then "" @@ -137,10 +137,9 @@ outputForFile color sys comments = do putStrLn $ color "message" $ "In " ++ fileName ++" line " ++ show lineNum ++ ":" putStrLn (color "source" line) - mapM_ (\c -> putStrLn (color (severityText c) $ cuteIndent c)) commentsForLine + forM_ commentsForLine $ \c -> putStrLn $ color (severityText c) $ cuteIndent c putStrLn "" showFixedString color commentsForLine (fromIntegral lineNum) fileLines - ) groups -- Pick out only the lines necessary to show a fix in action sliceFile :: Fix -> Array Int String -> (Fix, Array Int String)