Skip to content
Snippets Groups Projects
Commit 6d26911d authored by Jens Nolte's avatar Jens Nolte
Browse files

Convert trace warnings to hlint rules


Co-authored-by: default avatarJan Beinke <git@janbeinke.com>
parent a9c2fe5b
No related branches found
No related tags found
No related merge requests found
# HLint configuration file
# 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
# 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
- functions:
- message: "Traces are not allowed in production code"
within: [Quasar.Prelude]
name:
- trace
- traceId
- traceShow
- traceShowId
- traceM
- traceShowM
- traceIO
- traceShowIO
- traceShowIdIO
# 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
......@@ -40,6 +40,7 @@
pkgs.entr
pkgs.ghcid
pkgs.haskell-language-server
pkgs.hlint
];
}
);
......
......@@ -31,8 +31,8 @@ module Quasar.Prelude
Data.Void.Void,
Data.Hashable.Hashable,
GHC.Generics.Generic,
MonadIO,
liftIO,
Control.Monad.IO.Class.MonadIO,
Control.Monad.IO.Class.liftIO,
Data.Maybe.catMaybes,
Data.Maybe.fromMaybe,
Data.Maybe.isJust,
......@@ -49,15 +49,12 @@ module Quasar.Prelude
Data.Word.Word64,
error,
errorWithoutStackTrace,
head,
last,
read,
trace,
traceId,
traceShow,
traceShowId,
traceM,
traceShowM,
Debug.Trace.trace,
Debug.Trace.traceId,
Debug.Trace.traceShow,
Debug.Trace.traceShowId,
Debug.Trace.traceM,
Debug.Trace.traceShowM,
traceIO,
traceShowIO,
traceShowIdIO,
......@@ -86,7 +83,7 @@ import Control.Exception qualified
import Control.Monad ((>=>), (<=<))
import Control.Monad qualified
import Control.Monad.Fix qualified
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.IO.Class qualified
import Data.Foldable qualified
import Data.Functor.Identity qualified
import Data.Hashable qualified
......@@ -96,25 +93,13 @@ import Data.Maybe qualified
import Data.Unique qualified
import Data.Void qualified
import Data.Word qualified
import Debug.Trace qualified as Trace
import Debug.Trace qualified
import GHC.Generics qualified
import GHC.Stack.Types qualified
import GHC.Types qualified
import Quasar.PreludeExtras
import Quasar.PreludeSTM
{-# WARNING head "Partial Function." #-}
head :: [a] -> a
head = P.head
{-# WARNING last "Partial Function." #-}
last :: [a] -> a
last = P.last
{-# WARNING read "Partial Function." #-}
read :: Read a => String -> a
read = P.read
{-# WARNING error "Undefined." #-}
error :: forall (r :: GHC.Types.RuntimeRep). forall (a :: GHC.Types.TYPE r). GHC.Stack.Types.HasCallStack => String -> a
error = P.error
......@@ -127,41 +112,14 @@ errorWithoutStackTrace = P.errorWithoutStackTrace
undefined :: forall (r :: GHC.Types.RuntimeRep). forall (a :: GHC.Types.TYPE r). GHC.Stack.Types.HasCallStack => a
undefined = P.undefined
{-# WARNING trace "Trace." #-}
trace :: String -> a -> a
trace = Trace.trace
{-# WARNING traceId "Trace." #-}
traceId :: String -> String
traceId = Trace.traceId
{-# WARNING traceShow "Trace." #-}
traceShow :: Show a => a -> b -> b
traceShow = Trace.traceShow
{-# WARNING traceShowId "Trace." #-}
traceShowId :: Show a => a -> a
traceShowId = Trace.traceShowId
{-# WARNING traceM "Trace." #-}
traceM :: Applicative m => String -> m ()
traceM = Trace.traceM
{-# WARNING traceShowM "Trace." #-}
traceShowM :: (Show a, Applicative m) => a -> m ()
traceShowM = Trace.traceShowM
{-# WARNING traceIO "Trace." #-}
traceIO :: Control.Monad.IO.Class.MonadIO m => String -> m ()
traceIO = Control.Monad.IO.Class.liftIO . Trace.traceIO
traceIO = Control.Monad.IO.Class.liftIO . Debug.Trace.traceIO
{-# WARNING traceShowIO "Trace." #-}
traceShowIO :: (Control.Monad.IO.Class.MonadIO m, Show a) => a -> m ()
traceShowIO = traceIO . show
{-# WARNING traceShowIdIO "Trace." #-}
traceShowIdIO :: (Control.Monad.IO.Class.MonadIO m, Show a) => a -> m a
traceShowIdIO a = traceShowIO a >> pure a
newUnique :: MonadIO m => m Data.Unique.Unique
newUnique = liftIO Data.Unique.newUnique
newUnique :: Control.Monad.IO.Class.MonadIO m => m Data.Unique.Unique
newUnique = Control.Monad.IO.Class.liftIO Data.Unique.newUnique
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment