Fix annotations for here documents (fixes #1071)
This commit is contained in:
parent
81978d15bd
commit
46a3019ed7
|
@ -4,6 +4,9 @@
|
||||||
- SC2223: Quote warning specific to `: ${var=value}`
|
- SC2223: Quote warning specific to `: ${var=value}`
|
||||||
- SC1127: Warn about C-style comments
|
- SC1127: Warn about C-style comments
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Annotations intended for a command's here documents now work
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- SC1073: 'else if' is now parsed correctly and not like 'elif'
|
- SC1073: 'else if' is now parsed correctly and not like 'elif'
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ data Context =
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data HereDocContext =
|
data HereDocContext =
|
||||||
HereDocPending Token -- on linefeed, read this T_HereDoc
|
HereDocPending Token [Context] -- on linefeed, read this T_HereDoc
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data UserState = UserState {
|
data UserState = UserState {
|
||||||
|
@ -194,9 +194,10 @@ addToHereDocMap id list = do
|
||||||
|
|
||||||
addPendingHereDoc t = do
|
addPendingHereDoc t = do
|
||||||
state <- getState
|
state <- getState
|
||||||
|
context <- getCurrentContexts
|
||||||
let docs = pendingHereDocs state
|
let docs = pendingHereDocs state
|
||||||
putState $ state {
|
putState $ state {
|
||||||
pendingHereDocs = HereDocPending t : docs
|
pendingHereDocs = HereDocPending t context : docs
|
||||||
}
|
}
|
||||||
|
|
||||||
popPendingHereDocs = do
|
popPendingHereDocs = do
|
||||||
|
@ -205,9 +206,7 @@ popPendingHereDocs = do
|
||||||
putState $ state {
|
putState $ state {
|
||||||
pendingHereDocs = []
|
pendingHereDocs = []
|
||||||
}
|
}
|
||||||
return . map extract . reverse $ pendingHereDocs state
|
return . reverse $ pendingHereDocs state
|
||||||
where
|
|
||||||
extract (HereDocPending t) = t
|
|
||||||
|
|
||||||
getMap = positionMap <$> getState
|
getMap = positionMap <$> getState
|
||||||
getParseNotes = parseNotes <$> getState
|
getParseNotes = parseNotes <$> getState
|
||||||
|
@ -372,15 +371,16 @@ acceptButWarn parser level code note =
|
||||||
parseProblemAt pos level code note
|
parseProblemAt pos level code note
|
||||||
)
|
)
|
||||||
|
|
||||||
withContext entry p = do
|
parsecBracket before after op = do
|
||||||
pushContext entry
|
val <- before
|
||||||
do
|
(op val <* optional (after val)) <|> (after val *> fail "")
|
||||||
v <- p
|
|
||||||
popContext
|
swapContext contexts p =
|
||||||
return v
|
parsecBracket (getCurrentContexts <* setCurrentContexts contexts)
|
||||||
<|> do -- p failed without consuming input, abort context
|
setCurrentContexts
|
||||||
v <- popContext
|
(const p)
|
||||||
fail ""
|
|
||||||
|
withContext entry p = parsecBracket (pushContext entry) (const popContext) (const p)
|
||||||
|
|
||||||
called s p = do
|
called s p = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
@ -1594,6 +1594,8 @@ prop_readHereDoc14= isWarning readScript "cat << foo\nbar\nfoo \n"
|
||||||
prop_readHereDoc15= isWarning readScript "cat <<foo\nbar\nfoo bar\n"
|
prop_readHereDoc15= isWarning readScript "cat <<foo\nbar\nfoo bar\n"
|
||||||
prop_readHereDoc16= isOk readScript "cat <<- ' foo'\nbar\n foo\n"
|
prop_readHereDoc16= isOk readScript "cat <<- ' foo'\nbar\n foo\n"
|
||||||
prop_readHereDoc17= isWarning readScript "cat <<- ' foo'\nbar\n foo\n"
|
prop_readHereDoc17= isWarning readScript "cat <<- ' foo'\nbar\n foo\n"
|
||||||
|
prop_readHereDoc18= isWarning readScript "cat << foo\nLoose \\t\nfoo"
|
||||||
|
prop_readHereDoc19= isOk readScript "# shellcheck disable=SC1117\ncat << foo\nLoose \\t\nfoo"
|
||||||
readHereDoc = called "here document" $ do
|
readHereDoc = called "here document" $ do
|
||||||
fid <- getNextId
|
fid <- getNextId
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
@ -1625,7 +1627,8 @@ readPendingHereDocs = do
|
||||||
docs <- popPendingHereDocs
|
docs <- popPendingHereDocs
|
||||||
mapM_ readDoc docs
|
mapM_ readDoc docs
|
||||||
where
|
where
|
||||||
readDoc (T_HereDoc id dashed quoted endToken _) = do
|
readDoc (HereDocPending (T_HereDoc id dashed quoted endToken _) ctx) =
|
||||||
|
swapContext ctx $ do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
hereData <- concat <$> rawLine `reluctantlyTill` do
|
hereData <- concat <$> rawLine `reluctantlyTill` do
|
||||||
linewhitespace `reluctantlyTill` string endToken
|
linewhitespace `reluctantlyTill` string endToken
|
||||||
|
|
Loading…
Reference in New Issue