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

Gregory Szorc gregory.szorc at gmail.com
Thu Jun 15 14:18:14 EDT 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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.

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]


More information about the Mercurial-devel mailing list