Suggest -z/-n instead of ! -n/-z (fixes #1326).

This commit is contained in:
Vidar Holen 2018-08-28 20:15:54 -07:00
parent 488d6dcb41
commit 3d03b0ab3b
2 changed files with 23 additions and 0 deletions

View File

@ -1,6 +1,7 @@
## ??? ## ???
### Added ### Added
- Command line option --severity/-S for filtering by minimum severity - Command line option --severity/-S for filtering by minimum severity
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
### Changed ### Changed
- Most warnings now have useful end positions - Most warnings now have useful end positions
- SC1117 about unknown double-quoted escape sequences has been retired - SC1117 about unknown double-quoted escape sequences has been retired

View File

@ -168,6 +168,7 @@ nodeChecks = [
,checkPipeToNowhere ,checkPipeToNowhere
,checkForLoopGlobVariables ,checkForLoopGlobVariables
,checkSubshelledTests ,checkSubshelledTests
,checkInvertedStringTest
] ]
@ -3004,5 +3005,26 @@ checkSubshelledTests params t =
T_Annotation {} -> True T_Annotation {} -> True
_ -> False _ -> 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 [] return []
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |]) runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])