diff --git a/Makefile b/Makefile index 7106a98..de68200 100644 --- a/Makefile +++ b/Makefile @@ -9,15 +9,12 @@ shellcheck: regardless : Conditionally compiling shellcheck ghc $(GHCFLAGS) --make shellcheck -jsoncheck: regardless - : Conditionally compiling shellcheck - ghc $(GHCFLAGS) --make jsoncheck - .tests: *.hs */*.hs : Running unit tests ./test/runQuack && touch .tests clean: - rm -f .tests dist shellcheck jsoncheck *.hi *.o ShellCheck/*.hi ShellCheck/*.o + rm -f .tests shellcheck *.hi *.o ShellCheck/*.hi ShellCheck/*.o + rm -rf dist regardless: diff --git a/ShellCheck.cabal b/ShellCheck.cabal index 01b52cc..a00280f 100644 --- a/ShellCheck.cabal +++ b/ShellCheck.cabal @@ -9,12 +9,8 @@ Build-Type: Simple Cabal-Version: >= 1.2 library - build-depends: base >= 4, parsec, containers, regex-compat, mtl, directory + build-depends: base >= 4, parsec, containers, regex-compat, mtl, directory, json exposed-modules: ShellCheck.AST, ShellCheck.Data, ShellCheck.Parser, ShellCheck.Analytics, ShellCheck.Simple executable shellcheck main-is: shellcheck.hs - -executable jsoncheck - build-depends: json - main-is: jsoncheck.hs diff --git a/jsoncheck.hs b/jsoncheck.hs deleted file mode 100644 index 5996f46..0000000 --- a/jsoncheck.hs +++ /dev/null @@ -1,33 +0,0 @@ -{- - This file is part of ShellCheck. - http://www.vidarholen.net/contents/shellcheck - - ShellCheck is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ShellCheck is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . --} -import ShellCheck.Simple -import Text.JSON - -instance JSON ShellCheckComment where - showJSON c = makeObj [ - ("line", showJSON $ scLine c), - ("column", showJSON $ scColumn c), - ("level", showJSON $ scSeverity c), - ("code", showJSON $ scCode c), - ("message", showJSON $ scMessage c) - ] - readJSON = undefined - -main = do - script <- getContents - putStrLn $ encodeStrict $ shellCheck script diff --git a/shellcheck.hs b/shellcheck.hs index 1ba75fd..3ab0606 100644 --- a/shellcheck.hs +++ b/shellcheck.hs @@ -24,6 +24,7 @@ import System.Directory import System.Environment import System.Exit import System.IO +import Text.JSON import qualified Data.Map as Map data Flag = Flag String String @@ -36,6 +37,16 @@ options = [ printErr = hPutStrLn stderr +instance JSON ShellCheckComment where + showJSON c = makeObj [ + ("line", showJSON $ scLine c), + ("column", showJSON $ scColumn c), + ("level", showJSON $ scSeverity c), + ("code", showJSON $ scCode c), + ("message", showJSON $ scMessage c) + ] + readJSON = undefined + parseArguments argv = case getOpt Permute options argv of (opts, files, []) -> @@ -55,6 +66,7 @@ parseArguments argv = specials x = x formats = Map.fromList [ + ("json", forJson), ("tty", forTty) ] @@ -114,6 +126,16 @@ forTty options files = do term <- hIsTerminalDevice stdout return $ if term then colorComment else const id +-- This totally ignores the filenames. Fixme? +forJson options files = do + comments <- liftM concat $ mapM process files + putStrLn $ encodeStrict $ comments + return . null $ comments + where + process file = do + script <- readFile file + return $ shellCheck script + getOption [] _ def = def getOption ((Flag var val):_) name _ | name == var = val getOption (_:rest) flag def = getOption rest flag def