Ignore SC2033 when passing quoted function names.
This commit is contained in:
parent
5f7419ca37
commit
f9c346cfd7
ShellCheck
|
@ -1394,7 +1394,7 @@ getGlobOrLiteralString = getLiteralStringExt f
|
||||||
|
|
||||||
getLiteralStringExt more = g
|
getLiteralStringExt more = g
|
||||||
where
|
where
|
||||||
allInList = liftM concat . sequence . map g
|
allInList = liftM concat . mapM g
|
||||||
g (T_DoubleQuoted _ l) = allInList l
|
g (T_DoubleQuoted _ l) = allInList l
|
||||||
g (T_DollarDoubleQuoted _ l) = allInList l
|
g (T_DollarDoubleQuoted _ l) = allInList l
|
||||||
g (T_NormalWord _ l) = allInList l
|
g (T_NormalWord _ l) = allInList l
|
||||||
|
@ -1410,6 +1410,13 @@ getWordParts (T_NormalWord _ l) = concatMap getWordParts l
|
||||||
getWordParts (T_DoubleQuoted _ l) = l
|
getWordParts (T_DoubleQuoted _ l) = l
|
||||||
getWordParts other = [other]
|
getWordParts other = [other]
|
||||||
|
|
||||||
|
getUnquotedLiteral (T_NormalWord _ list) =
|
||||||
|
liftM concat $ mapM str list
|
||||||
|
where
|
||||||
|
str (T_Literal _ s) = return s
|
||||||
|
str _ = Nothing
|
||||||
|
getUnquotedLiteral _ = Nothing
|
||||||
|
|
||||||
isCommand token str = isCommandMatch token (\cmd -> cmd == str || ('/' : str) `isSuffixOf` cmd)
|
isCommand token str = isCommandMatch token (\cmd -> cmd == str || ('/' : str) `isSuffixOf` cmd)
|
||||||
isUnqualifiedCommand token str = isCommandMatch token (== str)
|
isUnqualifiedCommand token str = isCommandMatch token (== str)
|
||||||
|
|
||||||
|
@ -2256,6 +2263,8 @@ prop_checkFunctionsUsedExternally2 =
|
||||||
verifyTree checkFunctionsUsedExternally "alias f='a'; xargs -n 1 f"
|
verifyTree checkFunctionsUsedExternally "alias f='a'; xargs -n 1 f"
|
||||||
prop_checkFunctionsUsedExternally3 =
|
prop_checkFunctionsUsedExternally3 =
|
||||||
verifyNotTree checkFunctionsUsedExternally "f() { :; }; echo f"
|
verifyNotTree checkFunctionsUsedExternally "f() { :; }; echo f"
|
||||||
|
prop_checkFunctionsUsedExternally4 =
|
||||||
|
verifyNotTree checkFunctionsUsedExternally "foo() { :; }; sudo \"foo\""
|
||||||
checkFunctionsUsedExternally params t =
|
checkFunctionsUsedExternally params t =
|
||||||
runNodeAnalysis checkCommand params t
|
runNodeAnalysis checkCommand params t
|
||||||
where
|
where
|
||||||
|
@ -2284,14 +2293,14 @@ checkFunctionsUsedExternally params t =
|
||||||
let string = concat $ deadSimple arg
|
let string = concat $ deadSimple arg
|
||||||
in when ('=' `elem` string) $
|
in when ('=' `elem` string) $
|
||||||
modify ((takeWhile (/= '=') string, getId arg):)
|
modify ((takeWhile (/= '=') string, getId arg):)
|
||||||
checkArg cmd arg =
|
checkArg cmd arg = potentially $ do
|
||||||
case Map.lookup (concat $ deadSimple arg) functions of
|
literalArg <- getUnquotedLiteral arg -- only consider unquoted literals
|
||||||
Nothing -> return ()
|
definitionId <- Map.lookup literalArg functions
|
||||||
Just id -> do
|
return $ do
|
||||||
warn (getId arg) 2033
|
warn (getId arg) 2033
|
||||||
"Shell functions can't be passed to external commands."
|
"Shell functions can't be passed to external commands."
|
||||||
info id 2032 $
|
info definitionId 2032 $
|
||||||
"Use own script or sh -c '..' to run this from " ++ cmd ++ "."
|
"Use own script or sh -c '..' to run this from " ++ cmd ++ "."
|
||||||
|
|
||||||
prop_checkUnused0 = verifyNotTree checkUnusedAssignments "var=foo; echo $var"
|
prop_checkUnused0 = verifyNotTree checkUnusedAssignments "var=foo; echo $var"
|
||||||
prop_checkUnused1 = verifyTree checkUnusedAssignments "var=foo; echo $bar"
|
prop_checkUnused1 = verifyTree checkUnusedAssignments "var=foo; echo $bar"
|
||||||
|
|
Loading…
Reference in New Issue