diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0dca47..61b10b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,3 +118,16 @@ jobs: - name: Test run: | stack test --system-ghc + + hlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Run HLint + env: + HLINT_VERSION: "3.2.7" + run: | + curl -L https://github.com/ndmitchell/hlint/releases/download/v${HLINT_VERSION}/hlint-${HLINT_VERSION}-x86_64-linux.tar.gz --output hlint.tar.gz + tar -xvf hlint.tar.gz + ./hlint-${HLINT_VERSION}/hlint src/ test/ diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 0000000..111320d --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,76 @@ +# HLint configuration file +# https://github.com/ndmitchell/hlint +########################## + +# This file contains a template configuration file, which is typically +# placed as .hlint.yaml in the root of your project + + +# Warnings currently triggered by your code +- ignore: {name: "Parse error: lexical error at character 'A'"} +- ignore: {name: "Use newtype instead of data"} +- ignore: {name: "Redundant lambda"} +- ignore: {name: "Redundant <$>"} +- ignore: {name: "Use section"} +- ignore: {name: "Monoid law, right identity"} +- ignore: {name: "Monoid law, left identity"} + + +# Specify additional command line arguments +# +# - arguments: [--color, --cpp-simple, -XQuasiQuotes] + + +# Control which extensions/flags/modules/functions can be used +# +# - extensions: +# - default: false # all extension are banned by default +# - name: [PatternGuards, ViewPatterns] # only these listed extensions can be used +# - {name: CPP, within: CrossPlatform} # CPP can only be used in a given module +# +# - flags: +# - {name: -w, within: []} # -w is allowed nowhere +# +# - modules: +# - {name: [Data.Set, Data.HashSet], as: Set} # if you import Data.Set qualified, it must be as 'Set' +# - {name: Control.Arrow, within: []} # Certain modules are banned entirely +# +# - functions: +# - {name: unsafePerformIO, within: []} # unsafePerformIO can only appear in no modules + + +# Add custom hints for this project +# +# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar" +# - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x} + +# The hints are named by the string they display in warning messages. +# For example, if you see a warning starting like +# +# Main.hs:116:51: Warning: Redundant == +# +# You can refer to that hint with `{name: Redundant ==}` (see below). + +# Turn on hints that are off by default +# +# Ban "module X(module X) where", to require a real export list +# - warn: {name: Use explicit module export list} +# +# Replace a $ b $ c with a . b $ c +# - group: {name: dollar, enabled: true} +# +# Generalise map to fmap, ++ to <> +# - group: {name: generalise, enabled: true} + + +# Ignore some builtin hints +# - ignore: {name: Use let} +# - ignore: {name: Use const, within: SpecialModule} # Only within certain modules + + +# Define some custom infix operators +# - fixity: infixr 3 ~^#^~ + + +# To generate a suitable file for HLint do: +# $ hlint --default > .hlint.yaml diff --git a/README.md b/README.md index 3839e0d..a47bf26 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,14 @@ make it unique: Haskell types and `htoml*` libraries use typeclasses-based approach via `aeson` library. +## Development + +`tomland` uses `hlint`, you can run it through: + +``` +hlint . +``` + ## Acknowledgement Icons made by [Freepik](http://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/). diff --git a/src/Toml/Codec/BiMap/Conversion.hs b/src/Toml/Codec/BiMap/Conversion.hs index d14221b..6425745 100644 --- a/src/Toml/Codec/BiMap/Conversion.hs +++ b/src/Toml/Codec/BiMap/Conversion.hs @@ -315,7 +315,7 @@ _ByteStringText :: TomlBiMap ByteString Text _ByteStringText = prism T.encodeUtf8 eitherText where eitherText :: ByteString -> Either TomlBiMapError Text - eitherText = either (\err -> Left $ ArbitraryError $ tShow err) Right . T.decodeUtf8' + eitherText = either (Left . ArbitraryError . tShow) Right . T.decodeUtf8' {-# INLINE _ByteStringText #-} {- | UTF-8 encoded 'ByteString' 'BiMap' for 'AnyValue'. diff --git a/src/Toml/Codec/Generic.hs b/src/Toml/Codec/Generic.hs index 1d6f40f..313f930 100644 --- a/src/Toml/Codec/Generic.hs +++ b/src/Toml/Codec/Generic.hs @@ -6,7 +6,6 @@ {-# LANGUAGE PolyKinds #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE TypeOperators #-} -{-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE UndecidableInstances #-} {- | diff --git a/src/Toml/Codec/Types.hs b/src/Toml/Codec/Types.hs index ca112d0..c9c4970 100644 --- a/src/Toml/Codec/Types.hs +++ b/src/Toml/Codec/Types.hs @@ -119,8 +119,8 @@ instance Applicative (Codec i) where instance Alternative (Codec i) where empty :: Codec i o empty = Codec - { codecRead = \_ -> empty - , codecWrite = \_ -> empty + { codecRead = const empty + , codecWrite = const empty } {-# INLINE empty #-} @@ -212,7 +212,7 @@ instance (s ~ TOML) => MonadState s TomlState where {-# INLINE get #-} put :: TOML -> TomlState () - put t = TomlState (\_ -> (Just (), t)) + put t = TomlState (const (Just (), t)) {-# INLINE put #-} {- | Transform 'Either' into 'TomlState'. diff --git a/src/Toml/Parser/Value.hs b/src/Toml/Parser/Value.hs index fd64ad7..6d6d770 100644 --- a/src/Toml/Parser/Value.hs +++ b/src/Toml/Parser/Value.hs @@ -43,16 +43,16 @@ decimalP = do case value of Left _ -> do try more - Right _ -> + Right _ -> fail "Leading zero." where leadingZeroP :: Parser String leadingZeroP = do - count 1 (char '0') >>= (\_ -> some digitChar) + count 1 (char '0') >> some digitChar more :: Parser Integer - more = check =<< readMaybe . concat <$> sepBy1 (some digitChar) (char '_') + more = check . readMaybe . concat =<< sepBy1 (some digitChar) (char '_') check :: Maybe Integer -> Parser Integer check = maybe (fail "Not an integer") pure @@ -64,7 +64,7 @@ numberP :: Parser Integer -> Parser Char -> String -> Parser Integer numberP parseInteger parseDigit errorMessage = more where more :: Parser Integer - more = check =<< intValueMaybe . concat <$> sepBy1 (some parseDigit) (char '_') + more = check . intValueMaybe . concat =<< sepBy1 (some parseDigit) (char '_') intValueMaybe :: String -> Maybe Integer intValueMaybe = parseMaybe parseInteger . fromString diff --git a/src/Toml/Type/PrefixTree.hs b/src/Toml/Type/PrefixTree.hs index 31cb72c..12519fd 100644 --- a/src/Toml/Type/PrefixTree.hs +++ b/src/Toml/Type/PrefixTree.hs @@ -155,7 +155,7 @@ lookupT lk (Branch pref mv prefMap) = case keysDiff pref lk of Equal -> mv NoPrefix -> Nothing - Diff _ _ _ -> Nothing + Diff {} -> Nothing SndIsPref _ -> Nothing FstIsPref k -> lookup k prefMap @@ -185,7 +185,7 @@ toListT (Leaf k v) = [(k, v)] toListT (Branch pref ma prefMap) = case ma of Just a -> (:) (pref, a) Nothing -> id - $ map (\(k, v) -> (pref <> k, v)) $ toList prefMap + $ map (first ((<>) pref)) $ toList prefMap {- | Converts 'PrefixMap' to the list of pairs. @@ -224,14 +224,14 @@ differenceWithT f pt1 pt2 = case (pt1, pt2) of [(_, aNew)] -> Just $ addPrefixT k aNew -- shouldn't happen, but for some reasons _ : _ : _ -> Nothing - Diff _ _ _ -> Just l + Diff {} -> Just l (br@(Branch p ma pma), Leaf k b) -> case keysDiff p k of Equal -> compressTree $ Branch p (ma >>= \a -> f a b) pma NoPrefix -> Just br FstIsPref kSuf -> compressTree $ Branch p ma (differenceWith f pma $ single kSuf b) SndIsPref _ -> Just br - Diff _ _ _ -> Just br + Diff {} -> Just br (b1@(Branch p1 ma pma), Branch p2 mb pmb) -> case keysDiff p1 p2 of Equal -> compressTree $ @@ -242,4 +242,4 @@ differenceWithT f pt1 pt2 = case (pt1, pt2) of SndIsPref p1Suf@(p1Head :|| _) -> case HashMap.lookup p1Head pmb of Nothing -> Just b1 Just ch -> addPrefixT p2 <$> differenceWithT f (Branch p1Suf ma pma) ch - Diff _ _ _ -> Just b1 + Diff {} -> Just b1