mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-08 09:38:48 +08:00
Warn when redirecting to a literal integer.
This commit is contained in:
@@ -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 }) ) |])
|
||||
|
Reference in New Issue
Block a user