mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-09-22 03:45:41 +08:00
Warn about non-posix %q and flags for printf.
This commit is contained in:
@@ -584,6 +584,8 @@ prop_checkBashisms26= verify checkBashisms "trap mything ERR SIGTERM"
|
|||||||
prop_checkBashisms27= verify checkBashisms "echo *[^0-9]*"
|
prop_checkBashisms27= verify checkBashisms "echo *[^0-9]*"
|
||||||
prop_checkBashisms28= verify checkBashisms "exec {n}>&2"
|
prop_checkBashisms28= verify checkBashisms "exec {n}>&2"
|
||||||
prop_checkBashisms29= verify checkBashisms "echo ${!var}"
|
prop_checkBashisms29= verify checkBashisms "echo ${!var}"
|
||||||
|
prop_checkBashisms30= verify checkBashisms "printf -v '%s' \"$1\""
|
||||||
|
prop_checkBashisms31= verify checkBashisms "printf '%q' \"$1\""
|
||||||
checkBashisms _ = bashism
|
checkBashisms _ = bashism
|
||||||
where
|
where
|
||||||
errMsg id s = err id 2040 $ "In sh, " ++ s ++ " not supported, even when sh is actually bash."
|
errMsg id s = err id 2040 $ "In sh, " ++ s ++ " not supported, even when sh is actually bash."
|
||||||
@@ -671,6 +673,12 @@ checkBashisms _ = bashism
|
|||||||
return $ warnMsg (getId token) $ "trapping " ++ word ++ " is"
|
return $ warnMsg (getId token) $ "trapping " ++ word ++ " is"
|
||||||
in
|
in
|
||||||
mapM_ check (reverse rest)
|
mapM_ check (reverse rest)
|
||||||
|
|
||||||
|
when (name == "printf") $ potentially $ do
|
||||||
|
format <- rest !!! 0 -- flags are covered by allowedFlags
|
||||||
|
let literal = onlyLiteralString format
|
||||||
|
guard $ "%q" `isInfixOf` literal
|
||||||
|
return $ warnMsg (getId format) "printf %q is"
|
||||||
where
|
where
|
||||||
bashCommands = [
|
bashCommands = [
|
||||||
"let", "caller", "builtin", "complete", "compgen", "declare", "dirs", "disown",
|
"let", "caller", "builtin", "complete", "compgen", "declare", "dirs", "disown",
|
||||||
@@ -681,6 +689,7 @@ checkBashisms _ = bashism
|
|||||||
("read", ["r"]),
|
("read", ["r"]),
|
||||||
("ulimit", ["f"]),
|
("ulimit", ["f"]),
|
||||||
("echo", []),
|
("echo", []),
|
||||||
|
("printf", []),
|
||||||
("exec", [])
|
("exec", [])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user