1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Warn about swapped !# in the shebang.

This commit is contained in:
Vidar Holen 2014-10-11 12:35:45 -07:00
parent b05c12223f
commit a69e27b774

@ -1962,12 +1962,21 @@ readKeyword = choice [ g_Then, g_Else, g_Elif, g_Fi, g_Do, g_Done, g_Esac, g_Rbr
ifParse p t f =
(lookAhead (try p) >> t) <|> f
prop_readShebang1 = isOk readShebang "#!/bin/sh\n"
prop_readShebang2 = isWarning readShebang "!# /bin/sh\n"
readShebang = do
try $ string "#!"
try readCorrect <|> try readSwapped
str <- many $ noneOf "\r\n"
optional carriageReturn
optional linefeed
return str
where
readCorrect = void $ string "#!"
readSwapped = do
pos <- getPosition
string "!#"
parseProblemAt pos ErrorC 1084
"Use #!, not !#, for the shebang."
prop_readScript1 = isOk readScript "#!/bin/bash\necho hello world\n"
prop_readScript2 = isWarning readScript "#!/bin/bash\r\necho hello world\n"