Skip to content

Commit

Permalink
Parse keywords with case sensitivity (fixes koalaman#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Feb 17, 2020
1 parent 1da0bec commit 106f321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
- SC2256: Warn about translated strings that are known variables

### Changed
- SC2230: This check is now off by default
- SC2230: 'command -v' suggestion is now off by default (-i deprecate-which)
- SC1081: Keywords are now correctly parsed case sensitively, with a warning

## v0.7.0 - 2019-07-28
### Added
Expand Down
9 changes: 6 additions & 3 deletions src/ShellCheck/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,7 @@ prop_readIfClause2 = isWarning readIfClause "if false; then; echo oo; 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; fi"
prop_readIfClause5 = isOk readIfClause "if false; then true; else\nif true; then echo lol; fi; fi"
prop_readIfClause6 = isWarning readIfClause "if true\nthen\nDo the thing\nfi"
readIfClause = called "if expression" $ do
start <- startSpan
pos <- getPosition
Expand Down Expand Up @@ -2890,6 +2891,7 @@ redirToken c t = try $ do

tryWordToken s t = tryParseWordToken s t `thenSkip` spacing
tryParseWordToken keyword t = try $ do
pos <- getPosition
start <- startSpan
str <- anycaseString keyword
id <- endSpan start
Expand All @@ -2905,9 +2907,10 @@ tryParseWordToken keyword t = try $ do
_ -> return ()

lookAhead keywordSeparator
when (str /= keyword) $
parseProblem ErrorC 1081 $
"Scripts are case sensitive. Use '" ++ keyword ++ "', not '" ++ str ++ "'."
when (str /= keyword) $ do
parseProblemAt pos ErrorC 1081 $
"Scripts are case sensitive. Use '" ++ keyword ++ "', not '" ++ str ++ "' (or quote if literal)."
fail ""
return $ t id

anycaseString =
Expand Down

0 comments on commit 106f321

Please sign in to comment.