Warn about C-style comments

This commit is contained in:
Vidar Holen 2018-01-17 18:14:36 -08:00
parent dc1e7c1bd4
commit a6fb9d1ef8
2 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,7 @@
## Latest - ???
### Added
- SC2223: Quote warning specific to `: ${var=value}`
- SC1127: Warn about C-style comments
### Changed
- SC1073: 'else if' is now parsed correctly and not like 'elif'

View File

@ -1838,6 +1838,10 @@ prop_readSimpleCommand4 = isOk readSimpleCommand "typeset -a foo=(lol)"
prop_readSimpleCommand5 = isOk readSimpleCommand "time if true; then echo foo; fi"
prop_readSimpleCommand6 = isOk readSimpleCommand "time -p ( ls -l; )"
prop_readSimpleCommand7 = isOk readSimpleCommand "\\ls"
prop_readSimpleCommand8 = isWarning readSimpleCommand "// Lol"
prop_readSimpleCommand9 = isWarning readSimpleCommand "/* Lolbert */"
prop_readSimpleCommand10 = isWarning readSimpleCommand "/**** Lolbert */"
prop_readSimpleCommand11 = isOk readSimpleCommand "/\\* foo"
readSimpleCommand = called "simple command" $ do
pos <- getPosition
id1 <- getNextId
@ -1846,6 +1850,10 @@ readSimpleCommand = called "simple command" $ do
skipAnnotationAndWarn
cmd <- option Nothing $ do { f <- readCmdName; return $ Just f; }
when (null prefix && isNothing cmd) $ fail "Expected a command"
when (cStyleComment cmd) $
parseProblemAt pos ErrorC 1127 "Was this intended as a comment? Use # in sh."
case cmd of
Nothing -> return $ makeSimpleCommand id1 id2 prefix [] []
Just cmd -> do
@ -1869,6 +1877,13 @@ readSimpleCommand = called "simple command" $ do
then action
else getParser def cmd rest
cStyleComment cmd =
case cmd of
Just (T_NormalWord _ [T_Literal _ "//"]) -> True
Just (T_NormalWord _ (T_Literal _ "/" : T_Glob _ "*" :_)) -> True
_ -> False
readSource :: Monad m => SourcePos -> Token -> SCParser m Token
readSource pos t@(T_Redirecting _ _ (T_SimpleCommand _ _ (cmd:file:_))) = do