Suggest using test -e instead of -a (fixes #3174).

This commit is contained in:
Vidar Holen 2025-04-08 10:23:10 -07:00
parent 72af76f443
commit 574c6d18fb
2 changed files with 11 additions and 0 deletions

View file

@ -204,6 +204,7 @@ nodeChecks = [
,checkUnnecessaryParens
,checkPlusEqualsNumber
,checkExpansionWithRedirection
,checkUnaryTestA
]
optionalChecks = map fst optionalTreeChecks
@ -5098,6 +5099,15 @@ checkExpansionWithRedirection params t =
err redirectId 2328 $ "This redirection takes output away from the command substitution" ++ if suggestTee then " (use tee to duplicate)." else "."
prop_checkUnaryTestA1 = verify checkUnaryTestA "[ -a foo ]"
prop_checkUnaryTestA2 = verify checkUnaryTestA "[ ! -a foo ]"
prop_checkUnaryTestA3 = verifyNot checkUnaryTestA "[ foo -a bar ]"
checkUnaryTestA params t =
case t of
TC_Unary id _ "-a" _ ->
styleWithFix id 2331 "For file existence, prefer standard -e over legacy -a." $
fixWith [replaceStart id params 2 "-e"]
_ -> return ()
return []
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])