Skip to content

Commit

Permalink
Hlint: A handful of fixes to hints (haskell#3259)
Browse files Browse the repository at this point in the history
* CI: rwe/actions-hlint-run v2

* fmt script: Fix missing directories

Otherwise will fail

* Hlint: Automatically fix warnings via apply-refact

* Hlint: Do not suggest fromMaybe

Co-authored-by: Michael Peyton Jones <[email protected]>
  • Loading branch information
andys8 and michaelpj authored Oct 10, 2022
1 parent 050497a commit 21c8e9b
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
version: '3.4'

- name: 'Checking code'
uses: rwe/actions-hlint-run@v1
uses: rwe/actions-hlint-run@v2
with:
hlint-bin: "hlint --with-group=extra"
fail-on: error
Expand Down
29 changes: 15 additions & 14 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- ignore: {name: "Use camelCase"}
- ignore: {name: "Use uncurry"}
- ignore: {name: "Avoid lambda using `infix`"}
- ignore: {name: "Replace case with fromMaybe"}

# Gives at least one suggestion we don't like.
- ignore: {name: "Use <=<"}
Expand Down Expand Up @@ -65,11 +66,11 @@
- Wingman.Types
- AutoTupleSpec
- name: unsafeInterleaveIO
within:
within:
- Development.IDE.LSP.LanguageServer
- {name: unsafeDupablePerformIO, within: []}
- name: unsafeCoerce
within:
within:
- Ide.Plugin.Eval.Code
- Development.IDE.Core.Compile
- Development.IDE.Types.Shake
Expand All @@ -85,12 +86,12 @@
- Compat.HieBin

# Partial functions

# We need to check fucntions which
# are typically exported multiple ways under both names,
# see https://github.com/ndmitchell/hlint/issues/1389
- name: [Prelude.head, Data.List.head]
within:
within:
- Main
- Experiments
- Development.Benchmark.Rules
Expand All @@ -116,7 +117,7 @@
- Wingman.Tactics

- name: [Prelude.tail, Data.List.tail]
within:
within:
- Main
- Development.Benchmark.Rules
- Development.IDE.Plugin.CodeAction
Expand All @@ -125,7 +126,7 @@
- UnificationSpec

- name: [Prelude.last, Data.List.last]
within:
within:
- Main
- Development.IDE.Plugin.CodeAction
- Development.IDE.Plugin.CodeAction.ExactPrint
Expand All @@ -136,7 +137,7 @@
- Ide.Plugin.Eval.CodeLens

- name: [Prelude.init, Data.List.init]
within:
within:
- Main
- Development.IDE.Spans.Common
- Ide.PluginUtils
Expand All @@ -151,7 +152,7 @@
within: []

- name: ["Prelude.!!", "Data.List.!!"]
within:
within:
- Main
- Experiments
- FunctionalCodeAction
Expand All @@ -171,11 +172,11 @@
within: []

- name: Data.Foldable.foldr1
within:
within:
- Wingman.Tactics

- name: Data.Maybe.fromJust
within:
- name: Data.Maybe.fromJust
within:
- Experiments
- Main
- MultipleImports
Expand All @@ -193,7 +194,7 @@
- Ide.Plugin.Class

- name: "Data.Map.!"
within:
within:
- Wingman.LanguageServer

- name: "Data.IntMap.!"
Expand All @@ -210,7 +211,7 @@
# Debug.Trace, because that module also
# includes the eventlog tracing functions,
# which are legitimate to use.
- name:
- name:
- Debug.Trace.trace
- Debug.Trace.traceId
- Debug.Trace.traceShow
Expand All @@ -220,7 +221,7 @@
- Debug.Trace.traceM
- Debug.Trace.traceShowM
- Debug.Trace.putTraceMsg
within:
within:
- Development.IDE.Core.Compile
- Development.IDE.Graph.Internal.Database
- Development.IDE.GHC.Util
Expand Down
1 change: 0 additions & 1 deletion bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS -Wno-orphans #-}
{-# LANGUAGE PackageImports #-}

import Control.Lens (preview, (^.))
import Control.Monad.Extra
Expand Down
4 changes: 2 additions & 2 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
module Main where

import Control.Monad.Extra
import Data.Char (isSpace)
import Data.Default
import Data.Either.Extra (eitherToMaybe)
import Data.Foldable
import Data.List
import Data.List.Extra (trimEnd)
import Data.Void
import qualified Development.IDE.Session as Session
import qualified HIE.Bios.Environment as HieBios
Expand Down Expand Up @@ -232,7 +232,7 @@ findProjectCradle' log = do
trim :: String -> String
trim s = case lines s of
[] -> s
ls -> dropWhileEnd isSpace $ last ls
ls -> trimEnd $ last ls

data WrapperSetupError
= FailedToObtainGhcVersion (ActionName Void) CradleError
Expand Down
2 changes: 1 addition & 1 deletion fmt.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
set -eou pipefail
curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s ghcide/src ghcide/exe ghcide/bench/lib ghcide/bench/exe ghcide/bench/hist shake-bench/src ghcide/test/exe --with-group=extra --hint=ghcide/.hlint.yaml
curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s ghcide/src ghcide/exe ghcide-bench/exe shake-bench/src ghcide/test/exe --with-group=extra --hint=.hlint.yaml
2 changes: 1 addition & 1 deletion ghcide-bench/src/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ runBench runSess b = handleAny (\e -> print e >> return badRun)
output (showDuration t)
-- Wait for the delayed actions to finish
td <- waitForBuildQueue
loop' (timeForFirstResponse <|> (Just (t,td))) (userWaits+t) (delayedWork+td) (n -1)
loop' (timeForFirstResponse <|> Just (t,td)) (userWaits+t) (delayedWork+td) (n -1)
loop = loop' Nothing

(runExperiment, result) <- duration $ loop 0 0 samples
Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
mods_transitive = getTransitiveMods hsc_env needed_mods

-- If we don't support multiple home units, ModuleNames are sufficient because all the units will be the same
mods_transitive_list =
mods_transitive_list =
#if MIN_VERSION_ghc(9,3,0)
mapMaybe nodeKeyToInstalledModule $ Set.toList mods_transitive
#else
Expand Down Expand Up @@ -362,7 +362,7 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
#endif

-- Compute the transitive set of linkables required
getTransitiveMods hsc_env needed_mods
getTransitiveMods hsc_env needed_mods
#if MIN_VERSION_ghc(9,3,0)
= Set.unions (Set.fromList (map moduleToNodeKey mods) : [ dep | m <- mods
, Just dep <- [Map.lookup (moduleToNodeKey m) (mgTransDeps (hsc_mod_graph hsc_env))]
Expand Down Expand Up @@ -561,7 +561,7 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do


when (not $ null diffs) $
panicDoc "verify core failed!" (vcat $ punctuate (text "\n\n") (diffs )) -- ++ [ppr binds , ppr binds']))
panicDoc "verify core failed!" (vcat $ punctuate (text "\n\n") diffs) -- ++ [ppr binds , ppr binds']))
_ -> pure ()

pure ([], Just $! mkHiFileResult ms final_iface details (tmrRuntimeModules tcm) core_file)
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ typeCheckRuleDefinition hsc pm = do

unlift <- askUnliftIO
let dets = TypecheckHelpers
{ getLinkablesToKeep = unliftIO unlift $ currentLinkables
{ getLinkablesToKeep = unliftIO unlift currentLinkables
, getLinkables = unliftIO unlift . uses_ GetLinkable
}
addUsageDependencies $ liftIO $
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ testing recorder logger =
hlsPlugins = pluginDescToIdePlugins $
idePluginsToPluginDesc argsHlsPlugins
++ [Test.blockCommandDescriptor "block-command", Test.plugin]
ideOptions = \config sessionLoader ->
ideOptions config sessionLoader =
let
defOptions = argsIdeOptions config sessionLoader
in
Expand Down
2 changes: 1 addition & 1 deletion hie-compat/src-ghc86/Compat/HieTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ For more information see https://gitlab.haskell.org/ghc/ghc/wikis/hie-files
-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeSynonymInstances #-}

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-orphans #-}
Expand Down
2 changes: 1 addition & 1 deletion hie-compat/src-ghc86/Compat/HieUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ recoverFullType i m = go i

getTypeIndex :: Type -> State HieTypeState TypeIndex
getTypeIndex t
| otherwise = do
= do
tm <- gets tyMap
case lookupTypeMap tm t of
Just i -> return i
Expand Down
2 changes: 1 addition & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Database.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- We deliberately want to ensure the function we add to the rule database
-- has the constraints we need on it when we get it out.
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
{-# LANGUAGE DeriveFunctor #-}

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
Expand Down
6 changes: 3 additions & 3 deletions hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import qualified Data.Aeson.Types as A
import Data.Default (def)
import qualified Data.Dependent.Map as DMap
import qualified Data.Dependent.Sum as DSum
import Data.List (nub)
import Data.List.Extra (nubOrd)
import Data.String (IsString (fromString))
import qualified Data.Text as T
import Ide.Plugin.Config
Expand Down Expand Up @@ -62,7 +62,7 @@ pluginsToDefaultConfig IdePlugins {..} =
-- }
--
genericDefaultConfig =
let x = ["diagnosticsOn" A..= True | configHasDiagnostics] <> nub (mconcat (handlersToGenericDefaultConfig <$> handlers))
let x = ["diagnosticsOn" A..= True | configHasDiagnostics] <> nubOrd (mconcat (handlersToGenericDefaultConfig <$> handlers))
in case x of
-- if the plugin has only one capability, we produce globalOn instead of the specific one;
-- otherwise we don't produce globalOn at all
Expand Down Expand Up @@ -106,7 +106,7 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
genericSchema =
let x =
[toKey' "diagnosticsOn" A..= schemaEntry "diagnostics" | configHasDiagnostics]
<> nub (mconcat (handlersToGenericSchema <$> handlers))
<> nubOrd (mconcat (handlersToGenericSchema <$> handlers))
in case x of
-- If the plugin has only one capability, we produce globalOn instead of the specific one;
-- otherwise we don't produce globalOn at all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ library
aeson
, base >=4.12 && < 5
, containers
, extra
, ghcide ^>= 1.8
, ghc-boot-th
, hls-graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Ide.Plugin.Conversion (

import Data.Char (toUpper)
import Data.List (delete)
import Data.List.Extra (enumerate, upper)
import Data.Maybe (mapMaybe)
import Data.Ratio (denominator, numerator)
import Data.Text (Text)
Expand Down Expand Up @@ -108,10 +109,10 @@ filterFracFormats = mapMaybe getFracFormat
getFracFormat _ = Nothing

intFormats :: [IntFormatType]
intFormats = [minBound .. maxBound]
intFormats = enumerate

fracFormats :: [FracFormatType]
fracFormats = [minBound .. maxBound]
fracFormats = enumerate

-- | Regex to match a Haskell Hex Literal
hexRegex :: Text
Expand Down Expand Up @@ -157,8 +158,8 @@ sourceToFormatType srcText

toBase :: (Num a, Ord a) => (a -> ShowS) -> String -> a -> String
toBase conv header n
| n < 0 = '-' : header <> map toUpper (conv (abs n) "")
| otherwise = header <> map toUpper (conv n "")
| n < 0 = '-' : header <> upper (conv (abs n) "")
| otherwise = header <> upper (conv n "")

toOctal :: (Integral a, Show a) => a -> String
toOctal = toBase showOct "0o"
Expand Down
3 changes: 2 additions & 1 deletion plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Maybe (MaybeT (MaybeT),
maybeToExceptT)
import Data.Either.Extra (maybeToEither)
import Data.List.Extra (drop1)
import Data.Maybe (fromMaybe)
import Data.Vector (Vector)
import qualified Data.Vector as V
Expand Down Expand Up @@ -206,7 +207,7 @@ findPosition pos root = go Nothing root
findFoldingRanges :: CodeRange -> [FoldingRange]
findFoldingRanges codeRange =
-- removing the first node because it folds the entire file
drop 1 $ findFoldingRangesRec codeRange
drop1 $ findFoldingRangesRec codeRange

findFoldingRangesRec :: CodeRange -> [FoldingRange]
findFoldingRangesRec r@(CodeRange _ children _) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ abbreviateImportTitle input =
oneLineText = T.unwords $ T.lines input
-- Now, split at the max columns, leaving space for the summary text we're going to add
-- (conservatively assuming we won't need to print a number larger than 100)
(prefix, suffix) = T.splitAt (maxColumns - (T.length (summaryText 100))) oneLineText
(prefix, suffix) = T.splitAt (maxColumns - T.length (summaryText 100)) oneLineText
-- We also want to truncate the last item so we get a "clean" break, rather than half way through
-- something. The conditional here is just because 'breakOnEnd' doesn't give us quite the right thing
-- if there are actually no commas.
Expand Down
2 changes: 1 addition & 1 deletion shake-bench/src/Development/Benchmark/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ plotDiagram includeFailed t@Diagram {traceMetric, runLogs} out = do
]
]
return (lplot E.& E.plot_lines_style . E.line_width E.*~ 2)
case (runFirstReponse rl) of
case runFirstReponse rl of
Just t -> E.plot $ pure $
E.vlinePlot ("First build: " ++ runVersion rl) (E.defaultPlotLineStyle E.& E.line_color E..~ c) t
_ -> pure ()
Expand Down

0 comments on commit 21c8e9b

Please sign in to comment.