Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

auth.php

Blame
  • LintWriter.hs 5.60 KiB
    {-# LANGUAGE DeriveAnyClass    #-}
    {-# LANGUAGE DeriveGeneric     #-}
    {-# LANGUAGE FlexibleContexts  #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE LambdaCase        #-}
    {-# LANGUAGE NamedFieldPuns    #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RankNTypes        #-}
    {-# LANGUAGE TupleSections     #-}
    {-# OPTIONS_GHC -Wno-missing-signatures #-}
    
    -- | a monad that collects warnings, outputs, etc,
    module LintWriter
      ( runLintWriter
      , LintWriter
      , LintWriter'
      , LintResult
      , invertLintResult
      -- * working with lint results
      , resultToDeps
      , resultToOffers
      , resultToBadges
      , resultToLints
      , resultToAdjusted
      -- * Add lints to a linter
      , info
      , suggest
      , warn
      , forbid
      , complain
      -- * add other information to the linter
      , offersEntrypoint
      , offersBadge
      , dependsOn
      -- * get information about the linter's context
      , askContext
      , askFileDepth
      , lintConfig
      -- * adjust the linter's context
      , adjust
      ) where
    
    import           Data.Text                  (Text)
    
    import           Badges                     (Badge)
    import           Control.Monad.State        (StateT, modify)
    import           Control.Monad.Trans.Reader (Reader, asks, runReader)
    import           Control.Monad.Trans.State  (runStateT)
    import           Control.Monad.Writer.Lazy  (lift)
    import           Data.Bifunctor             (Bifunctor (second))
    import           Data.Map                   (Map, fromListWith)
    import           Data.Maybe                 (mapMaybe)
    import           LintConfig                 (LintConfig')
    import           TiledAbstract              (HasName)
    import           Types                      (Dep, Hint, Level (..), Lint (..),
                                                 hint, lintsToHints)
    
    
    -- | A monad modelling the main linter features
    type LintWriter ctxt = LintWriter' ctxt ()
    -- | A linter that can use pure / return things monadically
    type LintWriter' ctxt res =
      StateT (LinterState ctxt) (Reader (Context, ctxt, LintConfig')) res
    
    -- | A Linter's state: some context (which it may adjust), and a list of lints
    -- | it already collected.
    newtype LinterState ctxt = LinterState
      { fromLinterState :: ([Lint], ctxt)}
    
    -- | The result of running a linter: an adjusted context, and a list of lints.