Added check for "#!/usr/bin/env bash -x"

This commit is contained in:
Vidar Holen 2012-12-02 12:40:46 -08:00
parent 3c2d9557e0
commit 1a4301ea98
2 changed files with 11 additions and 2 deletions

View File

@ -33,6 +33,7 @@ checks = concat [
,[subshellAssignmentCheck] ,[subshellAssignmentCheck]
,[checkSpacefulness] ,[checkSpacefulness]
,[checkUnquotedExpansions] ,[checkUnquotedExpansions]
,[checkShebang]
] ]
runAllAnalytics = checkList checks runAllAnalytics = checkList checks
@ -223,6 +224,14 @@ bracedString l = concat $ deadSimple l
isMagicInQuotes (T_DollarBraced _ l) | '@' `elem` (bracedString l) = True isMagicInQuotes (T_DollarBraced _ l) | '@' `elem` (bracedString l) = True
isMagicInQuotes _ = False isMagicInQuotes _ = False
prop_checkShebang1 = verifyFull checkShebang "#!/usr/bin/env bash -x\necho cow"
prop_checkShebang2 = verifyNotFull checkShebang "#! /bin/sh -l "
checkShebang (T_Script id sb _) m =
if (length $ words sb) > 2 then
let note = Note ErrorC $ "On most OS, shebangs can only specify a single parameter."
in Map.adjust (\(Metadata pos notes) -> Metadata pos (note:notes)) id m
else m
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done" prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done" prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done"
prop_checkForInQuoted3 = verify checkForInQuoted "for f in 'find /'; do true; done" prop_checkForInQuoted3 = verify checkForInQuoted "for f in 'find /'; do true; done"

View File

@ -1338,8 +1338,8 @@ wtf = do
readShebang = do readShebang = do
try $ string "#!" try $ string "#!"
str <- anyChar `reluctantlyTill` oneOf "\r\n" str <- anyChar `reluctantlyTill` oneOf "\r\n"
optional $ carriageReturn optional carriageReturn
linefeed optional linefeed
return str return str
readScript = do readScript = do