Don't trigger SC2037 when quoting (PAGER="cat" foo)
This commit is contained in:
parent
bc882fd85a
commit
faafc99704
|
@ -256,15 +256,28 @@ prop_checkAssignAteCommand1 = verify checkAssignAteCommand "A=ls -l"
|
||||||
prop_checkAssignAteCommand2 = verify checkAssignAteCommand "A=ls --sort=$foo"
|
prop_checkAssignAteCommand2 = verify checkAssignAteCommand "A=ls --sort=$foo"
|
||||||
prop_checkAssignAteCommand3 = verify checkAssignAteCommand "A=cat foo | grep bar"
|
prop_checkAssignAteCommand3 = verify checkAssignAteCommand "A=cat foo | grep bar"
|
||||||
prop_checkAssignAteCommand4 = verifyNot checkAssignAteCommand "A=foo ls -l"
|
prop_checkAssignAteCommand4 = verifyNot checkAssignAteCommand "A=foo ls -l"
|
||||||
prop_checkAssignAteCommand5 = verifyNot checkAssignAteCommand "PAGER=cat grep bar"
|
prop_checkAssignAteCommand5 = verify checkAssignAteCommand "PAGER=cat grep bar"
|
||||||
checkAssignAteCommand _ (T_SimpleCommand id (T_Assignment _ _ _ _ assignmentTerm:[]) (firstWord:_)) =
|
prop_checkAssignAteCommand6 = verifyNot checkAssignAteCommand "PAGER=\"cat\" grep bar"
|
||||||
when ("-" `isPrefixOf` concat (oversimplify firstWord) ||
|
prop_checkAssignAteCommand7 = verify checkAssignAteCommand "here=pwd"
|
||||||
isCommonCommand (getLiteralString assignmentTerm)
|
checkAssignAteCommand _ (T_SimpleCommand id (T_Assignment _ _ _ _ assignmentTerm:[]) list) =
|
||||||
&& not (isCommonCommand (getLiteralString firstWord))) $
|
-- Check if first word is intended as an argument (flag or glob).
|
||||||
warn id 2037 "To assign the output of a command, use var=$(cmd) ."
|
if firstWordIsArg list
|
||||||
|
then
|
||||||
|
err id 2037 "To assign the output of a command, use var=$(cmd) ."
|
||||||
|
else
|
||||||
|
-- Check if it's a known, unquoted command name.
|
||||||
|
when (isCommonCommand $ getUnquotedLiteral assignmentTerm) $
|
||||||
|
warn id 2209 "Use var=$(command) to assign output (or quote to assign string)."
|
||||||
where
|
where
|
||||||
isCommonCommand (Just s) = s `elem` commonCommands
|
isCommonCommand (Just s) = s `elem` commonCommands
|
||||||
isCommonCommand _ = False
|
isCommonCommand _ = False
|
||||||
|
firstWordIsArg list = fromMaybe False $ do
|
||||||
|
head <- list !!! 0
|
||||||
|
return . or $ mapMaybe ($ head) [return . isGlob, isFlag]
|
||||||
|
isFlag word = do
|
||||||
|
first <- (concat $ oversimplify word) !!! 0
|
||||||
|
return $ first == '-'
|
||||||
|
|
||||||
checkAssignAteCommand _ _ = return ()
|
checkAssignAteCommand _ _ = return ()
|
||||||
|
|
||||||
prop_checkArithmeticOpCommand1 = verify checkArithmeticOpCommand "i=i + 1"
|
prop_checkArithmeticOpCommand1 = verify checkArithmeticOpCommand "i=i + 1"
|
||||||
|
|
Loading…
Reference in New Issue