Skip to content

Commit

Permalink
Exit failure when there are warnings or errors
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Jan 27, 2019
1 parent 2b14a3a commit 0f754fe
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/GLuaFixer/LintMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import Control.Applicative ((<|>))
import Data.Maybe (fromMaybe, fromJust)
import System.Directory (doesDirectoryExist, getCurrentDirectory)
import System.Environment (getArgs)
import System.Exit (exitWith, exitSuccess, ExitCode (..))
import System.Exit (exitWith, exitSuccess, exitFailure, ExitCode (..))
import System.IO (hPutStrLn, stderr)


version :: String
version = "1.10.0"
version = "1.11.0"


-- | Pretty print, uses the uu-parsinglib library
Expand Down Expand Up @@ -69,29 +69,30 @@ lintFile config f contents =


-- | Lint a set of files, uses parsec's parser library
lint :: Maybe LintSettings -> [FilePath] -> IO ()
lint _ [] = return ()
-- Bool return value indicates whether there were either warnings or errors
lint :: Maybe LintSettings -> [FilePath] -> IO Bool
lint _ [] = pure False
lint ls (f : fs) = do
settings <- getSettings f
let config = fromJust $ ls <|> Just settings

-- When we're dealing with a directory, lint all the files in it recursively.
isDirectory <- doesDirectoryExist f

if isDirectory then do
luaFiles <- findLuaFiles f
lint ls luaFiles
else if f == "stdin" then do
contents <- getContents
hasMsgs <- if isDirectory then findLuaFiles f >>= lint ls
else if f == "stdin" then do
msgs <- lintFile config f <$> getContents

mapM_ print (lintFile config f contents)
else do
contents <- doReadFile f
mapM_ print msgs
pure $ not $ null msgs
else do
msgs <- lintFile config f <$> doReadFile f

mapM_ print (lintFile config f contents)
mapM_ print msgs
pure $ not $ null msgs

-- Lint the other files
lint ls fs
(|| hasMsgs) <$> lint ls fs

-- | Indentation used for pretty printing code
type Indentation = String
Expand Down Expand Up @@ -126,4 +127,6 @@ main = do
args <- getArgs
(settings, files) <- parseCLArgs Nothing args

lint settings files
hasMessages <- lint settings files
if hasMessages then exitFailure
else exitSuccess

0 comments on commit 0f754fe

Please sign in to comment.