Warn when redirecting to a literal integer.
This commit is contained in:
parent
4f9a80db15
commit
4fb1080809
|
@ -161,6 +161,7 @@ nodeChecks = [
|
|||
,checkUnmatchableCases
|
||||
,checkSubshellAsTest
|
||||
,checkSplittingInArrays
|
||||
,checkRedirectionToNumber
|
||||
]
|
||||
|
||||
|
||||
|
@ -2796,5 +2797,16 @@ checkSplittingInArrays params t =
|
|||
else "Prefer mapfile or read -a to split command output (or quote to avoid splitting)."
|
||||
|
||||
|
||||
prop_checkRedirectionToNumber1 = verify checkRedirectionToNumber "( 1 > 2 )"
|
||||
prop_checkRedirectionToNumber2 = verify checkRedirectionToNumber "foo 1>2"
|
||||
prop_checkRedirectionToNumber3 = verifyNot checkRedirectionToNumber "echo foo > '2'"
|
||||
prop_checkRedirectionToNumber4 = verifyNot checkRedirectionToNumber "foo 1>&2"
|
||||
checkRedirectionToNumber _ t = case t of
|
||||
T_IoFile id _ word -> potentially $ do
|
||||
file <- getUnquotedLiteral word
|
||||
guard $ all isDigit file
|
||||
return $ warn id 2210 "This is a file redirection. Was it supposed to be a comparison or fd operation?"
|
||||
_ -> return ()
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Reference in New Issue