Warn about comments/blanks before shebang. Fixes #844
This commit is contained in:
parent
7b3c4025fb
commit
c86885427c
|
@ -3,6 +3,7 @@
|
|||
- SC2227: Warn about redirections in the middle of 'find' commands
|
||||
- SC2224,SC2225,SC2226: Warn when using mv/cp/ln without a destination
|
||||
- SC2223: Quote warning specific to `: ${var=value}`
|
||||
- SC1128: Warn about blanks/comments before shebang
|
||||
- SC1127: Warn about C-style comments
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -2654,20 +2654,23 @@ prop_readShebang1 = isOk readShebang "#!/bin/sh\n"
|
|||
prop_readShebang2 = isWarning readShebang "!# /bin/sh\n"
|
||||
prop_readShebang3 = isNotOk readShebang "#shellcheck shell=/bin/sh\n"
|
||||
prop_readShebang4 = isWarning readShebang "! /bin/sh"
|
||||
prop_readShebang5 = isWarning readShebang "\n#!/bin/sh"
|
||||
prop_readShebang6 = isWarning readShebang " # Copyright \n!#/bin/bash"
|
||||
prop_readShebang7 = isNotOk readShebang "# Copyright \nfoo\n#!/bin/bash"
|
||||
readShebang = do
|
||||
choice $ map try [
|
||||
readCorrect,
|
||||
readSwapped,
|
||||
readTooManySpaces,
|
||||
readMissingHash,
|
||||
readMissingBang
|
||||
]
|
||||
anyShebang <|> try readMissingBang <|> withHeader
|
||||
many linewhitespace
|
||||
str <- many $ noneOf "\r\n"
|
||||
optional carriageReturn
|
||||
optional linefeed
|
||||
return str
|
||||
where
|
||||
anyShebang = choice $ map try [
|
||||
readCorrect,
|
||||
readSwapped,
|
||||
readTooManySpaces,
|
||||
readMissingHash
|
||||
]
|
||||
readCorrect = void $ string "#!"
|
||||
|
||||
readSwapped = do
|
||||
|
@ -2705,11 +2708,22 @@ readShebang = do
|
|||
parseProblemAt pos ErrorC 1113
|
||||
"Use #!, not just #, for the shebang."
|
||||
|
||||
|
||||
ensurePathAhead = lookAhead $ do
|
||||
many linewhitespace
|
||||
char '/'
|
||||
|
||||
withHeader = try $ do
|
||||
many1 headerLine
|
||||
pos <- getPosition
|
||||
anyShebang <*
|
||||
parseProblemAt pos ErrorC 1128 "The shebang must be on the first line. Delete blanks and move comments."
|
||||
|
||||
headerLine = do
|
||||
notFollowedBy2 anyShebang
|
||||
many linewhitespace
|
||||
optional readAnyComment
|
||||
linefeed
|
||||
|
||||
verifyEof = eof <|> choice [
|
||||
ifParsable g_Lparen $
|
||||
parseProblem ErrorC 1088 "Parsing stopped here. Invalid use of parentheses?",
|
||||
|
|
Loading…
Reference in New Issue