Merge pull request #1907 from josephcsible/formatters

Clean up formatters
This commit is contained in:
Vidar Holen 2020-04-12 15:23:17 -07:00 committed by GitHub
commit e7b5fb9742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -22,6 +22,7 @@ module ShellCheck.Formatter.GCC (format) where
import ShellCheck.Interface import ShellCheck.Interface
import ShellCheck.Formatter.Format import ShellCheck.Formatter.Format
import Data.Either
import Data.List import Data.List
import GHC.Exts import GHC.Exts
import System.IO import System.IO
@ -44,7 +45,7 @@ outputAll cr sys = mapM_ f groups
f group = do f group = do
let filename = sourceFile (head group) let filename = sourceFile (head group)
result <- (siReadFile sys) filename result <- (siReadFile sys) filename
let contents = either (const "") id result let contents = fromRight "" result
outputResult filename contents group outputResult filename contents group
outputResult filename contents warnings = do outputResult filename contents warnings = do

View File

@ -24,6 +24,7 @@ import ShellCheck.Interface
import ShellCheck.Formatter.Format import ShellCheck.Formatter.Format
import Data.Aeson import Data.Aeson
import Data.Either
import Data.IORef import Data.IORef
import Data.Monoid import Data.Monoid
import GHC.Exts import GHC.Exts
@ -118,7 +119,7 @@ collectResult ref cr sys = mapM_ f groups
f group = do f group = do
let filename = sourceFile (head group) let filename = sourceFile (head group)
result <- siReadFile sys filename result <- siReadFile sys filename
let contents = either (const "") id result let contents = fromRight "" result
let comments' = makeNonVirtual comments contents let comments' = makeNonVirtual comments contents
modifyIORef ref (\x -> comments' ++ x) modifyIORef ref (\x -> comments' ++ x)

View File

@ -25,6 +25,7 @@ import ShellCheck.Formatter.Format
import Control.Monad import Control.Monad
import Data.Array import Data.Array
import Data.Either
import Data.Foldable import Data.Foldable
import Data.Ord import Data.Ord
import Data.IORef import Data.IORef
@ -122,12 +123,12 @@ outputResult options ref result sys = do
outputForFile color sys comments = do outputForFile color sys comments = do
let fileName = sourceFile (head comments) let fileName = sourceFile (head comments)
result <- (siReadFile sys) fileName result <- (siReadFile sys) fileName
let contents = either (const "") id result let contents = fromRight "" result
let fileLinesList = lines contents let fileLinesList = lines contents
let lineCount = length fileLinesList let lineCount = length fileLinesList
let fileLines = listArray (1, lineCount) fileLinesList let fileLines = listArray (1, lineCount) fileLinesList
let groups = groupWith lineNo comments let groups = groupWith lineNo comments
mapM_ (\commentsForLine -> do forM_ groups $ \commentsForLine -> do
let lineNum = fromIntegral $ lineNo (head commentsForLine) let lineNum = fromIntegral $ lineNo (head commentsForLine)
let line = if lineNum < 1 || lineNum > lineCount let line = if lineNum < 1 || lineNum > lineCount
then "" then ""
@ -136,10 +137,9 @@ outputForFile color sys comments = do
putStrLn $ color "message" $ putStrLn $ color "message" $
"In " ++ fileName ++" line " ++ show lineNum ++ ":" "In " ++ fileName ++" line " ++ show lineNum ++ ":"
putStrLn (color "source" line) putStrLn (color "source" line)
mapM_ (\c -> putStrLn (color (severityText c) $ cuteIndent c)) commentsForLine forM_ commentsForLine $ \c -> putStrLn $ color (severityText c) $ cuteIndent c
putStrLn "" putStrLn ""
showFixedString color commentsForLine (fromIntegral lineNum) fileLines showFixedString color commentsForLine (fromIntegral lineNum) fileLines
) groups
-- Pick out only the lines necessary to show a fix in action -- Pick out only the lines necessary to show a fix in action
sliceFile :: Fix -> Array Int String -> (Fix, Array Int String) sliceFile :: Fix -> Array Int String -> (Fix, Array Int String)