Skip to content

Commit

Permalink
gcc output mode now uses a tab width of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Nov 15, 2013
1 parent 473bb66 commit 8b7c0be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion shellcheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ forGcc options files = do
return $ and files
where
process file = do
comments <- commentsFor file
contents <- readContents file
let comments = makeNonVirtual (shellCheck contents) contents
mapM_ (putStrLn . format file) comments
return $ null comments

Expand Down Expand Up @@ -191,6 +192,18 @@ forCheckstyle options files = do
commentsFor file = liftM shellCheck $ readContents file
readContents file = if file == "-" then getContents else readFile file

-- Realign comments from a tabstop of 8 to 1
makeNonVirtual comments contents =
map fix comments
where
ls = lines contents
fix c = c { scColumn = real (ls !! (scLine c - 1)) 0 0 (scColumn c) }
real _ r v target | target <= v = r
real [] r v _ = r -- should never happen
real ('\t':rest) r v target =
real rest (r+1) (v + 8 - (v `mod` 8)) target
real (_:rest) r v target = real rest (r+1) (v+1) target

getOption [] _ def = def
getOption ((Flag var val):_) name _ | name == var = val
getOption (_:rest) flag def = getOption rest flag def
Expand Down

0 comments on commit 8b7c0be

Please sign in to comment.