Patchwork [4,of,6] check-config: look for ui.configwith

login
register
mail settings
Submitter Gregory Szorc
Date June 15, 2017, 6:18 p.m.
Message ID <92d8ae773d851bcf4d6a.1497550694@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21397/
State Accepted
Headers show

Comments

Gregory Szorc - June 15, 2017, 6:18 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1497549516 25200
#      Thu Jun 15 10:58:36 2017 -0700
# Node ID 92d8ae773d851bcf4d6a2e27a97ee1f749aabb99
# Parent  5fc91a88bb357f8ab5a15f57f765156badb1c48f
check-config: look for ui.configwith

We previously weren't looking for this config helper. And, surprise,
profiling.py references config options without docs.

If I tried hard enough, I could have combined the regexps using a
positive lookbehind assertion or something. But I didn't want to make
my brain explode.

At some point, we should probably do this linting at the tokenizer or
ast layer. I'm not willing to open that can of worms right now.

Patch

diff --git a/contrib/check-config.py b/contrib/check-config.py
--- a/contrib/check-config.py
+++ b/contrib/check-config.py
@@ -24,6 +24,16 @@  configre = re.compile(r'''
         (?:default=)?(?P<default>\S+?))?
     \)''', re.VERBOSE | re.MULTILINE)
 
+configwithre = re.compile('''
+    ui\.config(?P<ctype>with)\(
+        # First argument is callback function. This doesn't parse robustly
+        # if it is e.g. a function call.
+        [^,]+,\s*
+        ['"](?P<section>\S+)['"],\s*
+        ['"](?P<option>\S+)['"](,\s+
+        (?:default=)?(?P<default>\S+?))?
+    \)''', re.VERBOSE | re.MULTILINE)
+
 configpartialre = (r"""ui\.config""")
 
 def main(args):
@@ -79,7 +89,7 @@  def main(args):
 
             # look for code-like bits
             line = carryover + l
-            m = configre.search(line)
+            m = configre.search(line) or configwithre.search(line)
             if m:
                 ctype = m.group('ctype')
                 if not ctype:
diff --git a/tests/test-check-config.t b/tests/test-check-config.t
--- a/tests/test-check-config.t
+++ b/tests/test-check-config.t
@@ -33,3 +33,5 @@  New errors are not allowed. Warnings are
 
   $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
   >   python contrib/check-config.py
+  undocumented: profiling.showmax (with) [0.999]
+  undocumented: profiling.showmin (with) [0.005]