mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-09-21 19:29:29 +08:00
Warn about C-style comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
## Latest - ???
|
## Latest - ???
|
||||||
### Added
|
### Added
|
||||||
- SC2223: Quote warning specific to `: ${var=value}`
|
- SC2223: Quote warning specific to `: ${var=value}`
|
||||||
|
- SC1127: Warn about C-style comments
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- SC1073: 'else if' is now parsed correctly and not like 'elif'
|
- SC1073: 'else if' is now parsed correctly and not like 'elif'
|
||||||
|
@@ -1838,6 +1838,10 @@ prop_readSimpleCommand4 = isOk readSimpleCommand "typeset -a foo=(lol)"
|
|||||||
prop_readSimpleCommand5 = isOk readSimpleCommand "time if true; then echo foo; fi"
|
prop_readSimpleCommand5 = isOk readSimpleCommand "time if true; then echo foo; fi"
|
||||||
prop_readSimpleCommand6 = isOk readSimpleCommand "time -p ( ls -l; )"
|
prop_readSimpleCommand6 = isOk readSimpleCommand "time -p ( ls -l; )"
|
||||||
prop_readSimpleCommand7 = isOk readSimpleCommand "\\ls"
|
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
|
readSimpleCommand = called "simple command" $ do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
id1 <- getNextId
|
id1 <- getNextId
|
||||||
@@ -1846,6 +1850,10 @@ readSimpleCommand = called "simple command" $ do
|
|||||||
skipAnnotationAndWarn
|
skipAnnotationAndWarn
|
||||||
cmd <- option Nothing $ do { f <- readCmdName; return $ Just f; }
|
cmd <- option Nothing $ do { f <- readCmdName; return $ Just f; }
|
||||||
when (null prefix && isNothing cmd) $ fail "Expected a command"
|
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
|
case cmd of
|
||||||
Nothing -> return $ makeSimpleCommand id1 id2 prefix [] []
|
Nothing -> return $ makeSimpleCommand id1 id2 prefix [] []
|
||||||
Just cmd -> do
|
Just cmd -> do
|
||||||
@@ -1869,6 +1877,13 @@ readSimpleCommand = called "simple command" $ do
|
|||||||
then action
|
then action
|
||||||
else getParser def cmd rest
|
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 :: Monad m => SourcePos -> Token -> SCParser m Token
|
||||||
readSource pos t@(T_Redirecting _ _ (T_SimpleCommand _ _ (cmd:file:_))) = do
|
readSource pos t@(T_Redirecting _ _ (T_SimpleCommand _ _ (cmd:file:_))) = do
|
||||||
|
Reference in New Issue
Block a user