Directives after the shebang now apply to the entire script.

Also adds support for the shell= directive.
This commit is contained in:
Vidar Holen
2016-03-08 20:16:16 -08:00
parent 6af1aeb259
commit 944313c6ba
3 changed files with 52 additions and 15 deletions

View File

@@ -772,7 +772,7 @@ prop_readAnnotation3 = isOk readAnnotation "# shellcheck disable=SC1234 source=/
readAnnotation = called "shellcheck annotation" $ do
try readAnnotationPrefix
many1 linewhitespace
values <- many1 (readDisable <|> readSourceOverride)
values <- many1 (readDisable <|> readSourceOverride <|> readShellOverride)
linefeed
many linewhitespace
return $ concat values
@@ -789,6 +789,14 @@ readAnnotation = called "shellcheck annotation" $ do
filename <- many1 $ noneOf " \n"
return [SourceOverride filename]
readShellOverride = forKey "shell" $ do
pos <- getPosition
shell <- many1 $ noneOf " \n"
when (isNothing $ shellForExecutable shell) $
parseNoteAt pos ErrorC 1103
"This shell type is unknown. Use e.g. sh or bash."
return [ShellOverride shell]
forKey s p = do
try $ string s
char '='
@@ -2334,6 +2342,7 @@ ifParse p t f =
prop_readShebang1 = isOk readShebang "#!/bin/sh\n"
prop_readShebang2 = isWarning readShebang "!# /bin/sh\n"
prop_readShebang3 = isNotOk readShebang "#shellcheck shell=/bin/sh\n"
readShebang = do
try readCorrect <|> try readSwapped
str <- many $ noneOf "\r\n"
@@ -2378,9 +2387,11 @@ readScript = do
verifyShell pos (getShell sb)
if isValidShell (getShell sb) /= Just False
then do
commands <- readCompoundListOrEmpty
annotationId <- getNextId
annotations <- readAnnotations
commands <- withAnnotations annotations readCompoundListOrEmpty
verifyEof
return $ T_Script id sb commands
return $ T_Annotation annotationId annotations $ T_Script id sb commands
else do
many anyChar
return $ T_Script id sb []