Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HLint #414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
76 changes: 76 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# HLint configuration file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the default file or some additional configurations were added here?
I think it is okay if we use the default one without adding the config file at all 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the default one

# 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
2 changes: 1 addition & 1 deletion src/Toml/Codec/BiMap/Conversion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
1 change: 0 additions & 1 deletion src/Toml/Codec/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}

{- |
Expand Down
6 changes: 3 additions & 3 deletions src/Toml/Codec/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}

Expand Down Expand Up @@ -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'.
Expand Down
8 changes: 4 additions & 4 deletions src/Toml/Parser/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Toml/Type/PrefixTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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 $
Expand All @@ -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