Expose token positions in params, use that to construct fixes

This commit is contained in:
Ng Zhi An 2018-10-20 22:09:42 -07:00 committed by Vidar Holen
parent 41613babd9
commit 4a87d2a3de
5 changed files with 59 additions and 49 deletions

View file

@ -24,7 +24,7 @@ module ShellCheck.Interface
, CheckResult(crFilename, crComments)
, ParseSpec(psFilename, psScript, psCheckSourced, psShellTypeOverride)
, ParseResult(prComments, prTokenPositions, prRoot)
, AnalysisSpec(asScript, asShellType, asExecutionMode, asCheckSourced)
, AnalysisSpec(asScript, asShellType, asExecutionMode, asCheckSourced, asTokenPositions)
, AnalysisResult(arComments)
, FormatterOptions(foColorOption, foWikiLinkCount)
, Shell(Ksh, Sh, Bash, Dash)
@ -50,10 +50,7 @@ module ShellCheck.Interface
, newPositionedComment
, newComment
, Fix
, Replacement(Start, End)
, surroundWith
, replaceStart
, replaceEnd
, Replacement(R)
) where
import ShellCheck.AST
@ -132,14 +129,16 @@ data AnalysisSpec = AnalysisSpec {
asScript :: Token,
asShellType :: Maybe Shell,
asExecutionMode :: ExecutionMode,
asCheckSourced :: Bool
asCheckSourced :: Bool,
asTokenPositions :: Map.Map Id (Position, Position)
}
newAnalysisSpec token = AnalysisSpec {
asScript = token,
asShellType = Nothing,
asExecutionMode = Executed,
asCheckSourced = False
asCheckSourced = False,
asTokenPositions = Map.empty
}
newtype AnalysisResult = AnalysisResult {
@ -198,23 +197,11 @@ newComment = Comment {
-- only support single line for now
data Replacement =
Start Integer String
| End Integer String
R Position Position String
deriving (Show, Eq)
type Fix = [Replacement]
surroundWith s =
(replaceStart 0 s) ++ (replaceEnd 0 s)
-- replace first n chars
replaceStart n r =
[ Start n r ]
-- replace last n chars
replaceEnd n r =
[ End n r ]
data PositionedComment = PositionedComment {
pcStartPos :: Position,
pcEndPos :: Position,