diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c359a7..88c9f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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' diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 50dcaa9..3ce5ae4 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -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