# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1512747555 -32400
#      Sat Dec 09 00:39:15 2017 +0900
# Node ID ef030121dac2ff448db7d9bf667419b6249717c6
# Parent  dd85117b9bcace7416d51e7d59b492d00b4e44c7
check-code: allow tabs in heredoc

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -135,7 +135,6 @@ testpats = [
     (r'if\s*!', "don't use '!' to negate exit status"),
     (r'/dev/u?random', "don't use entropy, use /dev/zero"),
     (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"),
-    (r'^( *)\t', "don't use tabs to indent"),
     (r'sed (-e )?\'(\d+|/[^/]*/)i(?!\\\n)',
      "put a backslash-escaped newline after sed 'i' command"),
     (r'^diff *-\w*[uU].*$\n(^  \$ |^$)', "prefix diff -u/-U with cmp"),
@@ -225,6 +224,7 @@ utestpats = [
   ]
 ]
 
+# transform plain test rules to unified test's
 for i in [0, 1]:
     for tp in testpats[i]:
         p = tp[0]
@@ -235,6 +235,11 @@ for i in [0, 1]:
             p = r"^  [$>] .*(%s)" % p
         utestpats[i].append((p, m) + tp[2:])
 
+# don't transform the following rules:
+# "  > \t" and "  \t" should be allowed in unified tests
+testpats[0].append((r'^( *)\t', "don't use tabs to indent"))
+utestpats[0].append((r'^( ?)\t', "don't use tabs to indent"))
+
 utestfilters = [
     (r"<<(\S+)((.|\n)*?\n  > \1)", rephere),
     (r"( +)(#([^!][^\n]*\S)?)", repcomment),
diff --git a/tests/test-contrib-check-code.t b/tests/test-contrib-check-code.t
--- a/tests/test-contrib-check-code.t
+++ b/tests/test-contrib-check-code.t
@@ -173,6 +173,17 @@
    don't use old-style two-argument raise, use Exception(message)
   [1]
 
+  $ cat <<EOF > tab.t
+  >    indent
+  >   >        heredoc
+  > EOF
+  $ "$check_code" tab.t
+  tab.t:1:
+   >   indent
+   don't use tabs to indent
+  [1]
+  $ rm tab.t
+
   $ cat > rst.py <<EOF
   > """problematic rst text
   > 
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to