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
parent 6dcf4b8e64
commit 112a7d8b9b
1 changed files with 15 additions and 9 deletions

View File

@ -152,6 +152,10 @@ prop_checkBashisms69 = verifyNot checkBashisms "#!/bin/sh\numask -S"
prop_checkBashisms70 = verify checkBashisms "#!/bin/sh\ntrap -l"
prop_checkBashisms71 = verify checkBashisms "#!/bin/sh\ntype -a ls"
prop_checkBashisms72 = verifyNot checkBashisms "#!/bin/sh\ntype ls"
prop_checkBashisms73 = verifyNot checkBashisms "#!/bin/sh\necho \"-n foo\""
prop_checkBashisms74 = verifyNot checkBashisms "#!/bin/sh\necho \"-ne foo\""
prop_checkBashisms75 = verifyNot checkBashisms "#!/bin/sh\necho -Q foo"
prop_checkBashisms76 = verify checkBashisms "#!/bin/sh\necho -ne foo"
checkBashisms = ForShell [Sh, Dash] $ \t -> do
params <- ask
kludge params t
@ -238,15 +242,17 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
warnMsg id "`<file` to read files is"
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
| t `isCommand` "echo" && "-" `isPrefixOf` argString =
unless ("--" `isPrefixOf` argString) $ -- echo "-----"
| t `isCommand` "echo" && argString `matches` flagRegex =
if isDash
then
when (argString /= "-n") $
warnMsg (getId arg) "echo flags besides -n"
else
warnMsg (getId arg) "echo flags are"
where argString = concat $ oversimplify arg
where
argString = concat $ oversimplify arg
flagRegex = mkRegex "^-[eEsn]+$"
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
| t `isCommand` "exec" && "-" `isPrefixOf` concat (oversimplify arg) =
warnMsg (getId arg) "exec flags are"