Issue 1330 unsupported echo flags

Issue https://github.com/koalaman/shellcheck/issues/1330

Addresses false positives when quoted arguments to echo begin with what
looks like a flag. Now, warn only when the first argument is a
recognized echo flag when flags are unsupported.
This commit is contained in:
Gandalf- 2019-01-11 10:17:44 -08:00
commit ecb7bbe0ea

View file

@ -145,6 +145,7 @@ prop_checkBashisms62 = verify checkBashisms "#!/bin/sh\nexport -f foo"
prop_checkBashisms63 = verifyNot checkBashisms "#!/bin/sh\nexport -p" prop_checkBashisms63 = verifyNot checkBashisms "#!/bin/sh\nexport -p"
prop_checkBashisms64 = verify checkBashisms "#!/bin/sh\nreadonly -a" prop_checkBashisms64 = verify checkBashisms "#!/bin/sh\nreadonly -a"
prop_checkBashisms65 = verifyNot checkBashisms "#!/bin/sh\nreadonly -p" prop_checkBashisms65 = verifyNot checkBashisms "#!/bin/sh\nreadonly -p"
prop_checkBashisms66 = verifyNot checkBashisms "#!/bin/sh\necho \"-n foo\""
checkBashisms = ForShell [Sh, Dash] $ \t -> do checkBashisms = ForShell [Sh, Dash] $ \t -> do
params <- ask params <- ask
kludge params t kludge params t
@ -231,7 +232,7 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
warnMsg id "`<file` to read files is" warnMsg id "`<file` to read files is"
bashism t@(T_SimpleCommand _ _ (cmd:arg:_)) bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
| t `isCommand` "echo" && "-" `isPrefixOf` argString = | t `isCommand` "echo" && elem argString echoFlags =
unless ("--" `isPrefixOf` argString) $ -- echo "-----" unless ("--" `isPrefixOf` argString) $ -- echo "-----"
if isDash if isDash
then then
@ -239,7 +240,9 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
warnMsg (getId arg) "echo flags besides -n" warnMsg (getId arg) "echo flags besides -n"
else else
warnMsg (getId arg) "echo flags are" warnMsg (getId arg) "echo flags are"
where argString = concat $ oversimplify arg where
argString = concat $ oversimplify arg
echoFlags = ["-e", "-E", "-s", "-n"]
bashism t@(T_SimpleCommand _ _ (cmd:arg:_)) bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
| t `isCommand` "exec" && "-" `isPrefixOf` concat (oversimplify arg) = | t `isCommand` "exec" && "-" `isPrefixOf` concat (oversimplify arg) =
warnMsg (getId arg) "exec flags are" warnMsg (getId arg) "exec flags are"