mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-14 00:53:15 -07:00
Parse but warn about "else if"
This commit is contained in:
parent
b7ee5f4410
commit
74ea5eaeec
1 changed files with 9 additions and 1 deletions
|
@ -1348,6 +1348,8 @@ readCmdWord = do
|
||||||
prop_readIfClause = isOk readIfClause "if false; then foo; elif true; then stuff; more stuff; else cows; fi"
|
prop_readIfClause = isOk readIfClause "if false; then foo; elif true; then stuff; more stuff; else cows; fi"
|
||||||
prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; fi"
|
prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; fi"
|
||||||
prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol; fi"
|
prop_readIfClause3 = isWarning readIfClause "if false; then true; else; echo lol; fi"
|
||||||
|
prop_readIfClause4 = isWarning readIfClause "if false; then true; else if true; then echo lol; fi"
|
||||||
|
prop_readIfClause5 = isOk readIfClause "if false; then true; else\nif true; then echo lol; fi; fi"
|
||||||
readIfClause = called "if expression" $ do
|
readIfClause = called "if expression" $ do
|
||||||
id <- getNextId
|
id <- getNextId
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
|
@ -1389,7 +1391,9 @@ readIfPart = do
|
||||||
|
|
||||||
readElifPart = called "elif clause" $ do
|
readElifPart = called "elif clause" $ do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
g_Elif
|
correctElif <- elif
|
||||||
|
when (not correctElif) $
|
||||||
|
parseProblemAt pos ErrorC 1075 "Use 'elif' instead of 'else if'."
|
||||||
allspacing
|
allspacing
|
||||||
condition <- readTerm
|
condition <- readTerm
|
||||||
g_Then
|
g_Then
|
||||||
|
@ -1398,8 +1402,12 @@ readElifPart = called "elif clause" $ do
|
||||||
verifyNotEmptyIf "then"
|
verifyNotEmptyIf "then"
|
||||||
action <- readTerm
|
action <- readTerm
|
||||||
return (condition, action)
|
return (condition, action)
|
||||||
|
where
|
||||||
|
elif = (g_Elif >> return True) <|>
|
||||||
|
(try $ g_Else >> g_If >> return False)
|
||||||
|
|
||||||
readElsePart = called "else clause" $ do
|
readElsePart = called "else clause" $ do
|
||||||
|
pos <- getPosition
|
||||||
g_Else
|
g_Else
|
||||||
acceptButWarn g_Semi ErrorC 1053 "No semicolons directly after 'else'."
|
acceptButWarn g_Semi ErrorC 1053 "No semicolons directly after 'else'."
|
||||||
allspacing
|
allspacing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue