Commit Graph

19 Commits

Author SHA1 Message Date
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
Augie Fackler
ad0fddea79 check-code: disallow use of dict(key=value) construction
{} literals are faster and more consistent across Python 2 and 3.

Whitelisted the one use of dict() that is using a generator expresion.
2014-03-12 13:31:27 -04:00
Simon Heimberg
a4feb953c7 check-code: prepend warning prefix only once, but for each warning
The code adding the prefix is now run once per pattern. It was run once per
file (after the change 17484f4c54fb).
Demonstrate that it is working now by extending the test. Raise two different
warnings, one of them twice.
2013-11-09 10:21:20 +01:00
Simon Heimberg
81c6ecacd6 check-code: check comment for '.. note::' without two newlines
Because string entries are replaced before matching, we must search for
the transformed pattern. But it seems to be quite unique and does not return
false matches. If it will, they can be listed as 3rd arg in pypats.
2013-11-05 09:00:31 +01:00
Augie Fackler
ac76c4f1a9 check-code: add a check for the next() builtin, which was new in 2.6 2013-07-25 10:44:51 -04:00
Simon Heimberg
7ea18de5fd check-code: do not abort on an unreadable file, only report this 2013-07-22 10:04:45 +02:00
Simon Heimberg
83278fd7d4 check-code: automatically preppend "warning: " to all warning messages
Some warnings had "warning: " at the beginning of their message. Now this
is done consistent for all messages.
Especially in test-check-code-hg.t it is an advantage to see warnings at once
because only exceptions to them are tolerated. It is (almost) as obvious as
before a6180647ea.

The prefix will not remain when a warning is changed to a failure. A change
like a91387a37f will not be necessary anymore.
2013-07-16 01:29:14 +02:00
Simon Heimberg
0e27bb618e check-code: do not prepend "warning" to a failure message
The prefix has not been removed when this check changed from a warning to a
failure.
2013-03-09 22:14:46 +01:00
Augie Fackler
6f81622e24 check-code: disallow defunct <> operator
Added a test for that and one other python3 check in
test-check-code.t.
2013-01-01 13:05:22 -06:00
Augie Fackler
a52590ca42 check-code: disallow two-argument form of raise
Using this old form makes any attempt to port to Python 3 harder, and
the new syntax is supported in 2.4 already.
2013-01-01 12:58:21 -06:00
Thomas Arendsen Hein
23c6bfee41 check-code: catch yield inside try/finally (with tests)
This is not allowed in Python 2.4.
2012-09-19 12:29:12 +02:00
Mads Kiilerich
5e3dc3e383 avoid using abbreviations that look like spelling errors 2012-08-27 23:14:27 +02:00
Mads Kiilerich
ef0024b865 check-code: add --nolineno option for hiding line numbers
This makes the output more stable when it is used as a whitelist.
2011-11-11 01:25:47 +01:00
Thomas Arendsen Hein
ca6afcfc64 test-check-code.t: test matching try/except/finally introduced in d7e08f92afab 2011-10-17 14:27:34 +02:00
Matt Mackall
db1431fe95 check-code: support multiline matches like try/except/finally
- match one pattern at a time against entire file
- find line containing match
- sort matches by line number
2011-10-16 20:26:20 -05:00
Thomas Arendsen Hein
4575d54a81 check-code: fix class style checking (with tests)
- old-style classes were only checked for one-letter class names
- add check for new-style classes with empty parent class, because
  this is not available in Python 2.4
2011-06-29 13:45:51 +02:00
Thomas Arendsen Hein
16ae1c2ebb coding style: fix yield used as a function 2010-12-03 12:22:56 +01:00
Adrian Buehlmann
5e2e71ea82 check-code: catch Python 'is' comparing number or string literals
The Python 'is' operator compares object identity, so it should
definitely not be applied to string or number literals, which Python
implementations are free to represent with a temporary object.

This should catch the following kinds of bogus expressions (examples):

  x is 'foo'     x is not 'foo'
  x is "bar"     x is not "bar"
  x is 42        x is not 42
  x is -36       x is not -36

As originally proposed by Martin Geisler, amended with catching
negative numbers.
2010-11-21 11:52:27 +01:00
Brodie Rao
dfaf44c2e4 tests: unify test-check-code 2010-10-08 16:08:46 -05:00