Skip to content

Commit 499c993

Browse files
committed
Rewrite SC2032 warning and mention line number (fixes koalaman#2353)
1 parent d9a9d5d commit 499c993

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/ShellCheck/Analytics.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ checkFunctionsUsedExternally params t =
22972297
let args = skipOver t argv
22982298
let argStrings = map (\x -> (fromMaybe "" $ getLiteralString x, x)) args
22992299
let candidates = getPotentialCommands name argStrings
2300-
mapM_ (checkArg name) candidates
2300+
mapM_ (checkArg name (getId t)) candidates
23012301
_ -> return ()
23022302
checkCommand _ _ = return ()
23032303

@@ -2323,14 +2323,19 @@ checkFunctionsUsedExternally params t =
23232323

23242324
functionsAndAliases = Map.union (functions t) (aliases t)
23252325

2326-
checkArg cmd (_, arg) = sequence_ $ do
2326+
patternContext id =
2327+
case posLine . fst <$> Map.lookup id (tokenPositions params) of
2328+
Just l -> " on line " <> show l <> "."
2329+
_ -> "."
2330+
2331+
checkArg cmd cmdId (_, arg) = sequence_ $ do
23272332
literalArg <- getUnquotedLiteral arg -- only consider unquoted literals
23282333
definitionId <- Map.lookup literalArg functionsAndAliases
23292334
return $ do
23302335
warn (getId arg) 2033
2331-
"Shell functions can't be passed to external commands."
2336+
"Shell functions can't be passed to external commands. Use separate script or sh -c."
23322337
info definitionId 2032 $
2333-
"Use own script or sh -c '..' to run this from " ++ cmd ++ "."
2338+
"This function can't be invoked via " ++ cmd ++ patternContext cmdId
23342339

23352340
prop_checkUnused0 = verifyNotTree checkUnusedAssignments "var=foo; echo $var"
23362341
prop_checkUnused1 = verifyTree checkUnusedAssignments "var=foo; echo $bar"

0 commit comments

Comments
 (0)