Warn about 'read' without a variable in POSIX sh
Dash throws an error if the read command isn't supplied a variable name.
This commit is contained in:
parent
0786b2bf3c
commit
3342902d9a
|
@ -184,6 +184,10 @@ prop_checkBashisms96 = verifyNot checkBashisms "#!/bin/dash\necho $_"
|
||||||
prop_checkBashisms97 = verify checkBashisms "#!/bin/sh\necho ${var,}"
|
prop_checkBashisms97 = verify checkBashisms "#!/bin/sh\necho ${var,}"
|
||||||
prop_checkBashisms98 = verify checkBashisms "#!/bin/sh\necho ${var^^}"
|
prop_checkBashisms98 = verify checkBashisms "#!/bin/sh\necho ${var^^}"
|
||||||
prop_checkBashisms99 = verify checkBashisms "#!/bin/dash\necho [^f]oo"
|
prop_checkBashisms99 = verify checkBashisms "#!/bin/dash\necho [^f]oo"
|
||||||
|
prop_checkBashisms100 = verify checkBashisms "read -r"
|
||||||
|
prop_checkBashisms101 = verify checkBashisms "read"
|
||||||
|
prop_checkBashisms102 = verifyNot checkBashisms "read -r foo"
|
||||||
|
prop_checkBashisms103 = verifyNot checkBashisms "read foo"
|
||||||
checkBashisms = ForShell [Sh, Dash] $ \t -> do
|
checkBashisms = ForShell [Sh, Dash] $ \t -> do
|
||||||
params <- ask
|
params <- ask
|
||||||
kludge params t
|
kludge params t
|
||||||
|
@ -284,6 +288,13 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
|
||||||
argString = concat $ oversimplify arg
|
argString = concat $ oversimplify arg
|
||||||
flagRegex = mkRegex "^-[eEsn]+$"
|
flagRegex = mkRegex "^-[eEsn]+$"
|
||||||
|
|
||||||
|
bashism t@(T_SimpleCommand _ _ (cmd:args))
|
||||||
|
| t `isCommand` "read" && length (onlyNames args) == 0 =
|
||||||
|
warnMsg (getId cmd) 3061 "read without a variable is"
|
||||||
|
where
|
||||||
|
notFlag arg = head (concat $ oversimplify arg) /= '-'
|
||||||
|
onlyNames = filter (notFlag)
|
||||||
|
|
||||||
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
bashism t@(T_SimpleCommand _ _ (cmd:arg:_))
|
||||||
| getLiteralString cmd == Just "exec" && "-" `isPrefixOf` concat (oversimplify arg) =
|
| getLiteralString cmd == Just "exec" && "-" `isPrefixOf` concat (oversimplify arg) =
|
||||||
warnMsg (getId arg) 3038 "exec flags are"
|
warnMsg (getId arg) 3038 "exec flags are"
|
||||||
|
|
Loading…
Reference in New Issue