mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-21 22:03:45 -07:00
bats: Add check for useless negation (SC2293)
This commit is contained in:
parent
0dd5c67bdf
commit
b0817ca404
1 changed files with 19 additions and 0 deletions
|
@ -199,6 +199,7 @@ nodeChecks = [
|
|||
,checkComparisonWithLeadingX
|
||||
,checkCommandWithTrailingSymbol
|
||||
,checkUnquotedParameterExpansionPattern
|
||||
,checkBatsTestDoesNotUseNegation
|
||||
]
|
||||
|
||||
optionalChecks = map fst optionalTreeChecks
|
||||
|
@ -4847,6 +4848,24 @@ checkExtraMaskedReturns params t = runNodeAnalysis findMaskingNodes params t
|
|||
|
||||
hasParent pred t = any (uncurry pred) (parentChildPairs t)
|
||||
|
||||
prop_checkBatsTestDoesNotUseNegation1 = verifyNot checkBatsTestDoesNotUseNegation "#!/usr/bin/env bats\n@test \"name\"{ ! true; false; }"
|
||||
prop_checkBatsTestDoesNotUseNegation2 = verify checkBatsTestDoesNotUseNegation "#!/usr/bin/env bats\n@test \"name\"{ ! true; }" -- using ! on last command in test is okay
|
||||
prop_checkBatsTestDoesNotUseNegation3 = verify checkBatsTestDoesNotUseNegation "#!/usr/bin/env bats\n@test \"name\"{ run ! true }"
|
||||
checkBatsTestDoesNotUseNegation params t =
|
||||
case t of
|
||||
T_BatsTest _ _ (T_BraceGroup _ commands) -> mapM_ check (dropLast commands)
|
||||
T_Banged id (T_Pipeline _ _ [T_Redirecting _ _ (T_Condition idCondition _ _)]) ->
|
||||
err id 2293
|
||||
"bats: ! <command> will never fail the test. Fold the `!` into the conditional!"
|
||||
T_Banged id cmd -> errWithFix id 2293
|
||||
"bats: ! <command> will never fail the test."
|
||||
(fixWith [replaceStart id params 0 "run "])
|
||||
_ -> return ()
|
||||
dropLast t =
|
||||
case t of
|
||||
[_] -> []
|
||||
x:rest -> x : dropLast rest
|
||||
_ -> []
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue