Extend warnings about spaces around = to 'let'
This commit is contained in:
parent
4dd762253f
commit
e5745568e8
|
@ -101,7 +101,7 @@ commandChecks = [
|
||||||
++ map checkArgComparison declaringCommands
|
++ map checkArgComparison declaringCommands
|
||||||
++ map checkMaskedReturns declaringCommands
|
++ map checkMaskedReturns declaringCommands
|
||||||
|
|
||||||
declaringCommands = ["local", "declare", "export", "readonly", "typeset"]
|
declaringCommands = ["local", "declare", "export", "readonly", "typeset", "let"]
|
||||||
|
|
||||||
|
|
||||||
optionalChecks = map fst optionalCommandChecks
|
optionalChecks = map fst optionalCommandChecks
|
||||||
|
@ -1156,11 +1156,13 @@ prop_checkArgComparison2 = verify (checkArgComparison "declare") "declare a =b"
|
||||||
prop_checkArgComparison3 = verifyNot (checkArgComparison "declare") "declare a=b"
|
prop_checkArgComparison3 = verifyNot (checkArgComparison "declare") "declare a=b"
|
||||||
prop_checkArgComparison4 = verify (checkArgComparison "export") "export a +=b"
|
prop_checkArgComparison4 = verify (checkArgComparison "export") "export a +=b"
|
||||||
prop_checkArgComparison7 = verifyNot (checkArgComparison "declare") "declare -a +i foo"
|
prop_checkArgComparison7 = verifyNot (checkArgComparison "declare") "declare -a +i foo"
|
||||||
|
prop_checkArgComparison8 = verify (checkArgComparison "let") "let x = 0"
|
||||||
-- This mirrors checkSecondArgIsComparison but for arguments to local/readonly/declare/export
|
-- This mirrors checkSecondArgIsComparison but for arguments to local/readonly/declare/export
|
||||||
checkArgComparison str = CommandCheck (Exactly str) wordsWithEqual
|
checkArgComparison cmd = CommandCheck (Exactly cmd) wordsWithEqual
|
||||||
where
|
where
|
||||||
wordsWithEqual t = mapM_ check $ drop 1 $ arguments t
|
wordsWithEqual t = mapM_ check $ arguments t
|
||||||
check arg = sequence_ $ do
|
check arg = do
|
||||||
|
sequence_ $ do
|
||||||
str <- getLeadingUnquotedString arg
|
str <- getLeadingUnquotedString arg
|
||||||
case str of
|
case str of
|
||||||
'=':_ ->
|
'=':_ ->
|
||||||
|
@ -1171,6 +1173,15 @@ checkArgComparison str = CommandCheck (Exactly str) wordsWithEqual
|
||||||
"Remove spaces around += to append."
|
"Remove spaces around += to append."
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
-- 'let' is parsed as a sequence of arithmetic expansions,
|
||||||
|
-- so we want the additional warning for "x="
|
||||||
|
when (cmd == "let") $ sequence_ $ do
|
||||||
|
token <- getTrailingUnquotedLiteral arg
|
||||||
|
str <- getLiteralString token
|
||||||
|
guard $ "=" `isSuffixOf` str
|
||||||
|
return $ err (getId token) 2290 $
|
||||||
|
"Remove spaces around = to assign."
|
||||||
|
|
||||||
headId t =
|
headId t =
|
||||||
case t of
|
case t of
|
||||||
T_NormalWord _ (x:_) -> getId x
|
T_NormalWord _ (x:_) -> getId x
|
||||||
|
|
|
@ -2810,7 +2810,7 @@ readLetSuffix = many1 (readIoRedirect <|> try readLetExpression <|> readCmdWord)
|
||||||
startPos <- getPosition
|
startPos <- getPosition
|
||||||
expression <- readStringForParser readCmdWord
|
expression <- readStringForParser readCmdWord
|
||||||
let (unQuoted, newPos) = kludgeAwayQuotes expression startPos
|
let (unQuoted, newPos) = kludgeAwayQuotes expression startPos
|
||||||
subParse newPos readArithmeticContents unQuoted
|
subParse newPos (readArithmeticContents <* eof) unQuoted
|
||||||
|
|
||||||
kludgeAwayQuotes :: String -> SourcePos -> (String, SourcePos)
|
kludgeAwayQuotes :: String -> SourcePos -> (String, SourcePos)
|
||||||
kludgeAwayQuotes s p =
|
kludgeAwayQuotes s p =
|
||||||
|
|
Loading…
Reference in New Issue