Commit Graph

236 Commits

Author SHA1 Message Date
timeless
1af8764a9d check-code: export needs a space to avoid false positives 2016-01-12 15:58:59 +00:00
Matt Mackall
3ace626aa9 check-code: allow only-whitespace lines in tests
These turn out to be necessary to embed diffs with blank lines in test
input. So we now complain about whitespace following a character.
2016-01-08 12:35:02 -06:00
timeless
b863202251 check-code: enforce strict spacing around assignment 2015-12-31 17:41:59 +00:00
timeless
8dd6ee4d9a check-code: improve test-check-code error diffs
Whenever check-code finds something wrong, the diffs it
generated were fairly hard to read.

The problem is that check-code before this change
would list files that were white listed using
no- check- code but without a glob marker.

Whereas, the test-check-code.t expected output has
no-che?k-code (glob) in order to avoid having itself
flagged as a file to skip.

Thus, in addition to any lines relating to things you
did wrong, all of the white-listed files are listed as
changed.

There is no reason for things to be this painful.

This change makes the output from check-code.py match
the expected output in test-check-code.t
2015-12-24 19:32:14 +00:00
Danek Duvall
7653e06efa tests: Solaris diff -U also emits "No differences encountered"
This came up before, but the tests in check-code.py don't find -U (only -u)
and they don't work when the diff is inside a shell function.  This fixes
the offending tests and beefs up check-code.py.
2015-12-27 15:24:48 -08:00
timeless
f10778ca64 check-code: allow argument passing py2.6ism
this backs out dead48a12ce0, because Python2.5 support was dropped
2015-10-15 17:28:26 -04:00
timeless
76f10d8d74 check-code: block non-portable pipe-and 2015-10-15 20:36:12 -04:00
Pierre-Yves David
4b641b8c22 check-code: detect and ban 'util.Abort'
We have seen the light, please use the new way.
2015-10-08 12:53:09 -07:00
Pierre-Yves David
b2cac2b8b4 check-code: forbid mutable value for default argument
default value are common to all call. Using mutable value is a classical source
of bug in Python. We forbid it.

The regexp (Courtesy of Matt Mackall) is only catching such value on the first
line of a definition, but that will be good enough for now.
2015-09-24 00:34:15 -07:00
Gregory Szorc
7a107e3b4a check-code: detect legacy exception syntax
We just rewrote all files to use modern exception syntax. Ban the old
form.

This will detect the "except type, instance" and
"except (type1, type2), instance" forms.
2015-06-23 22:20:01 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Gregory Szorc
82ea02abcf check-code: detect legacy octal syntax
Now that we have mass rewriting all files to use the modern octal
syntax, detect and ban the legacy syntax, which is no longer supported
in Python 3.
2015-06-23 22:38:21 -07:00
Yuya Nishihara
5ddbe8ee34 check-code: ban use of '[[ ]]' in tests 2015-06-16 23:06:30 +09:00
Matt Mackall
2a25c01621 check-code: reintroduce str.format() ban for 3.x porting
In their infinite wisdom, the Python maintainers stripped bytes of its
% and format() methods for 3.x. They've now added % back to 3.5, but
format() is still missing. Since we don't have any particular need for
it, we should keep avoiding it.
2015-05-19 08:41:04 -05:00
Pierre-Yves David
cb4db56d2a check-code: drop ban of 'val if cond else otherval' construct
We now have access to this horrible but less bad than
'cond and val or otherval' syntax.
2015-05-18 16:18:18 -05:00
Pierre-Yves David
624cc99b09 check-code: drop the 'format' built-in
I'm not clear what it is doing, but one who knows what it is about can now make
use of it.
2015-05-18 16:11:44 -05:00
Pierre-Yves David
b59fc6f804 check-code: drop ban of str.format
After discussion with Augie and Matt, we are fine with it being introduced in
the code base.
2015-05-18 16:09:05 -05:00
Pierre-Yves David
d5a6426866 check-code: drop ban of BaseException
Lets go back to the basic. It is available in Python 2.6.
2015-05-18 13:20:19 -05:00
Pierre-Yves David
2d3ab51ced check-code: drop the yield inside try/finally ban
This is now possible with Python 2.6.
2015-05-18 12:56:59 -05:00
Augie Fackler
82d20c6721 check-code: un-ban __builtins__.all now that we're on 2.6 2015-05-16 14:34:04 -04:00
Augie Fackler
8135f8f3bf check-code: un-ban any() now that we're on 2.6 2015-05-16 14:31:03 -04:00
Pierre-Yves David
5c28bef986 check-code: lift the ban on 'next()'
'next' is supported by Python2.6 the new lowest version supported by Mercurial.
2015-05-17 17:47:42 -07:00
Pierre-Yves David
a800edc31c check-code: drop the 'isdisjoint' ban
'isdisjoint' is available in Python 2.6. The new lowest supported version.
2015-05-17 17:45:47 -07:00
Pierre-Yves David
b126ceafed check-code: fix the error message about 'class foo():'
Using 'classs foo():' result in old style object instead of new style object. We
do not want old style object so this check is unrelated to 2.4.
2015-05-17 17:40:26 -07:00
Pierre-Yves David
2e89aa0615 check-code: remove the check for os.path.relpath
This is available in Python2.6 the new default supported release.
2015-05-17 17:36:26 -07:00
Matt Mackall
d4d62e93d0 check-code: drop try/except/finally check 2015-05-15 09:54:35 -05:00
Pierre-Yves David
62621af660 check-code: allow with statements
We dropped python 2.4 compatibility.
2015-05-13 11:49:38 -07:00
Pierre-Yves David
93a4853f4a check-code: allow 'Except EClass as variable:'
Python 2.4 compatibility has been dropped.
2015-05-13 11:41:17 -07:00
Pierre-Yves David
46186d5bf4 check-code: allow print and exec as a function
This is required to move forward on python3 compatibility.
2015-05-13 11:39:48 -07:00
Matt Harbison
904c26befb check-code: drop the python 2.5 warning for os.path.relpath()
There's plenty of other cleanup to do in here, but this specific one is used in
the next patch.
2015-05-11 22:47:01 -04:00
FUJIWARA Katsunori
a87fdf93f3 check-code: check os.path.join(*, '') not working correctly with Python 2.7.9
Since Python 2.7.9, "os.path.join(path, '')" doesn't append "os.sep"
for UNC path (see issue4557 for detail).
2015-04-22 23:38:55 +09:00
Laurent Charignon
76fa3c9194 check-code: in C code, prevent space before closing parenthesis 2015-03-24 12:52:53 -07:00
Matt Harbison
4849cf877e check-code: enforce the usage of 'seq.py' instead of 'seq' 2015-03-17 21:48:34 -04:00
Matt Mackall
37e98d0538 check-code: allow disabling msys path check 2015-03-05 13:21:57 -06:00
FUJIWARA Katsunori
0ef76b45c5 check-code.py: avoid warning against "reverting subrepo ..." lines
Before this patch, "reverting subrepo subrepo/path" lines in *.t test
files require "(glob)", because such lines are recognized as
"reverting path/to/managed/file" by "check-code.py".

On the other hand, "(glob)" for such "reverting ..." line is
recognized as useless by "runt-tests.py", because subrepo paths shown
in such lines are always normalized by "util.pconvert". And this
causes "no result code from test" warning.

As a preparation for discarding "(glob)" from such lines in subsequent
patch, this patch avoids warning against them, by adding negative
lookahead assertion "(?!subrepo )" to the regexp.
2015-01-22 00:10:26 +09:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
Matt Mackall
1dfcf35d21 test-revert.t: fix wc check-code false positive 2014-11-03 11:06:51 -06:00
Yuya Nishihara
6684fe223e check-code: look for misuse of __bool__ 2014-09-17 00:28:37 +09:00
Matt Mackall
2b52e463fe check-code: extend try/except/finally check for multiple except clauses 2014-08-14 16:39:27 -05:00
Pierre-Yves David
4c3d1d5f78 check-code: allow an escape pattern to be specified for testpattern
Before this patch it was impossible to introduce a #no-xxx comment to disable a
test pattern warning.
2014-08-02 17:04:53 -07:00
Pierre-Yves David
1a25f452db check-code: capture "wc" as a word
Otherwise entries such as "wcchange" give false negative
2014-08-02 17:01:55 -07:00
Danek Duvall
151b68d8da tests: cat error messages are different on Solaris 2014-07-21 11:27:24 -07:00
Augie Fackler
e112e0adb8 check-code: drop ban on callable() which was restored in Python 3.2
A followup will restore use of callable() in place of the awkward
hasattr() construction we were using to be one step closer to Python
3.
2014-06-23 09:22:53 -04:00
Steven Brown
b97c015cd5 check-code: check for consistent usage of the websub filter in hgweb templates
The check-code tool now expects the "desc" keyword to be followed by the
"websub" filter, with the following exceptions:
a) It has no filters at all, e.g. a changeset description in the raw style
   templates or the repository description in the summary page.
b) It is followed by the "firstline" filter, e.g. the first line of the
   changeset description is displayed as a summary or title.
2014-05-17 17:11:06 +08:00
Matt Mackall
ff4d16ffda check-code: look at shebang to identify Python scripts 2014-05-05 13:37:59 -05:00
FUJIWARA Katsunori
0ba1f1ddab check-code: detect "% inside _()" when there are leading whitespaces
Before this patch, "contrib/check-code.py" can't detect "% inside _()"
correctly, when there are leading whitespaces before the format
string, like below:

    _(
      "format string %s" % v)

This patch adds regexp pattern "[ \t\n]*" before the pattern matching
against the format string.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.
2014-04-16 03:05:00 +09:00
Matt Mackall
c9eb4517fa merge with stable 2014-04-01 15:11:19 -05:00
FUJIWARA Katsunori
0eed53de6c i18n: fix "% inside _()" problems
Before this patch, "contrib/check-code.py" can't detect these
problems, because the regexp pattern to detect "% inside _()" doesn't
suppose the case that format string consists of multiple string
components concatenated implicitly or explicitly,

This patch does below for that regexp pattern to detect "% inside _()"
problems in such case.

  - put "+" into separator part ("[ \t\n]") for explicit concatenation
    ("...." + "...." style)

  - enclose "component and separator" part by "(?:....)+" for
    concatenation itself ("...." "...." or "...." + "....")
2014-04-01 02:46:03 +09:00
FUJIWARA Katsunori
01d8b27701 i18n: fix "% inside _()" problems
Before this patch, "contrib/check-code.py" can't detect these
problems, because the regexp pattern to detect "% inside _()" doesn't
suppose the case that the format string and "%" aren't placed in the
same line.

This patch replaces "\s" in that regexp pattern with "[ \t\n]" to
detect "% inside _()" problems in such case.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.
2014-04-01 02:46:03 +09:00
Matt Mackall
62ec223373 check-code: check for argument passing py2.6ism 2014-03-19 18:04:03 -05:00