mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-05 20:41:35 -07:00
Suggest using test -e instead of -a (fixes #3174).
This commit is contained in:
parent
72af76f443
commit
574c6d18fb
2 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue