mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-06 13:01:39 -07:00
SC2325/SC2326: Warn about ! ! foo and foo | ! bar (fixes #2810)
This commit is contained in:
parent
9490b94886
commit
dd747b2a98
3 changed files with 43 additions and 7 deletions
|
@ -60,6 +60,8 @@ checks = [
|
|||
,checkBraceExpansionVars
|
||||
,checkMultiDimensionalArrays
|
||||
,checkPS1Assignments
|
||||
,checkMultipleBangs
|
||||
,checkBangAfterPipe
|
||||
]
|
||||
|
||||
testChecker (ForShell _ t) =
|
||||
|
@ -566,5 +568,29 @@ checkPS1Assignments = ForShell [Bash] f
|
|||
escapeRegex = mkRegex "\\\\x1[Bb]|\\\\e|\x1B|\\\\033"
|
||||
|
||||
|
||||
prop_checkMultipleBangs1 = verify checkMultipleBangs "! ! true"
|
||||
prop_checkMultipleBangs2 = verifyNot checkMultipleBangs "! true"
|
||||
checkMultipleBangs = ForShell [Dash, Sh] f
|
||||
where
|
||||
f token = case token of
|
||||
T_Banged id (T_Banged _ _) ->
|
||||
err id 2325 "Multiple ! in front of pipelines are a bash/ksh extension. Use only 0 or 1."
|
||||
_ -> return ()
|
||||
|
||||
|
||||
prop_checkBangAfterPipe1 = verify checkBangAfterPipe "true | ! true"
|
||||
prop_checkBangAfterPipe2 = verifyNot checkBangAfterPipe "true | ( ! true )"
|
||||
prop_checkBangAfterPipe3 = verifyNot checkBangAfterPipe "! ! true | true"
|
||||
checkBangAfterPipe = ForShell [Dash, Sh, Bash] f
|
||||
where
|
||||
f token = case token of
|
||||
T_Pipeline _ _ cmds -> mapM_ check cmds
|
||||
_ -> return ()
|
||||
|
||||
check token = case token of
|
||||
T_Banged id _ ->
|
||||
err id 2326 "! is not allowed in the middle of pipelines. Use command group as in cmd | { ! cmd; } if necessary."
|
||||
_ -> return ()
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue