summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVidar Holen <spam@vidarholen.net>2018-10-21 17:21:08 -0700
committerVidar Holen <spam@vidarholen.net>2018-10-21 17:46:46 -0700
commitdf0a0d41fa2e7a00b3229a48a10a84d1565bdd2b (patch)
tree6abd5010e69e6949d017f58924b28e6bf36b40dd
parentb81524250698ccb0119d055417e22af446665c09 (diff)
Add SC1133: Warn when a line starts with |/||/&& (fixes #1359)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/ShellCheck/Parser.hs10
2 files changed, 9 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9078d56..60f890c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
- 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
+- SC1133: Better diagnostics when starting a line with |/||/&&
### Changed
- Most warnings now have useful end positions
- SC1117 about unknown double-quoted escape sequences has been retired
diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs
index aa99379..d656ed9 100644
--- a/src/ShellCheck/Parser.hs
+++ b/src/ShellCheck/Parser.hs
@@ -1911,7 +1911,13 @@ readHereString = called "here string" $ do
word <- readNormalWord
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
prop_readSeparator1 = isWarning readScript "a &; b"
@@ -2300,7 +2306,7 @@ readSubshell = called "explicit subshell" $ do
allspacing
list <- readCompoundList
allspacing
- char ')' <|> fail ") closing the subshell"
+ char ')' <|> fail "Expected ) closing the subshell"
id <- endSpan start
return $ T_Subshell id list