Add SC1133: Warn when a line starts with |/||/&& (fixes )

This commit is contained in:
Vidar Holen 2018-10-21 17:21:08 -07:00
parent b815242506
commit df0a0d41fa
2 changed files with 9 additions and 2 deletions
CHANGELOG.md
src/ShellCheck

View File

@ -5,6 +5,7 @@
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n - SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
- SC2238: Warn when redirecting to a known command name, e.g. ls > rm - SC2238: Warn when redirecting to a known command name, e.g. ls > rm
- SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh - SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh
- SC1133: Better diagnostics when starting a line with |/||/&&
### Changed ### Changed
- Most warnings now have useful end positions - Most warnings now have useful end positions
- SC1117 about unknown double-quoted escape sequences has been retired - SC1117 about unknown double-quoted escape sequences has been retired

View File

@ -1911,7 +1911,13 @@ readHereString = called "here string" $ do
word <- readNormalWord word <- readNormalWord
return $ T_HereString id word return $ T_HereString id word
readNewlineList = many1 ((linefeed <|> carriageReturn) `thenSkip` spacing) readNewlineList =
many1 ((linefeed <|> carriageReturn) `thenSkip` spacing) <* checkBadBreak
where
checkBadBreak = optional $ do
pos <- getPosition
try $ lookAhead (oneOf "|&") -- |, || or &&
parseProblemAt pos ErrorC 1133 "Unexpected start of line. If breaking lines, |/||/&& should be at the end of the previous one."
readLineBreak = optional readNewlineList readLineBreak = optional readNewlineList
prop_readSeparator1 = isWarning readScript "a &; b" prop_readSeparator1 = isWarning readScript "a &; b"
@ -2300,7 +2306,7 @@ readSubshell = called "explicit subshell" $ do
allspacing allspacing
list <- readCompoundList list <- readCompoundList
allspacing allspacing
char ')' <|> fail ") closing the subshell" char ')' <|> fail "Expected ) closing the subshell"
id <- endSpan start id <- endSpan start
return $ T_Subshell id list return $ T_Subshell id list