Skip to content

Commit 6576637

Browse files
Hlint fixes.
1 parent 4d431e9 commit 6576637

File tree

36 files changed

+119
-164
lines changed

36 files changed

+119
-164
lines changed

GenChangelogs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main = do
2424

2525
prs <- github' $ pullRequestsForR "haskell" "haskell-language-server" stateClosed FetchAll
2626
let prsAfterLastTag = either (error . show)
27-
(foldMap (\pr -> if inRange pr then [pr] else []))
27+
(foldMap (\pr -> [pr | inRange pr]))
2828
prs
2929
inRange pr
3030
| Just mergedDate <- simplePullRequestMergedAt pr = mergedDate > lastDate

ghcide/.hlint.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
- ignore: {name: "Redundant do"}
1212
- ignore: {name: "Avoid lambda"}
1313
- ignore: {name: "Use newtype instead of data"}
14-
- ignore: {name: "Use fromMaybe"}
1514
- ignore: {name: "Use unless"}
1615
- ignore: {name: "Move brackets to avoid $"}
1716
- ignore: {name: "Eta reduce"}
@@ -25,6 +24,16 @@
2524
- ignore: {name: "Use uncurry"}
2625
- ignore: {name: "Avoid lambda using `infix`"}
2726

27+
# We are using the "redundant" return/pure to assign a name. We do not want to
28+
# delete it. In particular, this is not an improvement:
29+
# Found:
30+
# do options <- somethingComplicated
31+
# pure options
32+
# Perhaps:
33+
# do somethingComplicated
34+
- ignore: {name: "Redundant return"}
35+
- ignore: {name: "Redundant pure"}
36+
2837
# Off by default hints we like
2938
- warn: {name: Use module export list}
3039

@@ -107,7 +116,7 @@
107116
# Things that are unsafe in Haskell base library
108117
- {name: unsafeInterleaveIO, within: []}
109118
- {name: unsafeDupablePerformIO, within: []}
110-
- {name: unsafeCoerce, within: []}
119+
- {name: unsafeCoerce, within: [Ide.Plugin.Eval.Code]}
111120
# Things that are a bit dangerous in the GHC API
112121
- {name: nameModule, within: []}
113122

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ setInitialDynFlags = do
120120
hPutStrLn stderr $ "Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
121121
pure Nothing
122122
CradleNone -> do
123-
hPutStrLn stderr $ "Couldn't load cradle (CradleNone)"
123+
hPutStrLn stderr "Couldn't load cradle (CradleNone)"
124124
pure Nothing
125125
dynFlags <- mapM dynFlagsForPrinting libdir
126126
mapM_ setUnsafeGlobalDynFlags dynFlags

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ documentHighlight hf rf pos = pure highlights
158158
ns = concat $ pointCommand hf pos (rights . M.keys . nodeIdentifiers . nodeInfo)
159159
highlights = do
160160
n <- ns
161-
ref <- maybe [] id (M.lookup (Right n) rf)
161+
ref <- fromMaybe [] (M.lookup (Right n) rf)
162162
pure $ makeHighlight ref
163163
makeHighlight (sp,dets) =
164164
DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets)
@@ -266,12 +266,12 @@ typeLocationsAtPoint hiedb lookupModule _ideOptions pos (HAR _ ast _ _ hieKind)
266266
HQualTy a b -> getTypes [a,b]
267267
HCastTy a -> getTypes [a]
268268
_ -> []
269-
in fmap nubOrd $ concatMapM (fmap (maybe [] id) . nameToLocation hiedb lookupModule) (getTypes ts)
269+
in fmap nubOrd $ concatMapM (fmap (fromMaybe []) . nameToLocation hiedb lookupModule) (getTypes ts)
270270
HieFresh ->
271271
let ts = concat $ pointCommand ast pos getts
272272
getts x = nodeType ni ++ (mapMaybe identType $ M.elems $ nodeIdentifiers ni)
273273
where ni = nodeInfo x
274-
in fmap nubOrd $ concatMapM (fmap (maybe [] id) . nameToLocation hiedb lookupModule) (getTypes ts)
274+
in fmap nubOrd $ concatMapM (fmap (fromMaybe []) . nameToLocation hiedb lookupModule) (getTypes ts)
275275

276276
namesInType :: Type -> [Name]
277277
namesInType (TyVarTy n) = [Var.varName n]

hls-plugin-api/src/Ide/PluginUtils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ clientSupportsDocumentChanges caps =
135135
WorkspaceEditClientCapabilities mDc _ _ <- _workspaceEdit wCaps
136136
mDc
137137
in
138-
fromMaybe False supports
138+
Just True == supports
139139

140140
-- ---------------------------------------------------------------------
141141

@@ -214,7 +214,7 @@ allLspCmdIds' pid mp = mkPlugin (allLspCmdIds pid) (Just . pluginCommands)
214214

215215

216216
allLspCmdIds :: T.Text -> [(PluginId, [PluginCommand ideState])] -> [T.Text]
217-
allLspCmdIds pid commands = concat $ map go commands
217+
allLspCmdIds pid commands = concatMap go commands
218218
where
219219
go (plid, cmds) = map (mkLspCmdId pid plid . commandId) cmds
220220

hls-plugin-api/src/Ide/Types.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE GADTs #-}
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
4-
{-# LANGUAGE TupleSections #-}
54
{-# LANGUAGE FlexibleContexts #-}
65
{-# LANGUAGE PolyKinds #-}
76
{-# LANGUAGE ViewPatterns #-}

install/src/Cabal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ getProjectFile ver = do
9696
else "cabal.project"
9797

9898
checkCabal_ :: [String] -> Action ()
99-
checkCabal_ args = checkCabal args >> return ()
99+
checkCabal_ args = void $ checkCabal args
100100

101101
-- | check `cabal` has the required version
102102
checkCabal :: [String] -> Action String

install/src/Env.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ findInstalledGhcs = do
5454
-- sort by version to make it coherent with getHlsVersions
5555
$ sortBy (comparing fst)
5656
-- nub by version. knownGhcs takes precedence.
57-
$ nubBy ((==) `on` fst)
57+
$ nubOrdBy (compare `on` fst)
5858
-- filter out stack provided GHCs (assuming that stack programs path is the default one in linux)
5959
$ filter (not . isInfixOf ".stack" . snd) (knownGhcs ++ availableGhcs)
6060

install/src/Print.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ printInStars = liftIO . putStrLn . embedInStars
2525

2626
-- | Trim whitespace of both ends of a string
2727
trim :: String -> String
28-
trim = dropWhileEnd isSpace . dropWhile isSpace
28+
trim = trimEnd . trimStart
2929

3030
-- | Trim the whitespace of the stdout of a command
3131
trimmedStdout :: Stdout String -> String

plugins/default/src/Ide/Plugin/Fourmolu.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable
9393

9494
convertDynFlags :: DynFlags -> IO [DynOption]
9595
convertDynFlags df =
96-
let pp = if null p then [] else ["-pgmF=" <> p]
96+
let pp = ["-pgmF=" <> p | not (null p)]
9797
p = D.sPgm_F $ D.settings df
9898
pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df
9999
ex = map showExtension $ S.toList $ D.extensionFlags df

plugins/default/src/Ide/Plugin/Ormolu.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ provider ideState typ contents fp _ = withIndefiniteProgress title Cancellable $
4444
let
4545
pp =
4646
let p = D.sPgm_F $ D.settings df
47-
in if null p then [] else ["-pgmF=" <> p]
47+
in ["-pgmF=" <> p | not (null p)]
4848
pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df
4949
ex = map showExtension $ S.toList $ D.extensionFlags df
5050
in

plugins/default/src/Ide/Plugin/Pragmas.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE DeriveAnyClass #-}
2-
{-# LANGUAGE DeriveGeneric #-}
31
{-# LANGUAGE DuplicateRecordFields #-}
42
{-# LANGUAGE OverloadedStrings #-}
53
{-# LANGUAGE ViewPatterns #-}
@@ -12,6 +10,7 @@ module Ide.Plugin.Pragmas
1210

1311
import Control.Lens hiding (List)
1412
import qualified Data.HashMap.Strict as H
13+
import Data.Maybe (catMaybes)
1514
import qualified Data.Text as T
1615
import Development.IDE as D
1716
import Ide.Types
@@ -78,7 +77,7 @@ codeActionProvider state _plId (CodeActionParams _ _ docId _ (J.CodeActionContex
7877
disabled
7978
| Just dynFlags <- mDynflags
8079
-- GHC does not export 'OnOff', so we have to view it as string
81-
= [ e | Just e <- T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags]
80+
= catMaybes $ T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags
8281
| otherwise
8382
-- When the module failed to parse, we don't have access to its
8483
-- dynFlags. In that case, simply don't disable any pragmas.

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{-# LANGUAGE TypeApplications #-}
22
{-# LANGUAGE ViewPatterns #-}
33
{-# LANGUAGE LambdaCase #-}
4-
{-# LANGUAGE DeriveAnyClass #-}
5-
{-# LANGUAGE DeriveGeneric #-}
64
{-# LANGUAGE DuplicateRecordFields #-}
75
{-# LANGUAGE ExtendedDefaultRules #-}
86
{-# LANGUAGE FlexibleContexts #-}

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type Loc = Located Line
5555

5656
type Line = Int
5757

58+
{- HLINT ignore locate "Use zipWithFrom" -}
59+
5860
locate :: Loc [a] -> [Loc a]
5961
locate (Located l tst) = zipWith Located [l ..] tst
6062

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Ide.Plugin.Eval.Util (
1515
logWith,
1616
) where
1717

18+
import Control.Monad.Extra (maybeM)
1819
import Control.Monad.IO.Class (MonadIO (liftIO))
1920
import Control.Monad.Trans.Class (lift)
2021
import Control.Monad.Trans.Except (
@@ -84,7 +85,7 @@ handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b
8485
handleMaybe msg = maybe (throwE msg) return
8586

8687
handleMaybeM :: Monad m => e -> m (Maybe b) -> ExceptT e m b
87-
handleMaybeM msg act = maybe (throwE msg) return =<< lift act
88+
handleMaybeM msg act = maybeM (throwE msg) return $ lift act
8889

8990
response :: Functor f => ExceptT String f c -> f (Either ResponseError c)
9091
response =

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right
278278
in LSP.CodeAction "Apply all hints" (Just LSP.CodeActionQuickFix) Nothing Nothing Nothing Nothing (Just cmd)
279279

280280
applyOneActions :: [LSP.CodeAction]
281-
applyOneActions = catMaybes $ map mkHlintAction (filter validCommand diags)
281+
applyOneActions = mapMaybe mkHlintAction (filter validCommand diags)
282282

283283
-- |Some hints do not have an associated refactoring
284284
validCommand (LSP.Diagnostic _ _ (Just (InR code)) (Just "hlint") _ _ _) =

plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Control.Concurrent.Extra (readVar)
2020
import Control.Exception.Safe (Exception (..), SomeException,
2121
catch, throwIO, try)
2222
import Control.Monad (forM, unless)
23+
import Control.Monad.Extra (maybeM)
2324
import Control.Monad.IO.Class (MonadIO (liftIO))
2425
import Control.Monad.Trans.Class (MonadTrans (lift))
2526
import Control.Monad.Trans.Except (ExceptT (..), runExceptT,
@@ -146,14 +147,14 @@ extractImports ModSummary{ms_mod} topLevelBinds (Unfold thing)
146147
, names <- listify p fun_matches
147148
=
148149
[ AddImport {..}
149-
| name <- names,
150-
Just ideclNameString <-
151-
[moduleNameString . GHC.moduleName <$> nameModule_maybe name],
152-
let ideclSource = False,
150+
| let ideclSource = False,
151+
name <- names,
153152
let r = nameRdrName name,
154153
let ideclQualifiedBool = isQual r,
155154
let ideclAsString = moduleNameString . fst <$> isQual_maybe r,
156-
let ideclThing = Just (IEVar $ occNameString $ rdrNameOcc r)
155+
let ideclThing = Just (IEVar $ occNameString $ rdrNameOcc r),
156+
Just ideclNameString <-
157+
[moduleNameString . GHC.moduleName <$> nameModule_maybe name]
157158
]
158159
where
159160
p name = nameModule_maybe name /= Just ms_mod
@@ -178,8 +179,8 @@ provider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) range ca)
178179
++ [ r
179180
| TyClGroup {group_tyclds} <- hs_tyclds,
180181
L l g <- group_tyclds,
181-
r <- suggestTypeRewrites uri ms_mod g,
182-
pos `isInsideSrcSpan` l
182+
pos `isInsideSrcSpan` l,
183+
r <- suggestTypeRewrites uri ms_mod g
183184

184185
]
185186

@@ -235,7 +236,6 @@ suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName}
235236
description = "Fold " <> pprNameText <> describeRestriction restrictToOriginatingFile
236237
in (description, CodeActionRefactorExtract, RunRetrieParams {..})
237238
in [unfoldRewrite False, unfoldRewrite True, foldRewrite False, foldRewrite True]
238-
where
239239
suggestBindRewrites _ _ _ _ = []
240240

241241
describeRestriction :: IsString p => Bool -> p
@@ -409,9 +409,7 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do
409409
-- TODO add the imports to the resulting edits
410410
(_user, ast, change@(Change _replacements _imports)) <-
411411
lift $ runRetrie fixityEnv retrie cpp
412-
case ast of
413-
_ ->
414-
return $ asTextEdits change
412+
return $ asTextEdits change
415413

416414
let (errors :: [CallRetrieError], replacements) = partitionEithers results
417415
editParams :: WorkspaceEdit
@@ -485,7 +483,7 @@ handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b
485483
handleMaybe msg = maybe (throwE msg) return
486484

487485
handleMaybeM :: Monad m => e -> m (Maybe b) -> ExceptT e m b
488-
handleMaybeM msg act = maybe (throwE msg) return =<< lift act
486+
handleMaybeM msg act = maybeM (throwE msg) return $ lift act
489487

490488
response :: Monad m => ExceptT String m a -> m (Either ResponseError a)
491489
response =

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ library
1818
build-depends: aeson
1919
, base >=4.12 && <5
2020
, containers
21+
, extra
2122
, foldl
2223
, lsp
2324
, hls-plugin-api

plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Control.Arrow
2525
import qualified Control.Foldl as L
2626
import Control.Lens (ix, view, (%~), (<&>), (^.))
2727
import Control.Monad
28+
import Control.Monad.Extra (eitherM)
2829
import qualified Control.Monad.Fail as Fail
2930
import Control.Monad.Trans.Class
3031
import Control.Monad.Trans.Except
@@ -324,8 +325,8 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e
324325
graftDeclsWithM (RealSrcSpan srcSpan) $ \case
325326
(L _spn (SpliceD _ (SpliceDecl _ (L _ spl) _))) -> do
326327
eExpr <-
327-
either (fail . show) pure
328-
=<< lift
328+
eitherM (fail . show) pure
329+
$ lift
329330
( lift $
330331
gtry @_ @SomeException $
331332
(fst <$> rnTopSpliceDecls spl)
@@ -337,8 +338,8 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e
337338
graftWithM (RealSrcSpan srcSpan) $ \case
338339
(L _spn (matchSplice astP -> Just spl)) -> do
339340
eExpr <-
340-
either (fail . show) pure
341-
=<< lift
341+
eitherM (fail . show) pure
342+
$ lift
342343
( lift $
343344
gtry @_ @SomeException $
344345
(fst <$> expandSplice astP spl)

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Data.Functor ((<&>))
2727
import Data.Generics.Aliases (mkQ)
2828
import Data.Generics.Schemes (everything)
2929
import Data.List
30+
import Data.List.Extra (enumerate)
3031
import Data.Map (Map)
3132
import qualified Data.Map as M
3233
import Data.Maybe
@@ -75,7 +76,7 @@ descriptor plId = (defaultPluginDescriptor plId)
7576
(tcCommandId tc)
7677
(tacticDesc $ tcCommandName tc)
7778
(tacticCmd $ commandTactic tc))
78-
[minBound .. maxBound]
79+
(enumerate :: [TacticCommand])
7980
, pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider
8081
}
8182

@@ -173,7 +174,7 @@ codeActionProvider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri)
173174
(_, jdg, _, dflags) <- judgementForHole state nfp range
174175
actions <- lift $
175176
-- This foldMap is over the function monoid.
176-
foldMap commandProvider [minBound .. maxBound]
177+
foldMap commandProvider (enumerate :: [TacticCommand])
177178
dflags
178179
plId
179180
uri
@@ -207,19 +208,19 @@ provide tc name _ plId uri range _ = do
207208
-- predicate holds for the goal.
208209
requireExtension :: Extension -> TacticProvider -> TacticProvider
209210
requireExtension ext tp dflags plId uri range jdg =
210-
case xopt ext dflags of
211-
True -> tp dflags plId uri range jdg
212-
False -> pure []
211+
if xopt ext dflags
212+
then tp dflags plId uri range jdg
213+
else pure []
213214

214215

215216
------------------------------------------------------------------------------
216217
-- | Restrict a 'TacticProvider', making sure it appears only when the given
217218
-- predicate holds for the goal.
218219
filterGoalType :: (Type -> Bool) -> TacticProvider -> TacticProvider
219220
filterGoalType p tp dflags plId uri range jdg =
220-
case p $ unCType $ jGoal jdg of
221-
True -> tp dflags plId uri range jdg
222-
False -> pure []
221+
if p $ unCType $ jGoal jdg
222+
then tp dflags plId uri range jdg
223+
else pure []
223224

224225

225226
------------------------------------------------------------------------------
@@ -234,9 +235,9 @@ filterBindingType p tp dflags plId uri range jdg =
234235
g = jGoal jdg
235236
in fmap join $ for (unHypothesis hy) $ \hi ->
236237
let ty = unCType $ hi_type hi
237-
in case p (unCType g) ty of
238-
True -> tp (hi_name hi) ty dflags plId uri range jdg
239-
False -> pure []
238+
in if p (unCType g) ty
239+
then tp (hi_name hi) ty dflags plId uri range jdg
240+
else pure []
240241

241242

242243
data TacticParams = TacticParams

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/CodeGen.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE TupleSections #-}
33
{-# LANGUAGE TypeApplications #-}
4-
{-# LANGUAGE ViewPatterns #-}
54

65
module Ide.Plugin.Tactic.CodeGen
76
( module Ide.Plugin.Tactic.CodeGen
@@ -202,4 +201,3 @@ buildDataCon jdg dc tyapps = do
202201
pure
203202
. (rose (show dc) $ pure tr,)
204203
$ mkCon dc sgs
205-

0 commit comments

Comments
 (0)