Fix hlint suggestions.
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
dist:
runghc Setup.hs configure
runghc Setup.hs sdist
+
+hlint:
+ hlint --ignore="Use camelCase" \
+ --ignore="Redundant bracket" \
+ --color \
+ src
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)
-- 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
--
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 }
-- 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 }
-- 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.
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
-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(..),
-- | 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
-- 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)
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)
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)
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