From 0ce7cc7443040ab54fe2ebeb3e3b9a2e1bcf267f Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 7 Oct 2022 15:54:33 +0200 Subject: [PATCH 1/4] CI: rwe/actions-hlint-run v2 --- .github/workflows/hlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/hlint.yml b/.github/workflows/hlint.yml index 053c49a03d..600d9ff669 100644 --- a/.github/workflows/hlint.yml +++ b/.github/workflows/hlint.yml @@ -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 From d83f02ca25f10c15df2c0c77c59a4c0f991b6d36 Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 7 Oct 2022 16:10:43 +0200 Subject: [PATCH 2/4] fmt script: Fix missing directories Otherwise will fail --- fmt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fmt.sh b/fmt.sh index c469a6be2c..1884d57e57 100755 --- a/fmt.sh +++ b/fmt.sh @@ -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 From f0b70075921d1a7c85c895f605bc23f78b8b3075 Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 7 Oct 2022 15:54:45 +0200 Subject: [PATCH 3/4] Hlint: Automatically fix warnings via apply-refact --- bench/Main.hs | 1 - exe/Wrapper.hs | 4 ++-- ghcide-bench/src/Experiments.hs | 2 +- ghcide/src/Development/IDE/Core/Compile.hs | 6 +++--- ghcide/src/Development/IDE/Core/Rules.hs | 2 +- ghcide/src/Development/IDE/Main.hs | 2 +- hie-compat/src-ghc86/Compat/HieDebug.hs | 6 ++---- hie-compat/src-ghc86/Compat/HieTypes.hs | 2 +- hie-compat/src-ghc86/Compat/HieUtils.hs | 2 +- hls-graph/src/Development/IDE/Graph/Internal/Database.hs | 2 +- hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs | 6 +++--- .../hls-alternate-number-format-plugin.cabal | 1 + .../src/Ide/Plugin/Conversion.hs | 9 +++++---- .../hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs | 3 ++- .../src/Ide/Plugin/ExplicitImports.hs | 2 +- shake-bench/src/Development/Benchmark/Rules.hs | 2 +- 16 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bench/Main.hs b/bench/Main.hs index 97d01f9537..2318d4a5e7 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -44,7 +44,6 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS -Wno-orphans #-} -{-# LANGUAGE PackageImports #-} import Control.Lens (preview, (^.)) import Control.Monad.Extra diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index b0a6484c85..b64c743cb7 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -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 @@ -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 diff --git a/ghcide-bench/src/Experiments.hs b/ghcide-bench/src/Experiments.hs index 1d8d6f6c5b..b6ab82226d 100644 --- a/ghcide-bench/src/Experiments.hs +++ b/ghcide-bench/src/Experiments.hs @@ -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 diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index e6094a470d..5b04963917 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -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 @@ -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))] @@ -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) diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index 72313a4661..5cb56379a8 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -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 $ diff --git a/ghcide/src/Development/IDE/Main.hs b/ghcide/src/Development/IDE/Main.hs index a344a46dd5..3f27e395aa 100644 --- a/ghcide/src/Development/IDE/Main.hs +++ b/ghcide/src/Development/IDE/Main.hs @@ -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 diff --git a/hie-compat/src-ghc86/Compat/HieDebug.hs b/hie-compat/src-ghc86/Compat/HieDebug.hs index c3df58f2f8..721d95e74f 100644 --- a/hie-compat/src-ghc86/Compat/HieDebug.hs +++ b/hie-compat/src-ghc86/Compat/HieDebug.hs @@ -1,7 +1,7 @@ {- Functions to validate and check .hie file ASTs generated by GHC. -} -{-# LANGUAGE StandaloneDeriving #-} + {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} module Compat.HieDebug where @@ -129,9 +129,7 @@ validateScopes asts = M.foldrWithKey (\k a b -> valid k a ++ b) [] refMap valid (Right n) refs = concatMap inScope refs where mapRef = foldMap getScopeFromContext . identInfo . snd - scopes = case foldMap mapRef refs of - Just xs -> xs - Nothing -> [] + scopes = Data.Maybe.fromMaybe [] (foldMap mapRef refs) inScope (sp, dets) | definedInAsts asts n && any isOccurrence (identInfo dets) diff --git a/hie-compat/src-ghc86/Compat/HieTypes.hs b/hie-compat/src-ghc86/Compat/HieTypes.hs index d17ec9a521..d3ed1170fa 100644 --- a/hie-compat/src-ghc86/Compat/HieTypes.hs +++ b/hie-compat/src-ghc86/Compat/HieTypes.hs @@ -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 #-} diff --git a/hie-compat/src-ghc86/Compat/HieUtils.hs b/hie-compat/src-ghc86/Compat/HieUtils.hs index 367e0adf2e..4eb5451913 100644 --- a/hie-compat/src-ghc86/Compat/HieUtils.hs +++ b/hie-compat/src-ghc86/Compat/HieUtils.hs @@ -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 diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs index f936687ebb..5bb4ed9ff4 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs @@ -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 #-} diff --git a/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs b/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs index 8e07af801d..60b700e0eb 100644 --- a/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs +++ b/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs @@ -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 @@ -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 @@ -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 diff --git a/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal b/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal index 041998756d..91198b3caf 100644 --- a/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal +++ b/plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal @@ -31,6 +31,7 @@ library aeson , base >=4.12 && < 5 , containers + , extra , ghcide ^>= 1.8 , ghc-boot-th , hls-graph diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs index 523ae6d37d..a6872121af 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Conversion.hs @@ -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) @@ -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 @@ -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" diff --git a/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs b/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs index 1fef9060b1..699e51f1f7 100644 --- a/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs +++ b/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs @@ -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 @@ -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 _) = diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 9c96678d5a..6021ce77fa 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -306,7 +306,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. diff --git a/shake-bench/src/Development/Benchmark/Rules.hs b/shake-bench/src/Development/Benchmark/Rules.hs index 7d5e4dcef9..4ffa6d22e6 100644 --- a/shake-bench/src/Development/Benchmark/Rules.hs +++ b/shake-bench/src/Development/Benchmark/Rules.hs @@ -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 () From 1ec2fea7680c6c03d0c139c69876871acd213d11 Mon Sep 17 00:00:00 2001 From: andys8 Date: Fri, 7 Oct 2022 17:18:53 +0200 Subject: [PATCH 4/4] Hlint: Do not suggest fromMaybe --- .hlint.yaml | 29 +++++++++++++------------ hie-compat/src-ghc86/Compat/HieDebug.hs | 6 +++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 324dbb2d55..369bb797f2 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -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 <=<"} @@ -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 @@ -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 @@ -116,7 +117,7 @@ - Wingman.Tactics - name: [Prelude.tail, Data.List.tail] - within: + within: - Main - Development.Benchmark.Rules - Development.IDE.Plugin.CodeAction @@ -125,7 +126,7 @@ - UnificationSpec - name: [Prelude.last, Data.List.last] - within: + within: - Main - Development.IDE.Plugin.CodeAction - Development.IDE.Plugin.CodeAction.ExactPrint @@ -136,7 +137,7 @@ - Ide.Plugin.Eval.CodeLens - name: [Prelude.init, Data.List.init] - within: + within: - Main - Development.IDE.Spans.Common - Ide.PluginUtils @@ -151,7 +152,7 @@ within: [] - name: ["Prelude.!!", "Data.List.!!"] - within: + within: - Main - Experiments - FunctionalCodeAction @@ -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 @@ -193,7 +194,7 @@ - Ide.Plugin.Class - name: "Data.Map.!" - within: + within: - Wingman.LanguageServer - name: "Data.IntMap.!" @@ -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 @@ -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 diff --git a/hie-compat/src-ghc86/Compat/HieDebug.hs b/hie-compat/src-ghc86/Compat/HieDebug.hs index 721d95e74f..c3df58f2f8 100644 --- a/hie-compat/src-ghc86/Compat/HieDebug.hs +++ b/hie-compat/src-ghc86/Compat/HieDebug.hs @@ -1,7 +1,7 @@ {- Functions to validate and check .hie file ASTs generated by GHC. -} - +{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} module Compat.HieDebug where @@ -129,7 +129,9 @@ validateScopes asts = M.foldrWithKey (\k a b -> valid k a ++ b) [] refMap valid (Right n) refs = concatMap inScope refs where mapRef = foldMap getScopeFromContext . identInfo . snd - scopes = Data.Maybe.fromMaybe [] (foldMap mapRef refs) + scopes = case foldMap mapRef refs of + Just xs -> xs + Nothing -> [] inScope (sp, dets) | definedInAsts asts n && any isOccurrence (identInfo dets)