##// END OF EJS Templates
check-code: detect "missing _() in ui message" more exactly...
FUJIWARA Katsunori -
r29397:844f7288 default
parent child Browse files
Show More
@@ -329,7 +329,20 b' pypats = ['
329 329 # rules depending on implementation of repquote()
330 330 (r' x+[xpqo%APM][\'"]\n\s+[\'"]x',
331 331 'string join across lines with no space'),
332 (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
332 (r'''(?x)ui\.(status|progress|write|note|warn)\(
333 [ \t\n#]*
334 (?# any strings/comments might precede a string, which
335 # contains translatable message)
336 ((['"]|\'\'\'|""")[ \npq%bAPMxno]*(['"]|\'\'\'|""")[ \t\n#]+)*
337 (?# sequence consisting of below might precede translatable message
338 # - formatting string: "% 10s", "%05d", "% -3.2f", "%*s", "%%" ...
339 # - escaped character: "\\", "\n", "\0" ...
340 # - character other than '%', 'b' as '\', and 'x' as alphabet)
341 (['"]|\'\'\'|""")
342 ((%([ n]?[PM]?([np]+|A))?x)|%%|b[bnx]|[ \nnpqAPMo])*x
343 (?# this regexp can't use [^...] style,
344 # because _preparepats forcibly adds "\n" into [^...],
345 # even though this regexp wants match it against "\n")''',
333 346 "missing _() in ui message (use () to hide false-positives)"),
334 347 ],
335 348 # warnings
@@ -52,7 +52,7 b' def debugshell(ui, repo, **opts):'
52 52 with demandimport.deactivated():
53 53 __import__(pdbmap[debugger])
54 54 except ImportError:
55 ui.warn("%s debugger specified but %s module was not found\n"
55 ui.warn(("%s debugger specified but %s module was not found\n")
56 56 % (debugger, pdbmap[debugger]))
57 57 debugger = 'pdb'
58 58
@@ -117,11 +117,11 b' def showdoc(ui):'
117 117 ui.write(_("This section contains help for extensions that are "
118 118 "distributed together with Mercurial. Help for other "
119 119 "extensions is available in the help system."))
120 ui.write("\n\n"
120 ui.write(("\n\n"
121 121 ".. contents::\n"
122 122 " :class: htmlonly\n"
123 123 " :local:\n"
124 " :depth: 1\n\n")
124 " :depth: 1\n\n"))
125 125
126 126 for extensionname in sorted(allextensionnames()):
127 127 mod = extensions.load(ui, extensionname, None)
@@ -81,13 +81,13 b' def difftree(ui, repo, node1=None, node2'
81 81
82 82 for f in modified:
83 83 # TODO get file permissions
84 ui.write(":100664 100664 %s %s M\t%s\t%s\n" %
84 ui.write((":100664 100664 %s %s M\t%s\t%s\n") %
85 85 (short(mmap[f]), short(mmap2[f]), f, f))
86 86 for f in added:
87 ui.write(":000000 100664 %s %s N\t%s\t%s\n" %
87 ui.write((":000000 100664 %s %s N\t%s\t%s\n") %
88 88 (empty, short(mmap2[f]), f, f))
89 89 for f in removed:
90 ui.write(":100664 000000 %s %s D\t%s\t%s\n" %
90 ui.write((":100664 000000 %s %s D\t%s\t%s\n") %
91 91 (short(mmap[f]), empty, f, f))
92 92 ##
93 93
@@ -455,7 +455,7 b' def demo(ui, repo, *args, **opts):'
455 455
456 456 uisetup(ui)
457 457 reposetup(ui, repo)
458 ui.write('[extensions]\nkeyword =\n')
458 ui.write(('[extensions]\nkeyword =\n'))
459 459 demoitems('keyword', ui.configitems('keyword'))
460 460 demoitems('keywordset', ui.configitems('keywordset'))
461 461 demoitems('keywordmaps', kwmaps.iteritems())
@@ -192,5 +192,5 b' def extsetup(ui):'
192 192 # command line options is not yet applied when
193 193 # extensions.loadall() is called.
194 194 if '--debug' in sys.argv:
195 ui.write("[win32mbcs] activated with encoding: %s\n"
195 ui.write(("[win32mbcs] activated with encoding: %s\n")
196 196 % _encoding)
@@ -1405,24 +1405,24 b' class jsonchangeset(changeset_printer):'
1405 1405 self.ui.write(",\n {")
1406 1406
1407 1407 if self.ui.quiet:
1408 self.ui.write('\n "rev": %s' % jrev)
1409 self.ui.write(',\n "node": %s' % jnode)
1408 self.ui.write(('\n "rev": %s') % jrev)
1409 self.ui.write((',\n "node": %s') % jnode)
1410 1410 self.ui.write('\n }')
1411 1411 return
1412 1412
1413 self.ui.write('\n "rev": %s' % jrev)
1414 self.ui.write(',\n "node": %s' % jnode)
1415 self.ui.write(',\n "branch": "%s"' % j(ctx.branch()))
1416 self.ui.write(',\n "phase": "%s"' % ctx.phasestr())
1417 self.ui.write(',\n "user": "%s"' % j(ctx.user()))
1418 self.ui.write(',\n "date": [%d, %d]' % ctx.date())
1419 self.ui.write(',\n "desc": "%s"' % j(ctx.description()))
1420
1421 self.ui.write(',\n "bookmarks": [%s]' %
1413 self.ui.write(('\n "rev": %s') % jrev)
1414 self.ui.write((',\n "node": %s') % jnode)
1415 self.ui.write((',\n "branch": "%s"') % j(ctx.branch()))
1416 self.ui.write((',\n "phase": "%s"') % ctx.phasestr())
1417 self.ui.write((',\n "user": "%s"') % j(ctx.user()))
1418 self.ui.write((',\n "date": [%d, %d]') % ctx.date())
1419 self.ui.write((',\n "desc": "%s"') % j(ctx.description()))
1420
1421 self.ui.write((',\n "bookmarks": [%s]') %
1422 1422 ", ".join('"%s"' % j(b) for b in ctx.bookmarks()))
1423 self.ui.write(',\n "tags": [%s]' %
1423 self.ui.write((',\n "tags": [%s]') %
1424 1424 ", ".join('"%s"' % j(t) for t in ctx.tags()))
1425 self.ui.write(',\n "parents": [%s]' %
1425 self.ui.write((',\n "parents": [%s]') %
1426 1426 ", ".join('"%s"' % c.hex() for c in ctx.parents()))
1427 1427
1428 1428 if self.ui.debugflag:
@@ -1430,26 +1430,26 b' class jsonchangeset(changeset_printer):'
1430 1430 jmanifestnode = 'null'
1431 1431 else:
1432 1432 jmanifestnode = '"%s"' % hex(ctx.manifestnode())
1433 self.ui.write(',\n "manifest": %s' % jmanifestnode)
1434
1435 self.ui.write(',\n "extra": {%s}' %
1433 self.ui.write((',\n "manifest": %s') % jmanifestnode)
1434
1435 self.ui.write((',\n "extra": {%s}') %
1436 1436 ", ".join('"%s": "%s"' % (j(k), j(v))
1437 1437 for k, v in ctx.extra().items()))
1438 1438
1439 1439 files = ctx.p1().status(ctx)
1440 self.ui.write(',\n "modified": [%s]' %
1440 self.ui.write((',\n "modified": [%s]') %
1441 1441 ", ".join('"%s"' % j(f) for f in files[0]))
1442 self.ui.write(',\n "added": [%s]' %
1442 self.ui.write((',\n "added": [%s]') %
1443 1443 ", ".join('"%s"' % j(f) for f in files[1]))
1444 self.ui.write(',\n "removed": [%s]' %
1444 self.ui.write((',\n "removed": [%s]') %
1445 1445 ", ".join('"%s"' % j(f) for f in files[2]))
1446 1446
1447 1447 elif self.ui.verbose:
1448 self.ui.write(',\n "files": [%s]' %
1448 self.ui.write((',\n "files": [%s]') %
1449 1449 ", ".join('"%s"' % j(f) for f in ctx.files()))
1450 1450
1451 1451 if copies:
1452 self.ui.write(',\n "copies": {%s}' %
1452 self.ui.write((',\n "copies": {%s}') %
1453 1453 ", ".join('"%s": "%s"' % (j(k), j(v))
1454 1454 for k, v in copies))
1455 1455
@@ -1463,12 +1463,13 b' class jsonchangeset(changeset_printer):'
1463 1463 self.ui.pushbuffer()
1464 1464 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
1465 1465 match=matchfn, stat=True)
1466 self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer()))
1466 self.ui.write((',\n "diffstat": "%s"')
1467 % j(self.ui.popbuffer()))
1467 1468 if diff:
1468 1469 self.ui.pushbuffer()
1469 1470 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
1470 1471 match=matchfn, stat=False)
1471 self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer()))
1472 self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer()))
1472 1473
1473 1474 self.ui.write("\n }")
1474 1475
@@ -2095,7 +2095,7 b' def debugbundle(ui, bundlepath, all=None'
2095 2095 def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
2096 2096 indent_string = ' ' * indent
2097 2097 if all:
2098 ui.write("%sformat: id, p1, p2, cset, delta base, len(delta)\n"
2098 ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n")
2099 2099 % indent_string)
2100 2100
2101 2101 def showchunks(named):
@@ -2562,12 +2562,12 b' def debugindex(ui, repo, file_=None, **o'
2562 2562 break
2563 2563
2564 2564 if format == 0:
2565 ui.write(" rev offset length " + basehdr + " linkrev"
2566 " %s %s p2\n" % ("nodeid".ljust(idlen), "p1".ljust(idlen)))
2565 ui.write((" rev offset length " + basehdr + " linkrev"
2566 " %s %s p2\n") % ("nodeid".ljust(idlen), "p1".ljust(idlen)))
2567 2567 elif format == 1:
2568 ui.write(" rev flag offset length"
2568 ui.write((" rev flag offset length"
2569 2569 " size " + basehdr + " link p1 p2"
2570 " %s\n" % "nodeid".rjust(idlen))
2570 " %s\n") % "nodeid".rjust(idlen))
2571 2571
2572 2572 for i in r:
2573 2573 node = r.node(i)
@@ -3030,13 +3030,13 b' def debuglocks(ui, repo, **opts):'
3030 3030 else:
3031 3031 locker = 'user %s, process %s, host %s' \
3032 3032 % (user, pid, host)
3033 ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age))
3033 ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age))
3034 3034 return 1
3035 3035 except OSError as e:
3036 3036 if e.errno != errno.ENOENT:
3037 3037 raise
3038 3038
3039 ui.write("%-6s free\n" % (name + ":"))
3039 ui.write(("%-6s free\n") % (name + ":"))
3040 3040 return 0
3041 3041
3042 3042 held += report(repo.svfs, "lock", repo.lock)
@@ -3329,8 +3329,8 b' def debugrevlog(ui, repo, file_=None, **'
3329 3329
3330 3330 if opts.get("dump"):
3331 3331 numrevs = len(r)
3332 ui.write("# rev p1rev p2rev start end deltastart base p1 p2"
3333 " rawsize totalsize compression heads chainlen\n")
3332 ui.write(("# rev p1rev p2rev start end deltastart base p1 p2"
3333 " rawsize totalsize compression heads chainlen\n"))
3334 3334 ts = 0
3335 3335 heads = set()
3336 3336
@@ -3519,18 +3519,19 b' def debugrevspec(ui, repo, expr, **opts)'
3519 3519 ui.note(revset.prettyformat(tree), "\n")
3520 3520 newtree = revset.expandaliases(ui, tree)
3521 3521 if newtree != tree:
3522 ui.note("* expanded:\n", revset.prettyformat(newtree), "\n")
3522 ui.note(("* expanded:\n"), revset.prettyformat(newtree), "\n")
3523 3523 tree = newtree
3524 3524 newtree = revset.foldconcat(tree)
3525 3525 if newtree != tree:
3526 ui.note("* concatenated:\n", revset.prettyformat(newtree), "\n")
3526 ui.note(("* concatenated:\n"), revset.prettyformat(newtree), "\n")
3527 3527 if opts["optimize"]:
3528 3528 optimizedtree = revset.optimize(newtree)
3529 ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n")
3529 ui.note(("* optimized:\n"),
3530 revset.prettyformat(optimizedtree), "\n")
3530 3531 func = revset.match(ui, expr, repo)
3531 3532 revs = func(repo)
3532 3533 if ui.verbose:
3533 ui.note("* set:\n", revset.prettyformatset(revs), "\n")
3534 ui.note(("* set:\n"), revset.prettyformatset(revs), "\n")
3534 3535 for c in revs:
3535 3536 ui.write("%s\n" % c)
3536 3537
@@ -3685,7 +3686,7 b' def debugtemplate(ui, repo, tmpl, **opts'
3685 3686 ui.note(templater.prettyformat(tree), '\n')
3686 3687 newtree = templater.expandaliases(tree, aliases)
3687 3688 if newtree != tree:
3688 ui.note("* expanded:\n", templater.prettyformat(newtree), '\n')
3689 ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n')
3689 3690
3690 3691 mapfile = None
3691 3692 if revs is None:
@@ -262,6 +262,20 b' web templates'
262 262 > 'bar foo-'
263 263 > 'bar')
264 264 > EOF
265
266 'missing _() in ui message' detection
267
268 $ cat > uigettext.py <<EOF
269 > ui.status("% 10s %05d % -3.2f %*s %%"
270 > # this use '\\\\' instead of '\\', because the latter in
271 > # heredoc on shell becomes just '\'
272 > '\\\\ \n \t \0'
273 > """12345
274 > """
275 > '''.:*+-=
276 > ''' "%-6d \n 123456 .:*+-= foobar")
277 > EOF
278
265 279 $ "$check_code" stringjoin.py
266 280 stringjoin.py:1:
267 281 > foo = (' foo'
@@ -288,3 +302,9 b' web templates'
288 302 > 'bar foo-'
289 303 string join across lines with no space
290 304 [1]
305
306 $ "$check_code" uigettext.py
307 uigettext.py:1:
308 > ui.status("% 10s %05d % -3.2f %*s %%"
309 missing _() in ui message (use () to hide false-positives)
310 [1]
General Comments 0
You need to be logged in to leave comments. Login now