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