mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-06 21:11:35 -07:00
Suggest -z/-n instead of ! -n/-z (fixes #1326).
This commit is contained in:
parent
488d6dcb41
commit
3d03b0ab3b
2 changed files with 23 additions and 0 deletions
|
@ -168,6 +168,7 @@ nodeChecks = [
|
|||
,checkPipeToNowhere
|
||||
,checkForLoopGlobVariables
|
||||
,checkSubshelledTests
|
||||
,checkInvertedStringTest
|
||||
]
|
||||
|
||||
|
||||
|
@ -3004,5 +3005,26 @@ checkSubshelledTests params t =
|
|||
T_Annotation {} -> True
|
||||
_ -> False
|
||||
|
||||
prop_checkInvertedStringTest1 = verify checkInvertedStringTest "[ ! -z $var ]"
|
||||
prop_checkInvertedStringTest2 = verify checkInvertedStringTest "! [[ -n $var ]]"
|
||||
prop_checkInvertedStringTest3 = verifyNot checkInvertedStringTest "! [ -x $var ]"
|
||||
prop_checkInvertedStringTest4 = verifyNot checkInvertedStringTest "[[ ! -w $var ]]"
|
||||
prop_checkInvertedStringTest5 = verifyNot checkInvertedStringTest "[ -z $var ]"
|
||||
checkInvertedStringTest _ t =
|
||||
case t of
|
||||
TC_Unary _ _ "!" (TC_Unary _ _ op _) ->
|
||||
case op of
|
||||
"-n" -> style (getId t) 2236 "Use -z instead of ! -n."
|
||||
"-z" -> style (getId t) 2236 "Use -n instead of ! -z."
|
||||
_ -> return ()
|
||||
T_Banged _ (T_Pipeline _ _
|
||||
[T_Redirecting _ _ (T_Condition _ _ (TC_Unary _ _ op _))]) ->
|
||||
case op of
|
||||
"-n" -> style (getId t) 2237 "Use [ -z .. ] instead of ! [ -n .. ]."
|
||||
"-z" -> style (getId t) 2237 "Use [ -n .. ] instead of ! [ -z .. ]."
|
||||
_ -> return ()
|
||||
_ -> return ()
|
||||
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue