From a69e27b7740406d38d2599cdbc1c3cee59bafacc Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 11 Oct 2014 12:35:45 -0700 Subject: [PATCH] Warn about swapped !# in the shebang. --- ShellCheck/Parser.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index eec9f3f..0411a06 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -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"