mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-11 15:46:26 -07:00
Warn for [ \( foo = bar\) ]
This commit is contained in:
parent
e6f2ee1f88
commit
5a3493740e
1 changed files with 15 additions and 12 deletions
|
@ -267,17 +267,20 @@ readConditionContents single = do
|
||||||
notFollowedBy2 (try (spacing >> (string "]")))
|
notFollowedBy2 (try (spacing >> (string "]")))
|
||||||
x <- readNormalWord
|
x <- readNormalWord
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
if (endedWithBracket x)
|
when (endedWith "]" x) $ do
|
||||||
then do
|
lookAhead (try $
|
||||||
lookAhead (try $ (many whitespace) >> (eof <|> disregard readSeparator <|> disregard (g_Then <|> g_Do)))
|
(many whitespace) >> (eof <|> disregard readSeparator <|> disregard (g_Then <|> g_Do)))
|
||||||
parseProblemAt pos ErrorC $ "You need a space before the " ++ (if single then "]" else "]]") ++ "."
|
parseProblemAt pos ErrorC $
|
||||||
else
|
"You need a space before the " ++ (if single then "]" else "]]") ++ "."
|
||||||
disregard spacing
|
when (single && endedWith ")" x) $ do
|
||||||
|
parseProblemAt pos ErrorC $
|
||||||
|
"You need a space before the \\)"
|
||||||
|
disregard spacing
|
||||||
return x
|
return x
|
||||||
where endedWithBracket (T_NormalWord id s@(_:_)) =
|
where endedWith str (T_NormalWord id s@(_:_)) =
|
||||||
case (last s) of T_Literal id s -> "]" `isSuffixOf` s
|
case (last s) of T_Literal id s -> str `isSuffixOf` s
|
||||||
_ -> False
|
_ -> False
|
||||||
endedWithBracket _ = False
|
endedWith _ _ = False
|
||||||
|
|
||||||
readCondAndOp = do
|
readCondAndOp = do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
|
@ -318,14 +321,14 @@ readConditionContents single = do
|
||||||
readCondGroup = do
|
readCondGroup = do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
lparen <- string "(" <|> string "\\("
|
lparen <- try $ string "(" <|> string "\\("
|
||||||
when (single && lparen == "(") $ parseProblemAt pos ErrorC "In [..] you have to escape (). Use [[..]] instead."
|
when (single && lparen == "(") $ parseProblemAt pos ErrorC "In [..] you have to escape (). Use [[..]] instead."
|
||||||
when (not single && lparen == "\\(") $ parseProblemAt pos ErrorC "In [[..]] you shouldn't escape ()."
|
when (not single && lparen == "\\(") $ parseProblemAt pos ErrorC "In [[..]] you shouldn't escape ()."
|
||||||
if single then softCondSpacing else disregard spacing
|
if single then hardCondSpacing else disregard spacing
|
||||||
x <- readCondContents
|
x <- readCondContents
|
||||||
cpos <- getPosition
|
cpos <- getPosition
|
||||||
rparen <- string ")" <|> string "\\)"
|
rparen <- string ")" <|> string "\\)"
|
||||||
if single then softCondSpacing else disregard spacing
|
if single then hardCondSpacing else disregard spacing
|
||||||
when (single && rparen == ")") $ parseProblemAt cpos ErrorC "In [..] you have to escape (). Use [[..]] instead."
|
when (single && rparen == ")") $ parseProblemAt cpos ErrorC "In [..] you have to escape (). Use [[..]] instead."
|
||||||
when (not single && rparen == "\\)") $ parseProblemAt cpos ErrorC "In [[..]] you shouldn't escape ()."
|
when (not single && rparen == "\\)") $ parseProblemAt cpos ErrorC "In [[..]] you shouldn't escape ()."
|
||||||
when (isEscaped lparen `xor` isEscaped rparen) $ parseProblemAt pos ErrorC "Did you just escape one half of () but not the other?"
|
when (isEscaped lparen `xor` isEscaped rparen) $ parseProblemAt pos ErrorC "Did you just escape one half of () but not the other?"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue