Check for [[ i + 1 = 2 ]]
This commit is contained in:
parent
0ec62390d5
commit
9ae776530b
|
@ -2,7 +2,7 @@ module ShellCheck.Data where
|
|||
|
||||
internalVariables = [
|
||||
-- Generic
|
||||
"", "_",
|
||||
"", "_", "rest", "REST",
|
||||
|
||||
-- Bash
|
||||
"BASH", "BASHOPTS", "BASHPID", "BASH_ALIASES", "BASH_ARGC",
|
||||
|
|
|
@ -34,8 +34,6 @@ import System.IO
|
|||
import Text.Parsec.Error
|
||||
import GHC.Exts (sortWith)
|
||||
|
||||
lastError = 1074
|
||||
|
||||
backslash = char '\\'
|
||||
linefeed = (optional carriageReturn) >> char '\n'
|
||||
singleQuote = char '\'' <|> unicodeSingleQuote
|
||||
|
@ -269,6 +267,7 @@ readConditionContents single = do
|
|||
where
|
||||
typ = if single then SingleBracket else DoubleBracket
|
||||
readCondBinaryOp = try $ do
|
||||
optional guardArithmetic
|
||||
id <- getNextId
|
||||
op <- (choice $ (map tryOp ["==", "!=", "<=", ">=", "=~", ">", "<", "=", "\\<=", "\\>=", "\\<", "\\>"])) <|> otherOp
|
||||
hardCondSpacing
|
||||
|
@ -284,6 +283,13 @@ readConditionContents single = do
|
|||
when (s == "-a" || s == "-o") $ fail "Wrong operator"
|
||||
return $ TC_Binary id typ s
|
||||
|
||||
guardArithmetic = do
|
||||
try . lookAhead $ disregard (oneOf "+*/%") <|> disregard (string "- ")
|
||||
parseProblem ErrorC 1076 $
|
||||
if single
|
||||
then "Trying to do math? Use e.g. [ $((i/2+7)) -ge 18 ]."
|
||||
else "Trying to do math? Use e.g. [[ $((i/2+7)) -ge 18 ]]."
|
||||
|
||||
readCondUnaryExp = do
|
||||
op <- readCondUnaryOp
|
||||
pos <- getPosition
|
||||
|
@ -323,6 +329,7 @@ readConditionContents single = do
|
|||
endedWith _ _ = False
|
||||
|
||||
readCondAndOp = do
|
||||
optional guardArithmetic
|
||||
id <- getNextId
|
||||
x <- try (string "&&" <|> string "-a")
|
||||
when (single && x == "&&") $ addNoteFor id $ Note ErrorC 1022 "You can't use && inside [..]. Use [[..]] instead."
|
||||
|
@ -331,6 +338,7 @@ readConditionContents single = do
|
|||
return $ TC_And id typ x
|
||||
|
||||
readCondOrOp = do
|
||||
optional guardArithmetic
|
||||
id <- getNextId
|
||||
x <- try (string "||" <|> string "-o")
|
||||
when (single && x == "||") $ addNoteFor id $ Note ErrorC 1024 "You can't use || inside [..]. Use [[..]] instead."
|
||||
|
|
Loading…
Reference in New Issue