{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module ShellCheck.Interface
(
SystemInterface(..)
, CheckSpec(csFilename, csScript, csCheckSourced, csIncludedWarnings, csExcludedWarnings, csShellTypeOverride, csMinSeverity, csIgnoreRC, csExtendedAnalysis, csOptionalChecks)
, CheckResult(crFilename, crComments)
, ParseSpec(psFilename, psScript, psCheckSourced, psIgnoreRC, psShellTypeOverride)
, ParseResult(prComments, prTokenPositions, prRoot)
, AnalysisSpec(asScript, asShellType, asFallbackShell, asExecutionMode, asCheckSourced, asTokenPositions, asExtendedAnalysis, asOptionalChecks)
, AnalysisResult(arComments)
, FormatterOptions(foColorOption, foWikiLinkCount)
, Shell(Ksh, Sh, Bash, Dash, BusyboxSh)
, ExecutionMode(Executed, Sourced)
, ErrorMessage
, Code
, Severity(ErrorC, WarningC, InfoC, StyleC)
, Position(posFile, posLine, posColumn)
, Comment(cSeverity, cCode, cMessage)
, PositionedComment(pcStartPos , pcEndPos , pcComment, pcFix)
, ColorOption(ColorAuto, ColorAlways, ColorNever)
, TokenComment(tcId, tcComment, tcFix)
, emptyCheckResult
, newAnalysisResult
, newAnalysisSpec
, newFormatterOptions
, newParseResult
, newPosition
, newSystemInterface
, newTokenComment
, mockedSystemInterface
, mockRcFile
, newParseSpec
, emptyCheckSpec
, newPositionedComment
, newComment
, Fix(fixReplacements)
, newFix
, InsertionPoint(InsertBefore, InsertAfter)
, Replacement(repStartPos, repEndPos, repString, repPrecedence, repInsertionPoint)
, newReplacement
, CheckDescription(cdName, cdDescription, cdPositive, cdNegative)
, newCheckDescription
) where
import ShellCheck.AST
import Control.DeepSeq
import Control.Monad.Identity
import Data.List
import Data.Monoid
import Data.Ord
import Data.Semigroup
import GHC.Generics (Generic)
import qualified Data.Map as Map
data SystemInterface m = SystemInterface {
forall (m :: * -> *).
SystemInterface m
-> Maybe Bool -> String -> m (Either String String)
siReadFile :: Maybe Bool -> String -> m (Either ErrorMessage String),
forall (m :: * -> *).
SystemInterface m
-> String -> Maybe Bool -> [String] -> String -> m String
siFindSource :: String -> Maybe Bool -> [String] -> String -> m FilePath,
forall (m :: * -> *).
SystemInterface m -> String -> m (Maybe (String, String))
siGetConfig :: String -> m (Maybe (FilePath, String))
}
data CheckSpec = CheckSpec {
CheckSpec -> String
csFilename :: String,
CheckSpec -> String
csScript :: String,
CheckSpec -> Bool
csCheckSourced :: Bool,
CheckSpec -> Bool
csIgnoreRC :: Bool,
CheckSpec -> [Integer]
csExcludedWarnings :: [Integer],
CheckSpec -> Maybe [Integer]
csIncludedWarnings :: Maybe [Integer],
CheckSpec -> Maybe Shell
csShellTypeOverride :: Maybe Shell,
CheckSpec -> Severity
csMinSeverity :: Severity,
CheckSpec -> Maybe Bool
csExtendedAnalysis :: Maybe Bool,
CheckSpec -> [String]
csOptionalChecks :: [String]
} deriving (Int -> CheckSpec -> ShowS
[CheckSpec] -> ShowS
CheckSpec -> String
(Int -> CheckSpec -> ShowS)
-> (CheckSpec -> String)
-> ([CheckSpec] -> ShowS)
-> Show CheckSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckSpec -> ShowS
showsPrec :: Int -> CheckSpec -> ShowS
$cshow :: CheckSpec -> String
show :: CheckSpec -> String
$cshowList :: [CheckSpec] -> ShowS
showList :: [CheckSpec] -> ShowS
Show, CheckSpec -> CheckSpec -> Bool
(CheckSpec -> CheckSpec -> Bool)
-> (CheckSpec -> CheckSpec -> Bool) -> Eq CheckSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckSpec -> CheckSpec -> Bool
== :: CheckSpec -> CheckSpec -> Bool
$c/= :: CheckSpec -> CheckSpec -> Bool
/= :: CheckSpec -> CheckSpec -> Bool
Eq)
data CheckResult = CheckResult {
CheckResult -> String
crFilename :: String,
:: [PositionedComment]
} deriving (Int -> CheckResult -> ShowS
[CheckResult] -> ShowS
CheckResult -> String
(Int -> CheckResult -> ShowS)
-> (CheckResult -> String)
-> ([CheckResult] -> ShowS)
-> Show CheckResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckResult -> ShowS
showsPrec :: Int -> CheckResult -> ShowS
$cshow :: CheckResult -> String
show :: CheckResult -> String
$cshowList :: [CheckResult] -> ShowS
showList :: [CheckResult] -> ShowS
Show, CheckResult -> CheckResult -> Bool
(CheckResult -> CheckResult -> Bool)
-> (CheckResult -> CheckResult -> Bool) -> Eq CheckResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckResult -> CheckResult -> Bool
== :: CheckResult -> CheckResult -> Bool
$c/= :: CheckResult -> CheckResult -> Bool
/= :: CheckResult -> CheckResult -> Bool
Eq)
emptyCheckResult :: CheckResult
emptyCheckResult :: CheckResult
emptyCheckResult = CheckResult {
crFilename :: String
crFilename = String
"",
crComments :: [PositionedComment]
crComments = []
}
emptyCheckSpec :: CheckSpec
emptyCheckSpec :: CheckSpec
emptyCheckSpec = CheckSpec {
csFilename :: String
csFilename = String
"",
csScript :: String
csScript = String
"",
csCheckSourced :: Bool
csCheckSourced = Bool
False,
csIgnoreRC :: Bool
csIgnoreRC = Bool
False,
csExcludedWarnings :: [Integer]
csExcludedWarnings = [],
csIncludedWarnings :: Maybe [Integer]
csIncludedWarnings = Maybe [Integer]
forall a. Maybe a
Nothing,
csShellTypeOverride :: Maybe Shell
csShellTypeOverride = Maybe Shell
forall a. Maybe a
Nothing,
csMinSeverity :: Severity
csMinSeverity = Severity
StyleC,
csExtendedAnalysis :: Maybe Bool
csExtendedAnalysis = Maybe Bool
forall a. Maybe a
Nothing,
csOptionalChecks :: [String]
csOptionalChecks = []
}
newParseSpec :: ParseSpec
newParseSpec :: ParseSpec
newParseSpec = ParseSpec {
psFilename :: String
psFilename = String
"",
psScript :: String
psScript = String
"",
psCheckSourced :: Bool
psCheckSourced = Bool
False,
psIgnoreRC :: Bool
psIgnoreRC = Bool
False,
psShellTypeOverride :: Maybe Shell
psShellTypeOverride = Maybe Shell
forall a. Maybe a
Nothing
}
newSystemInterface :: Monad m => SystemInterface m
newSystemInterface :: forall (m :: * -> *). Monad m => SystemInterface m
newSystemInterface =
SystemInterface {
siReadFile :: Maybe Bool -> String -> m (Either String String)
siReadFile = \Maybe Bool
_ String
_ -> Either String String -> m (Either String String)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String String -> m (Either String String))
-> Either String String -> m (Either String String)
forall a b. (a -> b) -> a -> b
$ String -> Either String String
forall a b. a -> Either a b
Left String
"Not implemented",
siFindSource :: String -> Maybe Bool -> [String] -> String -> m String
siFindSource = \String
_ Maybe Bool
_ [String]
_ String
name -> String -> m String
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return String
name,
siGetConfig :: String -> m (Maybe (String, String))
siGetConfig = \String
_ -> Maybe (String, String) -> m (Maybe (String, String))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (String, String)
forall a. Maybe a
Nothing
}
data ParseSpec = ParseSpec {
ParseSpec -> String
psFilename :: String,
ParseSpec -> String
psScript :: String,
ParseSpec -> Bool
psCheckSourced :: Bool,
ParseSpec -> Bool
psIgnoreRC :: Bool,
ParseSpec -> Maybe Shell
psShellTypeOverride :: Maybe Shell
} deriving (Int -> ParseSpec -> ShowS
[ParseSpec] -> ShowS
ParseSpec -> String
(Int -> ParseSpec -> ShowS)
-> (ParseSpec -> String)
-> ([ParseSpec] -> ShowS)
-> Show ParseSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseSpec -> ShowS
showsPrec :: Int -> ParseSpec -> ShowS
$cshow :: ParseSpec -> String
show :: ParseSpec -> String
$cshowList :: [ParseSpec] -> ShowS
showList :: [ParseSpec] -> ShowS
Show, ParseSpec -> ParseSpec -> Bool
(ParseSpec -> ParseSpec -> Bool)
-> (ParseSpec -> ParseSpec -> Bool) -> Eq ParseSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParseSpec -> ParseSpec -> Bool
== :: ParseSpec -> ParseSpec -> Bool
$c/= :: ParseSpec -> ParseSpec -> Bool
/= :: ParseSpec -> ParseSpec -> Bool
Eq)
data ParseResult = ParseResult {
:: [PositionedComment],
ParseResult -> Map Id (Position, Position)
prTokenPositions :: Map.Map Id (Position, Position),
ParseResult -> Maybe Token
prRoot :: Maybe Token
} deriving (Int -> ParseResult -> ShowS
[ParseResult] -> ShowS
ParseResult -> String
(Int -> ParseResult -> ShowS)
-> (ParseResult -> String)
-> ([ParseResult] -> ShowS)
-> Show ParseResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseResult -> ShowS
showsPrec :: Int -> ParseResult -> ShowS
$cshow :: ParseResult -> String
show :: ParseResult -> String
$cshowList :: [ParseResult] -> ShowS
showList :: [ParseResult] -> ShowS
Show, ParseResult -> ParseResult -> Bool
(ParseResult -> ParseResult -> Bool)
-> (ParseResult -> ParseResult -> Bool) -> Eq ParseResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParseResult -> ParseResult -> Bool
== :: ParseResult -> ParseResult -> Bool
$c/= :: ParseResult -> ParseResult -> Bool
/= :: ParseResult -> ParseResult -> Bool
Eq)
newParseResult :: ParseResult
newParseResult :: ParseResult
newParseResult = ParseResult {
prComments :: [PositionedComment]
prComments = [],
prTokenPositions :: Map Id (Position, Position)
prTokenPositions = Map Id (Position, Position)
forall k a. Map k a
Map.empty,
prRoot :: Maybe Token
prRoot = Maybe Token
forall a. Maybe a
Nothing
}
data AnalysisSpec = AnalysisSpec {
AnalysisSpec -> Token
asScript :: Token,
AnalysisSpec -> Maybe Shell
asShellType :: Maybe Shell,
AnalysisSpec -> Maybe Shell
asFallbackShell :: Maybe Shell,
AnalysisSpec -> ExecutionMode
asExecutionMode :: ExecutionMode,
AnalysisSpec -> Bool
asCheckSourced :: Bool,
AnalysisSpec -> [String]
asOptionalChecks :: [String],
AnalysisSpec -> Maybe Bool
asExtendedAnalysis :: Maybe Bool,
AnalysisSpec -> Map Id (Position, Position)
asTokenPositions :: Map.Map Id (Position, Position)
}
newAnalysisSpec :: Token -> AnalysisSpec
newAnalysisSpec Token
token = AnalysisSpec {
asScript :: Token
asScript = Token
token,
asShellType :: Maybe Shell
asShellType = Maybe Shell
forall a. Maybe a
Nothing,
asFallbackShell :: Maybe Shell
asFallbackShell = Maybe Shell
forall a. Maybe a
Nothing,
asExecutionMode :: ExecutionMode
asExecutionMode = ExecutionMode
Executed,
asCheckSourced :: Bool
asCheckSourced = Bool
False,
asOptionalChecks :: [String]
asOptionalChecks = [],
asExtendedAnalysis :: Maybe Bool
asExtendedAnalysis = Maybe Bool
forall a. Maybe a
Nothing,
asTokenPositions :: Map Id (Position, Position)
asTokenPositions = Map Id (Position, Position)
forall k a. Map k a
Map.empty
}
newtype AnalysisResult = AnalysisResult {
:: [TokenComment]
}
newAnalysisResult :: AnalysisResult
newAnalysisResult = AnalysisResult {
arComments :: [TokenComment]
arComments = []
}
data FormatterOptions = FormatterOptions {
FormatterOptions -> ColorOption
foColorOption :: ColorOption,
FormatterOptions -> Integer
foWikiLinkCount :: Integer
}
newFormatterOptions :: FormatterOptions
newFormatterOptions = FormatterOptions {
foColorOption :: ColorOption
foColorOption = ColorOption
ColorAuto,
foWikiLinkCount :: Integer
foWikiLinkCount = Integer
3
}
data CheckDescription = CheckDescription {
CheckDescription -> String
cdName :: String,
CheckDescription -> String
cdDescription :: String,
CheckDescription -> String
cdPositive :: String,
CheckDescription -> String
cdNegative :: String
}
newCheckDescription :: CheckDescription
newCheckDescription = CheckDescription {
cdName :: String
cdName = String
"",
cdDescription :: String
cdDescription = String
"",
cdPositive :: String
cdPositive = String
"",
cdNegative :: String
cdNegative = String
""
}
data Shell = Ksh | Sh | Bash | Dash | BusyboxSh deriving (Int -> Shell -> ShowS
[Shell] -> ShowS
Shell -> String
(Int -> Shell -> ShowS)
-> (Shell -> String) -> ([Shell] -> ShowS) -> Show Shell
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Shell -> ShowS
showsPrec :: Int -> Shell -> ShowS
$cshow :: Shell -> String
show :: Shell -> String
$cshowList :: [Shell] -> ShowS
showList :: [Shell] -> ShowS
Show, Shell -> Shell -> Bool
(Shell -> Shell -> Bool) -> (Shell -> Shell -> Bool) -> Eq Shell
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Shell -> Shell -> Bool
== :: Shell -> Shell -> Bool
$c/= :: Shell -> Shell -> Bool
/= :: Shell -> Shell -> Bool
Eq)
data ExecutionMode = Executed | Sourced deriving (Int -> ExecutionMode -> ShowS
[ExecutionMode] -> ShowS
ExecutionMode -> String
(Int -> ExecutionMode -> ShowS)
-> (ExecutionMode -> String)
-> ([ExecutionMode] -> ShowS)
-> Show ExecutionMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExecutionMode -> ShowS
showsPrec :: Int -> ExecutionMode -> ShowS
$cshow :: ExecutionMode -> String
show :: ExecutionMode -> String
$cshowList :: [ExecutionMode] -> ShowS
showList :: [ExecutionMode] -> ShowS
Show, ExecutionMode -> ExecutionMode -> Bool
(ExecutionMode -> ExecutionMode -> Bool)
-> (ExecutionMode -> ExecutionMode -> Bool) -> Eq ExecutionMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExecutionMode -> ExecutionMode -> Bool
== :: ExecutionMode -> ExecutionMode -> Bool
$c/= :: ExecutionMode -> ExecutionMode -> Bool
/= :: ExecutionMode -> ExecutionMode -> Bool
Eq)
type ErrorMessage = String
type Code = Integer
data Severity = ErrorC | WarningC | InfoC | StyleC
deriving (Int -> Severity -> ShowS
[Severity] -> ShowS
Severity -> String
(Int -> Severity -> ShowS)
-> (Severity -> String) -> ([Severity] -> ShowS) -> Show Severity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Severity -> ShowS
showsPrec :: Int -> Severity -> ShowS
$cshow :: Severity -> String
show :: Severity -> String
$cshowList :: [Severity] -> ShowS
showList :: [Severity] -> ShowS
Show, Severity -> Severity -> Bool
(Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool) -> Eq Severity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Severity -> Severity -> Bool
== :: Severity -> Severity -> Bool
$c/= :: Severity -> Severity -> Bool
/= :: Severity -> Severity -> Bool
Eq, Eq Severity
Eq Severity =>
(Severity -> Severity -> Ordering)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Severity)
-> (Severity -> Severity -> Severity)
-> Ord Severity
Severity -> Severity -> Bool
Severity -> Severity -> Ordering
Severity -> Severity -> Severity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Severity -> Severity -> Ordering
compare :: Severity -> Severity -> Ordering
$c< :: Severity -> Severity -> Bool
< :: Severity -> Severity -> Bool
$c<= :: Severity -> Severity -> Bool
<= :: Severity -> Severity -> Bool
$c> :: Severity -> Severity -> Bool
> :: Severity -> Severity -> Bool
$c>= :: Severity -> Severity -> Bool
>= :: Severity -> Severity -> Bool
$cmax :: Severity -> Severity -> Severity
max :: Severity -> Severity -> Severity
$cmin :: Severity -> Severity -> Severity
min :: Severity -> Severity -> Severity
Ord, (forall x. Severity -> Rep Severity x)
-> (forall x. Rep Severity x -> Severity) -> Generic Severity
forall x. Rep Severity x -> Severity
forall x. Severity -> Rep Severity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Severity -> Rep Severity x
from :: forall x. Severity -> Rep Severity x
$cto :: forall x. Rep Severity x -> Severity
to :: forall x. Rep Severity x -> Severity
Generic, Severity -> ()
(Severity -> ()) -> NFData Severity
forall a. (a -> ()) -> NFData a
$crnf :: Severity -> ()
rnf :: Severity -> ()
NFData)
data Position = Position {
Position -> String
posFile :: String,
Position -> Integer
posLine :: Integer,
Position -> Integer
posColumn :: Integer
} deriving (Int -> Position -> ShowS
[Position] -> ShowS
Position -> String
(Int -> Position -> ShowS)
-> (Position -> String) -> ([Position] -> ShowS) -> Show Position
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Position -> ShowS
showsPrec :: Int -> Position -> ShowS
$cshow :: Position -> String
show :: Position -> String
$cshowList :: [Position] -> ShowS
showList :: [Position] -> ShowS
Show, Position -> Position -> Bool
(Position -> Position -> Bool)
-> (Position -> Position -> Bool) -> Eq Position
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Position -> Position -> Bool
== :: Position -> Position -> Bool
$c/= :: Position -> Position -> Bool
/= :: Position -> Position -> Bool
Eq, (forall x. Position -> Rep Position x)
-> (forall x. Rep Position x -> Position) -> Generic Position
forall x. Rep Position x -> Position
forall x. Position -> Rep Position x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Position -> Rep Position x
from :: forall x. Position -> Rep Position x
$cto :: forall x. Rep Position x -> Position
to :: forall x. Rep Position x -> Position
Generic, Position -> ()
(Position -> ()) -> NFData Position
forall a. (a -> ()) -> NFData a
$crnf :: Position -> ()
rnf :: Position -> ()
NFData, Eq Position
Eq Position =>
(Position -> Position -> Ordering)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Position)
-> (Position -> Position -> Position)
-> Ord Position
Position -> Position -> Bool
Position -> Position -> Ordering
Position -> Position -> Position
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Position -> Position -> Ordering
compare :: Position -> Position -> Ordering
$c< :: Position -> Position -> Bool
< :: Position -> Position -> Bool
$c<= :: Position -> Position -> Bool
<= :: Position -> Position -> Bool
$c> :: Position -> Position -> Bool
> :: Position -> Position -> Bool
$c>= :: Position -> Position -> Bool
>= :: Position -> Position -> Bool
$cmax :: Position -> Position -> Position
max :: Position -> Position -> Position
$cmin :: Position -> Position -> Position
min :: Position -> Position -> Position
Ord)
newPosition :: Position
newPosition :: Position
newPosition = Position {
posFile :: String
posFile = String
"",
posLine :: Integer
posLine = Integer
1,
posColumn :: Integer
posColumn = Integer
1
}
data = {
Comment -> Severity
cSeverity :: Severity,
Comment -> Integer
cCode :: Code,
Comment -> String
cMessage :: String
} deriving (Int -> Comment -> ShowS
[Comment] -> ShowS
Comment -> String
(Int -> Comment -> ShowS)
-> (Comment -> String) -> ([Comment] -> ShowS) -> Show Comment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Comment -> ShowS
showsPrec :: Int -> Comment -> ShowS
$cshow :: Comment -> String
show :: Comment -> String
$cshowList :: [Comment] -> ShowS
showList :: [Comment] -> ShowS
Show, Comment -> Comment -> Bool
(Comment -> Comment -> Bool)
-> (Comment -> Comment -> Bool) -> Eq Comment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Comment -> Comment -> Bool
== :: Comment -> Comment -> Bool
$c/= :: Comment -> Comment -> Bool
/= :: Comment -> Comment -> Bool
Eq, (forall x. Comment -> Rep Comment x)
-> (forall x. Rep Comment x -> Comment) -> Generic Comment
forall x. Rep Comment x -> Comment
forall x. Comment -> Rep Comment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Comment -> Rep Comment x
from :: forall x. Comment -> Rep Comment x
$cto :: forall x. Rep Comment x -> Comment
to :: forall x. Rep Comment x -> Comment
Generic, Comment -> ()
(Comment -> ()) -> NFData Comment
forall a. (a -> ()) -> NFData a
$crnf :: Comment -> ()
rnf :: Comment -> ()
NFData)
newComment :: Comment
= Comment {
cSeverity :: Severity
cSeverity = Severity
StyleC,
cCode :: Integer
cCode = Integer
0,
cMessage :: String
cMessage = String
""
}
data Replacement = Replacement {
Replacement -> Position
repStartPos :: Position,
Replacement -> Position
repEndPos :: Position,
Replacement -> String
repString :: String,
Replacement -> Int
repPrecedence :: Int,
Replacement -> InsertionPoint
repInsertionPoint :: InsertionPoint
} deriving (Int -> Replacement -> ShowS
[Replacement] -> ShowS
Replacement -> String
(Int -> Replacement -> ShowS)
-> (Replacement -> String)
-> ([Replacement] -> ShowS)
-> Show Replacement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Replacement -> ShowS
showsPrec :: Int -> Replacement -> ShowS
$cshow :: Replacement -> String
show :: Replacement -> String
$cshowList :: [Replacement] -> ShowS
showList :: [Replacement] -> ShowS
Show, Replacement -> Replacement -> Bool
(Replacement -> Replacement -> Bool)
-> (Replacement -> Replacement -> Bool) -> Eq Replacement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Replacement -> Replacement -> Bool
== :: Replacement -> Replacement -> Bool
$c/= :: Replacement -> Replacement -> Bool
/= :: Replacement -> Replacement -> Bool
Eq, (forall x. Replacement -> Rep Replacement x)
-> (forall x. Rep Replacement x -> Replacement)
-> Generic Replacement
forall x. Rep Replacement x -> Replacement
forall x. Replacement -> Rep Replacement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Replacement -> Rep Replacement x
from :: forall x. Replacement -> Rep Replacement x
$cto :: forall x. Rep Replacement x -> Replacement
to :: forall x. Rep Replacement x -> Replacement
Generic, Replacement -> ()
(Replacement -> ()) -> NFData Replacement
forall a. (a -> ()) -> NFData a
$crnf :: Replacement -> ()
rnf :: Replacement -> ()
NFData)
data InsertionPoint = InsertBefore | InsertAfter
deriving (Int -> InsertionPoint -> ShowS
[InsertionPoint] -> ShowS
InsertionPoint -> String
(Int -> InsertionPoint -> ShowS)
-> (InsertionPoint -> String)
-> ([InsertionPoint] -> ShowS)
-> Show InsertionPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InsertionPoint -> ShowS
showsPrec :: Int -> InsertionPoint -> ShowS
$cshow :: InsertionPoint -> String
show :: InsertionPoint -> String
$cshowList :: [InsertionPoint] -> ShowS
showList :: [InsertionPoint] -> ShowS
Show, InsertionPoint -> InsertionPoint -> Bool
(InsertionPoint -> InsertionPoint -> Bool)
-> (InsertionPoint -> InsertionPoint -> Bool) -> Eq InsertionPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InsertionPoint -> InsertionPoint -> Bool
== :: InsertionPoint -> InsertionPoint -> Bool
$c/= :: InsertionPoint -> InsertionPoint -> Bool
/= :: InsertionPoint -> InsertionPoint -> Bool
Eq, (forall x. InsertionPoint -> Rep InsertionPoint x)
-> (forall x. Rep InsertionPoint x -> InsertionPoint)
-> Generic InsertionPoint
forall x. Rep InsertionPoint x -> InsertionPoint
forall x. InsertionPoint -> Rep InsertionPoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InsertionPoint -> Rep InsertionPoint x
from :: forall x. InsertionPoint -> Rep InsertionPoint x
$cto :: forall x. Rep InsertionPoint x -> InsertionPoint
to :: forall x. Rep InsertionPoint x -> InsertionPoint
Generic, InsertionPoint -> ()
(InsertionPoint -> ()) -> NFData InsertionPoint
forall a. (a -> ()) -> NFData a
$crnf :: InsertionPoint -> ()
rnf :: InsertionPoint -> ()
NFData)
newReplacement :: Replacement
newReplacement = Replacement {
repStartPos :: Position
repStartPos = Position
newPosition,
repEndPos :: Position
repEndPos = Position
newPosition,
repString :: String
repString = String
"",
repPrecedence :: Int
repPrecedence = Int
1,
repInsertionPoint :: InsertionPoint
repInsertionPoint = InsertionPoint
InsertAfter
}
data Fix = Fix {
Fix -> [Replacement]
fixReplacements :: [Replacement]
} deriving (Int -> Fix -> ShowS
[Fix] -> ShowS
Fix -> String
(Int -> Fix -> ShowS)
-> (Fix -> String) -> ([Fix] -> ShowS) -> Show Fix
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fix -> ShowS
showsPrec :: Int -> Fix -> ShowS
$cshow :: Fix -> String
show :: Fix -> String
$cshowList :: [Fix] -> ShowS
showList :: [Fix] -> ShowS
Show, Fix -> Fix -> Bool
(Fix -> Fix -> Bool) -> (Fix -> Fix -> Bool) -> Eq Fix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Fix -> Fix -> Bool
== :: Fix -> Fix -> Bool
$c/= :: Fix -> Fix -> Bool
/= :: Fix -> Fix -> Bool
Eq, (forall x. Fix -> Rep Fix x)
-> (forall x. Rep Fix x -> Fix) -> Generic Fix
forall x. Rep Fix x -> Fix
forall x. Fix -> Rep Fix x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Fix -> Rep Fix x
from :: forall x. Fix -> Rep Fix x
$cto :: forall x. Rep Fix x -> Fix
to :: forall x. Rep Fix x -> Fix
Generic, Fix -> ()
(Fix -> ()) -> NFData Fix
forall a. (a -> ()) -> NFData a
$crnf :: Fix -> ()
rnf :: Fix -> ()
NFData)
newFix :: Fix
newFix = Fix {
fixReplacements :: [Replacement]
fixReplacements = []
}
data = {
PositionedComment -> Position
pcStartPos :: Position,
PositionedComment -> Position
pcEndPos :: Position,
:: Comment,
PositionedComment -> Maybe Fix
pcFix :: Maybe Fix
} deriving (Int -> PositionedComment -> ShowS
[PositionedComment] -> ShowS
PositionedComment -> String
(Int -> PositionedComment -> ShowS)
-> (PositionedComment -> String)
-> ([PositionedComment] -> ShowS)
-> Show PositionedComment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PositionedComment -> ShowS
showsPrec :: Int -> PositionedComment -> ShowS
$cshow :: PositionedComment -> String
show :: PositionedComment -> String
$cshowList :: [PositionedComment] -> ShowS
showList :: [PositionedComment] -> ShowS
Show, PositionedComment -> PositionedComment -> Bool
(PositionedComment -> PositionedComment -> Bool)
-> (PositionedComment -> PositionedComment -> Bool)
-> Eq PositionedComment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PositionedComment -> PositionedComment -> Bool
== :: PositionedComment -> PositionedComment -> Bool
$c/= :: PositionedComment -> PositionedComment -> Bool
/= :: PositionedComment -> PositionedComment -> Bool
Eq, (forall x. PositionedComment -> Rep PositionedComment x)
-> (forall x. Rep PositionedComment x -> PositionedComment)
-> Generic PositionedComment
forall x. Rep PositionedComment x -> PositionedComment
forall x. PositionedComment -> Rep PositionedComment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PositionedComment -> Rep PositionedComment x
from :: forall x. PositionedComment -> Rep PositionedComment x
$cto :: forall x. Rep PositionedComment x -> PositionedComment
to :: forall x. Rep PositionedComment x -> PositionedComment
Generic, PositionedComment -> ()
(PositionedComment -> ()) -> NFData PositionedComment
forall a. (a -> ()) -> NFData a
$crnf :: PositionedComment -> ()
rnf :: PositionedComment -> ()
NFData)
newPositionedComment :: PositionedComment
= PositionedComment {
pcStartPos :: Position
pcStartPos = Position
newPosition,
pcEndPos :: Position
pcEndPos = Position
newPosition,
pcComment :: Comment
pcComment = Comment
newComment,
pcFix :: Maybe Fix
pcFix = Maybe Fix
forall a. Maybe a
Nothing
}
data = {
TokenComment -> Id
tcId :: Id,
:: Comment,
TokenComment -> Maybe Fix
tcFix :: Maybe Fix
} deriving (Int -> TokenComment -> ShowS
[TokenComment] -> ShowS
TokenComment -> String
(Int -> TokenComment -> ShowS)
-> (TokenComment -> String)
-> ([TokenComment] -> ShowS)
-> Show TokenComment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TokenComment -> ShowS
showsPrec :: Int -> TokenComment -> ShowS
$cshow :: TokenComment -> String
show :: TokenComment -> String
$cshowList :: [TokenComment] -> ShowS
showList :: [TokenComment] -> ShowS
Show, TokenComment -> TokenComment -> Bool
(TokenComment -> TokenComment -> Bool)
-> (TokenComment -> TokenComment -> Bool) -> Eq TokenComment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TokenComment -> TokenComment -> Bool
== :: TokenComment -> TokenComment -> Bool
$c/= :: TokenComment -> TokenComment -> Bool
/= :: TokenComment -> TokenComment -> Bool
Eq, (forall x. TokenComment -> Rep TokenComment x)
-> (forall x. Rep TokenComment x -> TokenComment)
-> Generic TokenComment
forall x. Rep TokenComment x -> TokenComment
forall x. TokenComment -> Rep TokenComment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TokenComment -> Rep TokenComment x
from :: forall x. TokenComment -> Rep TokenComment x
$cto :: forall x. Rep TokenComment x -> TokenComment
to :: forall x. Rep TokenComment x -> TokenComment
Generic, TokenComment -> ()
(TokenComment -> ()) -> NFData TokenComment
forall a. (a -> ()) -> NFData a
$crnf :: TokenComment -> ()
rnf :: TokenComment -> ()
NFData)
= TokenComment {
tcId :: Id
tcId = Int -> Id
Id Int
0,
tcComment :: Comment
tcComment = Comment
newComment,
tcFix :: Maybe Fix
tcFix = Maybe Fix
forall a. Maybe a
Nothing
}
data ColorOption =
ColorAuto
| ColorAlways
| ColorNever
deriving (Eq ColorOption
Eq ColorOption =>
(ColorOption -> ColorOption -> Ordering)
-> (ColorOption -> ColorOption -> Bool)
-> (ColorOption -> ColorOption -> Bool)
-> (ColorOption -> ColorOption -> Bool)
-> (ColorOption -> ColorOption -> Bool)
-> (ColorOption -> ColorOption -> ColorOption)
-> (ColorOption -> ColorOption -> ColorOption)
-> Ord ColorOption
ColorOption -> ColorOption -> Bool
ColorOption -> ColorOption -> Ordering
ColorOption -> ColorOption -> ColorOption
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ColorOption -> ColorOption -> Ordering
compare :: ColorOption -> ColorOption -> Ordering
$c< :: ColorOption -> ColorOption -> Bool
< :: ColorOption -> ColorOption -> Bool
$c<= :: ColorOption -> ColorOption -> Bool
<= :: ColorOption -> ColorOption -> Bool
$c> :: ColorOption -> ColorOption -> Bool
> :: ColorOption -> ColorOption -> Bool
$c>= :: ColorOption -> ColorOption -> Bool
>= :: ColorOption -> ColorOption -> Bool
$cmax :: ColorOption -> ColorOption -> ColorOption
max :: ColorOption -> ColorOption -> ColorOption
$cmin :: ColorOption -> ColorOption -> ColorOption
min :: ColorOption -> ColorOption -> ColorOption
Ord, ColorOption -> ColorOption -> Bool
(ColorOption -> ColorOption -> Bool)
-> (ColorOption -> ColorOption -> Bool) -> Eq ColorOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColorOption -> ColorOption -> Bool
== :: ColorOption -> ColorOption -> Bool
$c/= :: ColorOption -> ColorOption -> Bool
/= :: ColorOption -> ColorOption -> Bool
Eq, Int -> ColorOption -> ShowS
[ColorOption] -> ShowS
ColorOption -> String
(Int -> ColorOption -> ShowS)
-> (ColorOption -> String)
-> ([ColorOption] -> ShowS)
-> Show ColorOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColorOption -> ShowS
showsPrec :: Int -> ColorOption -> ShowS
$cshow :: ColorOption -> String
show :: ColorOption -> String
$cshowList :: [ColorOption] -> ShowS
showList :: [ColorOption] -> ShowS
Show)
mockedSystemInterface :: [(String, String)] -> SystemInterface Identity
mockedSystemInterface :: [(String, String)] -> SystemInterface Identity
mockedSystemInterface [(String, String)]
files = (SystemInterface Identity
forall (m :: * -> *). Monad m => SystemInterface m
newSystemInterface :: SystemInterface Identity) {
siReadFile = rf,
siFindSource = fs,
siGetConfig = const $ return Nothing
}
where
rf :: p -> String -> m (Either String String)
rf p
_ String
file = Either String String -> m (Either String String)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String String -> m (Either String String))
-> Either String String -> m (Either String String)
forall a b. (a -> b) -> a -> b
$
case ((String, String) -> Bool)
-> [(String, String)] -> Maybe (String, String)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
file) (String -> Bool)
-> ((String, String) -> String) -> (String, String) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, String) -> String
forall a b. (a, b) -> a
fst) [(String, String)]
files of
Maybe (String, String)
Nothing -> String -> Either String String
forall a b. a -> Either a b
Left String
"File not included in mock."
Just (String
_, String
contents) -> String -> Either String String
forall a b. b -> Either a b
Right String
contents
fs :: p -> p -> p -> a -> m a
fs p
_ p
_ p
_ a
file = a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
file
mockRcFile :: String -> SystemInterface m -> SystemInterface m
mockRcFile String
rcfile SystemInterface m
mock = SystemInterface m
mock {
siGetConfig = const . return $ Just (".shellcheckrc", rcfile)
}