From 3b1ec7f84eb37d532406f9823605a3f14ce9106b Mon Sep 17 00:00:00 2001
From: Vidar Holen <spam@vidarholen.net>
Date: Wed, 28 Nov 2012 00:16:08 -0800
Subject: [PATCH] Check for [[ $foo =~ '.*' ]]

---
 ShellCheck/Analytics.hs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs
index ea0d2be..0074f37 100644
--- a/ShellCheck/Analytics.hs
+++ b/ShellCheck/Analytics.hs
@@ -71,6 +71,7 @@ basicChecks = [
     ,checkGrepRe
     ,checkDollarArithmeticCommand
     ,checkExpr
+    ,checkQuotedCondRegex 
     ]
 
 modifyMap = modify
@@ -347,6 +348,19 @@ checkNumberComparisons (TC_Binary id typ op lhs rhs)
         eqv _ = "the numerical equivalent"
 checkNumberComparisons _ = return ()
 
+prop_checkQuotedCondRegex1 = verify checkQuotedCondRegex "[[ $foo =~ \"bar\" ]]"
+prop_checkQuotedCondRegex2 = verify checkQuotedCondRegex "[[ $foo =~ 'cow' ]]"
+prop_checkQuotedCondRegex3 = verifyNot checkQuotedCondRegex "[[ $foo =~ $foo ]]"
+checkQuotedCondRegex (TC_Binary _ _ "=~" _ rhs) = 
+    case rhs of 
+        T_NormalWord id [T_DoubleQuoted _ _] -> error id
+        T_NormalWord id [T_SingleQuoted _ _] -> error id
+        _ -> return ()
+  where
+    error id = err id $ "Don't quote rhs of =~, it'll match literally rather than as a regex."
+checkQuotedCondRegex _ = return ()
+
+
 prop_checkConstantIfs1 = verify checkConstantIfs "[[ foo != bar ]]"
 prop_checkConstantIfs2 = verify checkConstantIfs "[[ n -le 4 ]]"
 prop_checkConstantIfs3 = verify checkConstantIfs "[[ $n -le 4 && n -ge 2 ]]"