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

@ -3,6 +3,7 @@
- SC2327/SC2328: Warn about capturing the output of redirected commands.
- SC2329: Warn when (non-escaping) functions are never invoked.
- SC2330: Warn about unsupported glob matches with [[ .. ]] in BusyBox.
- SC2331: Suggest using standard -e instead of unary -a in tests.
- Precompiled binaries for Linux riscv64 (linux.riscv64)
### Changed
- SC2002 about Useless Use Of Cat is now disabled by default. It can be

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 }) ) |])