Error on backslash in comment #2132

- Report error in case of a backspace in a comment

Backspaces in comments are no good. In most cases they are the result of
commenting out a longer line, that was broken down. This usually results
in the shell treating the following lines as their own commands on their
own lines instead of as parts of the longer, broken down line.
This commit is contained in:
Moritz Röhrich 2021-02-14 19:13:29 +01:00
parent 15ff87cf80
commit d6bb8fc0d8
1 changed files with 6 additions and 1 deletions

View File

@ -1039,9 +1039,14 @@ readComment = do
unexpecting "shellcheck annotation" readAnnotationPrefix unexpecting "shellcheck annotation" readAnnotationPrefix
readAnyComment readAnyComment
prop_readAnyComment = isOk readAnyComment "# Comment"
prop_readAnyComment1 = not $ isOk readAnyComment "# Comment \\\n"
readAnyComment = do readAnyComment = do
char '#' char '#'
many $ noneOf "\r\n" comment <- many $ noneOf "\\\r\n"
bs <- many $ oneOf "\\"
unless (null bs) (fail "Backslash in or directly after comment")
return comment
prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)" prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)"
prop_readNormalWord2 = isOk readNormalWord "foo**(foo)!!!(@@(bar))" prop_readNormalWord2 = isOk readNormalWord "foo**(foo)!!!(@@(bar))"