mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-10 15:22:58 -07:00
Check if =~ is applied to something that looks like a glob
This commit is contained in:
parent
02efc2e945
commit
0d3dded238
1 changed files with 13 additions and 0 deletions
|
@ -76,6 +76,7 @@ basicChecks = [
|
||||||
,checkForInCat
|
,checkForInCat
|
||||||
,checkFindExec
|
,checkFindExec
|
||||||
,checkValidCondOps
|
,checkValidCondOps
|
||||||
|
,checkGlobbedRegex
|
||||||
]
|
]
|
||||||
treeChecks = [
|
treeChecks = [
|
||||||
checkUnquotedExpansions
|
checkUnquotedExpansions
|
||||||
|
@ -461,6 +462,18 @@ checkQuotedCondRegex (TC_Binary _ _ "=~" _ rhs) =
|
||||||
error id = err id $ "Don't quote rhs of =~, it'll match literally rather than as a regex."
|
error id = err id $ "Don't quote rhs of =~, it'll match literally rather than as a regex."
|
||||||
checkQuotedCondRegex _ = return ()
|
checkQuotedCondRegex _ = return ()
|
||||||
|
|
||||||
|
prop_checkGlobbedRegex1 = verify checkGlobbedRegex "[[ $foo =~ *foo* ]]"
|
||||||
|
prop_checkGlobbedRegex2 = verify checkGlobbedRegex "[[ $foo =~ f* ]]"
|
||||||
|
prop_checkGlobbedRegex2a = verify checkGlobbedRegex "[[ $foo =~ \\#* ]]"
|
||||||
|
prop_checkGlobbedRegex3 = verifyNot checkGlobbedRegex "[[ $foo =~ $foo ]]"
|
||||||
|
prop_checkGlobbedRegex4 = verifyNot checkGlobbedRegex "[[ $foo =~ ^c.* ]]"
|
||||||
|
checkGlobbedRegex (TC_Binary _ DoubleBracket "=~" _ rhs) =
|
||||||
|
case rhs of
|
||||||
|
T_NormalWord id ((T_Glob _ "*"):_) -> warn id $ "=~ is for regex. Use == for globs."
|
||||||
|
T_NormalWord id ([(T_Literal _ [c]), (T_Glob _ "*")]) -> warn id $ "=~ is for regex. Either ^anchor$ this, or treat it as a glob with == ."
|
||||||
|
_ -> return ()
|
||||||
|
checkGlobbedRegex _ = return ()
|
||||||
|
|
||||||
|
|
||||||
prop_checkConstantIfs1 = verify checkConstantIfs "[[ foo != bar ]]"
|
prop_checkConstantIfs1 = verify checkConstantIfs "[[ foo != bar ]]"
|
||||||
prop_checkConstantIfs2 = verify checkConstantIfs "[[ n -le 4 ]]"
|
prop_checkConstantIfs2 = verify checkConstantIfs "[[ n -le 4 ]]"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue