mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-10 15:22:58 -07:00
Add support for source-path directives (fixes #1577)
This commit is contained in:
parent
aa4b24e458
commit
d9e419d60f
7 changed files with 67 additions and 17 deletions
|
@ -264,6 +264,15 @@ shouldIgnoreCode code = do
|
|||
disabling' (DisableComment n) = code == n
|
||||
disabling' _ = False
|
||||
|
||||
getCurrentAnnotations includeSource =
|
||||
concatMap get . takeWhile (not . isBoundary) <$> getCurrentContexts
|
||||
where
|
||||
get (ContextAnnotation list) = list
|
||||
get _ = []
|
||||
isBoundary (ContextSource _) = not includeSource
|
||||
isBoundary _ = False
|
||||
|
||||
|
||||
shouldFollow file = do
|
||||
context <- getCurrentContexts
|
||||
if any isThisFile context
|
||||
|
@ -966,7 +975,7 @@ readAnnotationWithoutPrefix = do
|
|||
where
|
||||
readKey = do
|
||||
keyPos <- getPosition
|
||||
key <- many1 letter
|
||||
key <- many1 (letter <|> char '-')
|
||||
char '=' <|> fail "Expected '=' after directive key"
|
||||
annotations <- case key of
|
||||
"disable" -> readCode `sepBy` char ','
|
||||
|
@ -980,6 +989,10 @@ readAnnotationWithoutPrefix = do
|
|||
filename <- many1 $ noneOf " \n"
|
||||
return [SourceOverride filename]
|
||||
|
||||
"source-path" -> do
|
||||
dirname <- many1 $ noneOf " \n"
|
||||
return [SourcePath dirname]
|
||||
|
||||
"shell" -> do
|
||||
pos <- getPosition
|
||||
shell <- many1 $ noneOf " \n"
|
||||
|
@ -2079,6 +2092,7 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
|
|||
proceed <- shouldFollow filename
|
||||
if not proceed
|
||||
then do
|
||||
-- FIXME: This actually gets squashed without -a
|
||||
parseNoteAtId (getId file) InfoC 1093
|
||||
"This file appears to be recursively sourced. Ignoring."
|
||||
return t
|
||||
|
@ -2089,7 +2103,8 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
|
|||
then return (Right "")
|
||||
else do
|
||||
currentScript <- Mr.asks currentFilename
|
||||
filename' <- system $ siFindSource sys currentScript filename
|
||||
paths <- mapMaybe getSourcePath <$> getCurrentAnnotations True
|
||||
filename' <- system $ siFindSource sys currentScript paths filename
|
||||
system $ siReadFile sys filename'
|
||||
case input of
|
||||
Left err -> do
|
||||
|
@ -2118,6 +2133,11 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
|
|||
x -> file
|
||||
getFile file _ = file
|
||||
|
||||
getSourcePath t =
|
||||
case t of
|
||||
SourcePath x -> Just x
|
||||
_ -> Nothing
|
||||
|
||||
subRead name script =
|
||||
withContext (ContextSource name) $
|
||||
inSeparateContext $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue