From: Michael Orlitzky Date: Sat, 8 Jun 2013 17:38:06 +0000 (-0400) Subject: Add hlint makefile target. X-Git-Tag: 0.0.1 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e36ba2f22248d0cbe485aa3961cdebb12178df0a;p=hath.git Add hlint makefile target. Fix hlint suggestions. --- diff --git a/makefile b/makefile index 2061f44..276c512 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ BIN = dist/build/hath/hath TESTSUITE_BIN = dist/build/testsuite/testsuite -.PHONY : test dist +.PHONY : test dist hlint $(BIN): src/*.hs runghc Setup.hs clean @@ -34,3 +34,9 @@ test: $(BIN) $(TESTSUITE_BIN) dist: runghc Setup.hs configure runghc Setup.hs sdist + +hlint: + hlint --ignore="Use camelCase" \ + --ignore="Redundant bracket" \ + --color \ + src diff --git a/src/Cidr.hs b/src/Cidr.hs index 7143a80..cdfef9a 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -22,7 +22,7 @@ module Cidr import Data.List (nubBy) import Data.List.Split (splitOneOf) -import Data.Maybe (catMaybes, fromJust) +import Data.Maybe (catMaybes, fromJust, mapMaybe) import Test.HUnit (assertEqual) import Test.Framework (Test, testGroup) @@ -77,7 +77,7 @@ maskbits_from_cidr_string s -- of its octets (as Ints). octets_from_cidr_string :: String -> [Octet] octets_from_cidr_string s = - catMaybes $ map octet_from_string (take 4 (splitOneOf "./" s)) + mapMaybe octet_from_string (take 4 (splitOneOf "./" s)) -- | Return Nothing if we can't parse both maskbits and octets from diff --git a/src/CommandLine.hs b/src/CommandLine.hs index c2bbe0c..181eb6f 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -52,13 +52,13 @@ default_options = Options { opt_help = False, -- options :: [OptDescr (Options -> IO Options)] options = - [ Option ['h']["help"] (NoArg set_help) "Prints this help message.", - Option ['i']["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ] + [ Option "h" ["help"] (NoArg set_help) "Prints this help message.", + Option "i" ["input"] (ReqArg set_input "FILE") "Read FILE instead of stdin." ] -- | Takes an Options as an argument, and sets its opt_help member to -- True. set_help :: Options -> IO Options -set_help opts = do +set_help opts = return opts { opt_help = True } @@ -67,7 +67,7 @@ set_help opts = do -- default opt_input is to read from stdin, but if this option is -- set, we replace that with readFile. set_input :: String -> Options -> IO Options -set_input arg opts = do +set_input arg opts = return opts { opt_input = readFile arg } @@ -91,9 +91,8 @@ parse_options = do -- list, one after another, on a default_options record. The end -- result should be an Options instance with all of its members set -- correctly. - opts <- foldl (>>=) (return default_options) actions + foldl (>>=) (return default_options) actions - return opts -- | Return the mode if one was given. @@ -101,13 +100,12 @@ parse_mode :: IO Mode parse_mode = do argv <- getArgs let (_, non_options, _) = getOpt Permute options argv - if (null non_options) - then do - -- Default - return Regex - else do - -- Some non-option was given, but were any of them modes? - case (lowercase (non_options !! 0)) of + case non_options of + -- Default + [] -> return Regex + -- Some non-option was given, but were any of them modes? + (x:_) -> + case (lowercase x) of "regex" -> return Regex "regexed" -> return Regex "reduce" -> return Reduce diff --git a/src/Main.hs b/src/Main.hs index dd7eefe..12511b6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,8 +1,8 @@ -import Control.Monad (when) -import Data.List ((\\), intercalate, intersperse) +import Control.Monad (unless, when) +import Data.List ((\\), intercalate) import Data.Maybe (catMaybes, isNothing) import Data.String.Utils (splitWs) -import System.Exit (ExitCode(..), exitWith) +import System.Exit (ExitCode(..), exitSuccess, exitWith) import System.IO (stderr, hPutStrLn) import Cidr (Cidr(..), @@ -71,7 +71,7 @@ cidr_to_regex cidr = -- | Take a list of Strings, and return a regular expression matching -- any of them. alternate :: [String] -> String -alternate terms = "(" ++ (concat (intersperse "|" terms)) ++ ")" +alternate terms = "(" ++ (intercalate "|" terms) ++ ")" -- | Take two Ints as parameters, and return a regex matching any @@ -89,7 +89,7 @@ main = do -- First, check for any errors that occurred while parsing -- the command line options. errors <- CommandLine.parse_errors - when ((not . null) errors) $ do + unless (null errors) $ do hPutStrLn stderr (concat errors) putStrLn CommandLine.help_text exitWith (ExitFailure exit_args_parse_failed) @@ -99,7 +99,7 @@ main = do help_opt_set <- CommandLine.help_set when help_opt_set $ do putStrLn CommandLine.help_text - exitWith ExitSuccess + exitSuccess -- The input function we receive here should know what to read. inputfunc <- (CommandLine.input_function) @@ -123,10 +123,10 @@ main = do let regexes = map cidr_to_regex valid_cidrs putStrLn $ alternate regexes Reduce -> do - _ <- mapM (putStrLn . show) (combine_all valid_cidrs) + _ <- mapM print (combine_all valid_cidrs) return () Dupe -> do - _ <- mapM (putStrLn . show) dupes + _ <- mapM print dupes return () where dupes = valid_cidrs \\ (combine_all valid_cidrs) @@ -136,6 +136,6 @@ main = do return () where dupes = valid_cidrs \\ (combine_all valid_cidrs) - deletions = map (\s -> "-" ++ (show s)) dupes + deletions = map (\s -> '-' : (show s)) dupes newcidrs = (combine_all valid_cidrs) \\ valid_cidrs - additions = map (\s -> "+" ++ (show s)) newcidrs + additions = map (\s -> '+' : (show s)) newcidrs