From 8b7c0be06faaf898e1e60ccd1baf69ae89b1de04 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 14 Nov 2013 22:23:55 -0800 Subject: [PATCH] gcc output mode now uses a tab width of 1 --- shellcheck.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/shellcheck.hs b/shellcheck.hs index 04d413c..3ec71b8 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -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 @@ -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