Skip to content

Commit

Permalink
Remove partial head function from src/ShellCheck/Formatter/TTY.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible committed Dec 11, 2023
1 parent a9e7bf1 commit 4c1d917
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ShellCheck/Formatter/TTY.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import Data.Ord
import Data.IORef
import Data.List
import Data.Maybe
import GHC.Exts
import System.IO
import System.Info
import qualified Data.List.NonEmpty as NE

wikiLink = "https://www.shellcheck.net/wiki/"

Expand Down Expand Up @@ -117,19 +117,19 @@ outputResult options ref result sys = do
color <- getColorFunc $ foColorOption options
let comments = crComments result
appendComments ref comments (fromIntegral $ foWikiLinkCount options)
let fileGroups = groupWith sourceFile comments
let fileGroups = NE.groupWith sourceFile comments
mapM_ (outputForFile color sys) fileGroups

outputForFile color sys comments = do
let fileName = sourceFile (head comments)
let fileName = sourceFile (NE.head comments)
result <- siReadFile sys (Just True) fileName
let contents = either (const "") id result
let fileLinesList = lines contents
let lineCount = length fileLinesList
let fileLines = listArray (1, lineCount) fileLinesList
let groups = groupWith lineNo comments
let groups = NE.groupWith lineNo comments
forM_ groups $ \commentsForLine -> do
let lineNum = fromIntegral $ lineNo (head commentsForLine)
let lineNum = fromIntegral $ lineNo (NE.head commentsForLine)
let line = if lineNum < 1 || lineNum > lineCount
then ""
else fileLines ! fromIntegral lineNum
Expand All @@ -139,7 +139,7 @@ outputForFile color sys comments = do
putStrLn (color "source" line)
forM_ commentsForLine $ \c -> putStrLn $ color (severityText c) $ cuteIndent c
putStrLn ""
showFixedString color commentsForLine (fromIntegral lineNum) fileLines
showFixedString color (toList commentsForLine) (fromIntegral lineNum) fileLines

-- Pick out only the lines necessary to show a fix in action
sliceFile :: Fix -> Array Int String -> (Fix, Array Int String)
Expand Down

0 comments on commit 4c1d917

Please sign in to comment.