check-code: there must also be whitespace between ')' and operator
authorMads Kiilerich <madski@unity3d.com>
Sun, 09 Dec 2012 23:33:16 +0100
changeset 18054 b35e3364f94a
parent 18053 0c2f0048125d
child 18055 e440a2c0d944
check-code: there must also be whitespace between ')' and operator The check pattern only checked for whitespace between keyword and operator. Now it also warns: > x = f(),7 missing whitespace after , > x = f()+7 missing whitespace in expression
contrib/check-code.py
doc/hgmanpage.py
hgext/highlight/highlight.py
hgext/inotify/linux/watcher.py
hgext/mq.py
hgext/win32text.py
mercurial/ignore.py
mercurial/localrepo.py
mercurial/patch.py
mercurial/store.py
mercurial/ui.py
--- a/contrib/check-code.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/contrib/check-code.py	Sun Dec 09 23:33:16 2012 +0100
@@ -133,8 +133,8 @@
     (r'\S;\s*\n', "semicolon"),
     (r'[^_]_\("[^"]+"\s*%', "don't use % inside _()"),
     (r"[^_]_\('[^']+'\s*%", "don't use % inside _()"),
-    (r'\w,\w', "missing whitespace after ,"),
-    (r'\w[+/*\-<>]\w', "missing whitespace in expression"),
+    (r'(\w|\)),\w', "missing whitespace after ,"),
+    (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"),
     (r'^\s+\w+=\w+[^,)\n]$', "missing whitespace in assignment"),
     (r'(\s+)try:\n((?:\n|\1\s.*\n)+?)\1except.*?:\n'
      r'((?:\n|\1\s.*\n)+?)\1finally:', 'no try/except/finally in Python 2.4'),
--- a/doc/hgmanpage.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/doc/hgmanpage.py	Sun Dec 09 23:33:16 2012 +0100
@@ -146,7 +146,7 @@
                 text.extend(cell)
                 if not text[-1].endswith('\n'):
                     text[-1] += '\n'
-                if i < len(row)-1:
+                if i < len(row) - 1:
                     text.append('T}'+self._tab_char+'T{\n')
                 else:
                     text.append('T}\n')
@@ -258,7 +258,7 @@
             # ensure we get a ".TH" as viewers require it.
             self.head.append(self.header())
         # filter body
-        for i in xrange(len(self.body)-1, 0, -1):
+        for i in xrange(len(self.body) - 1, 0, -1):
             # remove superfluous vertical gaps.
             if self.body[i] == '.sp\n':
                 if self.body[i - 1][:4] in ('.BI ','.IP '):
@@ -880,7 +880,7 @@
         self.context[-3] = '.BI' # bold/italic alternate
         if node['delimiter'] != ' ':
             self.body.append('\\fB%s ' % node['delimiter'])
-        elif self.body[len(self.body)-1].endswith('='):
+        elif self.body[len(self.body) - 1].endswith('='):
             # a blank only means no blank in output, just changing font
             self.body.append(' ')
         else:
--- a/hgext/highlight/highlight.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/hgext/highlight/highlight.py	Sun Dec 09 23:33:16 2012 +0100
@@ -50,7 +50,7 @@
     colorized = highlight(text, lexer, formatter)
     # strip wrapping div
     colorized = colorized[:colorized.find('\n</pre>')]
-    colorized = colorized[colorized.find('<pre>')+5:]
+    colorized = colorized[colorized.find('<pre>') + 5:]
     coloriter = (s.encode(encoding.encoding, 'replace')
                  for s in colorized.splitlines())
 
--- a/hgext/inotify/linux/watcher.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/hgext/inotify/linux/watcher.py	Sun Dec 09 23:33:16 2012 +0100
@@ -72,7 +72,7 @@
 
     def __repr__(self):
         r = repr(self.raw)
-        return 'event(path=' + repr(self.path) + ', ' + r[r.find('(')+1:]
+        return 'event(path=' + repr(self.path) + ', ' + r[r.find('(') + 1:]
 
 
 _event_props = {
--- a/hgext/mq.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/hgext/mq.py	Sun Dec 09 23:33:16 2012 +0100
@@ -1147,7 +1147,7 @@
                 return matches[0]
             if self.series and self.applied:
                 if s == 'qtip':
-                    return self.series[self.seriesend(True)-1]
+                    return self.series[self.seriesend(True) - 1]
                 if s == 'qbase':
                     return self.series[0]
             return None
@@ -1626,7 +1626,7 @@
                 # if the patch excludes a modified file, mark that
                 # file with mtime=0 so status can see it.
                 mm = []
-                for i in xrange(len(m)-1, -1, -1):
+                for i in xrange(len(m) - 1, -1, -1):
                     if not matchfn(m[i]):
                         mm.append(m[i])
                         del m[i]
--- a/hgext/win32text.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/hgext/win32text.py	Sun Dec 09 23:33:16 2012 +0100
@@ -121,7 +121,7 @@
     # changegroup that contains an unacceptable commit followed later
     # by a commit that fixes the problem.
     tip = repo['tip']
-    for rev in xrange(len(repo)-1, repo[node].rev()-1, -1):
+    for rev in xrange(len(repo) - 1, repo[node].rev() - 1, -1):
         c = repo[rev]
         for f in c.files():
             if f in seen or f not in tip or f not in c:
--- a/mercurial/ignore.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/mercurial/ignore.py	Sun Dec 09 23:33:16 2012 +0100
@@ -46,7 +46,7 @@
                 pat = line
                 break
             elif line.startswith(s+':'):
-                pat = rels + line[len(s)+1:]
+                pat = rels + line[len(s) + 1:]
                 break
         patterns.append(pat)
 
--- a/mercurial/localrepo.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/mercurial/localrepo.py	Sun Dec 09 23:33:16 2012 +0100
@@ -2655,7 +2655,7 @@
             fp.write(text)
         finally:
             fp.close()
-        return self.pathto(fp.name[len(self.root)+1:])
+        return self.pathto(fp.name[len(self.root) + 1:])
 
 # used to avoid circular references so destructors work
 def aftertrans(files):
--- a/mercurial/patch.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/mercurial/patch.py	Sun Dec 09 23:33:16 2012 +0100
@@ -1007,7 +1007,7 @@
 
             bot = min(fuzz, bot)
             top = min(fuzz, top)
-            return old[top:len(old)-bot], new[top:len(new)-bot], top
+            return old[top:len(old) - bot], new[top:len(new) - bot], top
         return old, new, 0
 
     def fuzzit(self, fuzz, toponly):
--- a/mercurial/store.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/mercurial/store.py	Sun Dec 09 23:33:16 2012 +0100
@@ -76,7 +76,7 @@
     cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
     for x in (range(32) + range(126, 256) + winreserved):
         cmap[chr(x)] = "~%02x" % x
-    for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
+    for x in range(ord("A"), ord("Z") + 1) + [ord(e)]:
         cmap[chr(x)] = e + chr(x).lower()
     dmap = {}
     for k, v in cmap.iteritems():
@@ -128,7 +128,7 @@
     cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
     for x in (range(32) + range(126, 256) + winreserved):
         cmap[chr(x)] = "~%02x" % x
-    for x in range(ord("A"), ord("Z")+1):
+    for x in range(ord("A"), ord("Z") + 1):
         cmap[chr(x)] = chr(x).lower()
     return lambda s: "".join([cmap[c] for c in s])
 
--- a/mercurial/ui.py	Sun Dec 09 23:33:16 2012 +0100
+++ b/mercurial/ui.py	Sun Dec 09 23:33:16 2012 +0100
@@ -613,7 +613,7 @@
         ('&None', 'E&xec', 'Sym&link') Responses are case insensitive.
         If ui is not interactive, the default is returned.
         """
-        resps = [s[s.index('&')+1].lower() for s in choices]
+        resps = [s[s.index('&') + 1].lower() for s in choices]
         while True:
             r = self.prompt(msg, resps[default])
             if r.lower() in resps: