From da5ab701da02c3cd34d7da1e48803278f777d9db Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Tue, 10 Sep 2019 16:31:43 +0200 Subject: [PATCH] Enable HLint --- .gitignore | 1 + .hlint.yaml | 120 ++++++++++++++++++++++++++++++++++++++++++++ azure-pipelines.yml | 3 ++ fmt.sh | 3 ++ 4 files changed, 127 insertions(+) create mode 100644 .hlint.yaml create mode 100755 fmt.sh diff --git a/.gitignore b/.gitignore index 22763241..10864ab1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist/ .stack-work/ dist-newstyle/ cabal.project.local +*~ diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 00000000..aefdb49f --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,120 @@ +# HLint configuration file +# https://github.com/ndmitchell/hlint +########################## + +# To run HLint do: +# $ hlint --git -j4 + +# Warnings currently triggered by our code +- ignore: {name: "Use <$>"} +- ignore: {name: "Use :"} +- ignore: {name: "Redundant do"} +- ignore: {name: "Avoid lambda"} +- ignore: {name: "Use newtype instead of data"} +- ignore: {name: "Use fromMaybe"} +- ignore: {name: "Use unless"} +- ignore: {name: "Move brackets to avoid $"} +- ignore: {name: "Eta reduce"} +- ignore: {name: "Parse error"} +- ignore: {name: "Reduce duplication"} +- ignore: {name: "Use ++"} +- ignore: {name: "Use $>"} +- ignore: {name: "Use section"} +- ignore: {name: "Use record patterns"} +- ignore: {name: "Use camelCase"} +- ignore: {name: "Use uncurry"} +- ignore: {name: "Avoid lambda using `infix`"} + +# Off by default hints we like +- warn: {name: Use module export list} + +# Condemn nub and friends +- warn: {lhs: nub (sort x), rhs: Data.List.Extra.nubSort x} +- warn: {lhs: nub, rhs: Data.List.Extra.nubOrd} +- warn: {lhs: nubBy, rhs: Data.List.Extra.nubOrdBy} +- warn: {lhs: Data.List.Extra.nubOn, rhs: Data.List.Extra.nubOrdOn} + +# DA specific hints +- warn: {lhs: Data.Text.pack (DA.Pretty.renderPlain x), rhs: DA.Pretty.renderPlain x} +- warn: {lhs: Data.Text.Extended.pack (DA.Pretty.renderPlain x), rhs: DA.Pretty.renderPlain x} +- warn: {lhs: DA.Pretty.renderPlain (DA.Pretty.pretty x), rhs: DA.Pretty.renderPretty x} +- warn: {lhs: Data.Text.readFile, rhs: Data.Text.Extended.readFileUtf8} +- warn: {lhs: Data.Text.writeFile, rhs: Data.Text.Extended.writeFileUtf8} +- warn: {lhs: Data.Text.Lazy.readFile, rhs: Data.Text.Extended.readFileUtf8} +- warn: {lhs: Data.Text.Lazy.writeFile, rhs: Data.Text.Extended.writeFileUtf8} +- warn: {lhs: System.Environment.setEnv, rhs: System.Environment.Blank.setEnv} + +# Specify additional command line arguments +# +# - arguments: [--color, --cpp-simple, -XQuasiQuotes] + +- extensions: + - default: true + + # Extensions enabled by `bazel` and `da-ghci` by default. We ban them here + # to avoid useless pragmas piling up on the top of files. + - {name: BangPatterns, within: []} + - {name: DeriveDataTypeable, within: []} + - {name: DeriveFoldable, within: []} + - {name: DeriveFunctor, within: []} + - {name: DeriveGeneric, within: []} + - {name: DeriveTraversable, within: []} + - {name: FlexibleContexts, within: []} + - {name: GeneralizedNewtypeDeriving, within: []} + - {name: LambdaCase, within: []} + - {name: NamedFieldPuns, within: []} + - {name: OverloadedStrings, within: []} + - {name: PackageImports, within: []} + - {name: RecordWildCards, within: []} + - {name: ScopedTypeVariables, within: []} + - {name: StandaloneDeriving, within: []} + - {name: TupleSections, within: []} + - {name: TypeApplications, within: []} + - {name: ViewPatterns, within: []} + + # Shady extensions + - {name: ImplicitParams, within: []} + - name: CPP + within: + - Development.IDE.Core.FileStore + - Development.IDE.Core.Compile + - Development.IDE.GHC.Compat + - Development.IDE.GHC.Util + - Development.IDE.Import.FindImports + - Development.IDE.Spans.Calculate + +- flags: + - default: false + - {name: [-Wno-missing-signatures, -Wno-orphans, -Wno-overlapping-patterns, -Wno-incomplete-patterns, -Wno-missing-fields, -Wno-unused-matches]} + - {name: [-Wno-dodgy-imports], within: Main} +# - 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: unsafeInterleaveIO, within: []} + - {name: unsafeDupablePerformIO, within: []} + - {name: unsafeCoerce, within: []} + +# Add custom hints for this project +# +# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar" +# - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x} + +# 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 ~^#^~ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1c68a0bb..1a4747ef 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,9 @@ jobs: tar xzf .azure-cache/stack-root.tar.gz -C $HOME displayName: "Unpack cache" condition: eq(variables.CACHE_RESTORED, 'true') + - bash: | + ./fmt.sh + displayName: "HLint via ./fmt.sh" - bash: | sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev curl -sSL https://get.haskellstack.org/ | sh diff --git a/fmt.sh b/fmt.sh new file mode 100755 index 00000000..54e5440c --- /dev/null +++ b/fmt.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -eou pipefail +curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s .