Commit Graph

198 Commits

Author SHA1 Message Date
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
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
Danek Duvall
4a6ebc20e6 solaris: diff -u emits "No differences encountered"
Solaris diff -u isn't silent when two files are identical, and tests that
don't account for that will fail.  Fix those tests, and introduce a check
that prevents reintroduction.
2014-02-19 13:46:49 -08:00
Simon Heimberg
18c74b7667 help: remove last occurrences of ".. note::" without two newlines
When we add two newlines after ".. note::" translators will not see this
entry. And all versions of docutils interpret this paragraph correctly
(details in 89e31d6e438f).
2014-02-19 13:25:28 +01:00
Simon Heimberg
305a187eff tests: lines with largefile .* file://$TESTTMP also match on windows
on windows, largefile paths are written as "file:///C:/temp/...", corresponding
to "file:///$TESTTMP/..." (all three slashes shown).
But on posix systems they are written as "file:///tmp/..." corresponding to
"file://$TESTTMP/..." (only two slashes shown).

Write the glob "file:/*/" to match both versions.
2014-01-27 21:39:25 +01:00
Simon Heimberg
617e52dc43 tests: rewrite path in test-shelve.t for not being mangled on msys
msys (on windows) converets '-R bundle:.XX/XX' to '-R bundle:;.XX/XX'. Avoid
this by writing '-R bundle://.XX/XX'. This is used more often than the
alternative work arounds like '-Rbundle://.XX/XX' or '-R bundle:Y/../.XX/XX'.
2014-02-10 22:56:10 +01:00
Simon Heimberg
c202d2b08f check-code: print debug output when an ignore pattern matches 2014-01-07 22:29:57 +01:00
Simon Heimberg
20f36987da check-code: drop now unused check-code-ignore
Using check-code-ignore to skip the failures on a line has several
disadvantages:
 * It skips all check-code failures on a line, not only the one it was created
   for.
 * It does not give any hint for which rule it was added, making it difficult to
   see when it is not needed anymore.
So drop this pragma in favor of better alternatives promoted before.
2014-01-07 22:29:51 +01:00
Simon Heimberg
2af7eb452d check-code: explain what to do when a check-code rule mismatches
In the past several approaches were used when a check-code rule triggered
without a good reason. Not all of them looked nice, some were even wrong.
Suggest some good practices which should be used instead.
2014-01-07 22:29:44 +01:00
Simon Heimberg
8a4db51de9 check-code: always report when a file is skipped by "no-check-code"
Skipping an entire file generally from checking is an important event, so
report it always.
Do not tell the check name because skipping does not depend on it. Directly
skip the entire file instead of checking more patterns and skip again.

The pragma no-check-code was introduced by accident in the past. (Fixed in
bc3ff9741549 and aa06d5c0d698.) This now is prevented because the files
to skip have to be listed in the test output of test-check-code-hg.t.
2014-01-07 22:29:15 +01:00
Simon Heimberg
cfe498cdf6 check-code: do not skip entire file, skip only one match instead
Skipping of the entire file has been introduced in 4ff3c5cd4ae4.
2014-01-07 22:28:45 +01:00
Simon Heimberg
6295e690d1 check-code: document last ignore regexp
For easier remembering to delete when it is not needed anymore.
2013-11-09 14:50:12 +01:00
Simon Heimberg
a4201b65cf check-code: drop unneeded ignore patterns
The exceptions seem to have disappeared.
2013-11-09 14:49:05 +01:00
Matt Mackall
0ed8797e8c merge with stable 2013-11-16 12:44:28 -05: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
Augie Fackler
e39a8b44a4 Merge with stable. 2013-11-05 13:25:45 -05:00
Simon Heimberg
90fcdb6fe7 check-code: more replacement characters
for finding '.. note::' (even) more exact by using more characters:
replace '.' with 'p' and ':' with 'q'
2013-11-05 09:00:31 +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
Simon Heimberg
7d27400fc9 check-code: prepend warning prefix for repeated warnings only once
When a warning occured several times in one file, "warning: " was prepended
several times:

examplefile.py:3:
 > def a(object):
 warning: this looks wrong
examplefile.py:27:
 > def x(object):
 warning: warning: this looks wrong
2013-11-02 11:25:04 +01:00
Simon Heimberg
bfb1db1bf5 check-code: fix an error message 2013-11-02 11:25:33 +01:00
Mads Kiilerich
a07958f34c check-code: fix no-check-code skip message - obfuscation was too obscure 2013-10-23 23:42:13 +08:00
Mads Kiilerich
a4a7d21498 check-code: check that '>' is used for continued lines
Continued lines do not get the SALT mangling.
2013-10-03 14:50:47 +02:00
Mads Kiilerich
1e900bb145 check-code: check for spaces around = for named parameters 2013-10-03 14:50:47 +02:00
Augie Fackler
1e3892da3b check-code: new rule to forbid imports of a.b on the same line as other imports
This style of import can trip up 2to3 and cause it to produce invalid
files if one of the imports is supposed to be a relative import. This
prevents that behavior, and in the process exposed a lot of silly
import errors related to the email module.
2013-09-20 10:18:09 -04:00
Matt Mackall
c1fcd00695 check-code: add bracket style check 2013-09-18 14:36:19 -05:00
Matt Mackall
b8ff933b09 check-code: check C patterns against .h files 2013-09-17 18:19:04 -05:00
Matt Mackall
5f16d1c838 check-code: make casting style check more precise 2013-09-17 18:13:54 -05:00
Danek Duvall
d0c8a3b9e7 solaris: tests can't use tail -n
Solaris tail doesn't recognize the -n option.  Replace the one use of it
with some inline python code, and add a test case to check-code.py.
2013-08-26 15:20:44 -07:00
Danek Duvall
dd1467f6d7 solaris: test cases can't use grep -a
The -a option to GNU grep isn't available when using Solaris grep.  Replace
the one use of grep -a in the testsuite with some in-line Python that does
the equivalent, and add a check for grep -a in check-code.py.
2013-08-23 14:31:42 -07: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
be961a468d check-code: concatenate "check-code" on compile time
The python compiler concatenates two string constants. Use this instead of
doing it on run time or instruct the user how to do it.
The strings "no-check-code" and "check-code-ignore" has to be specially written
for not skipping some checking of the code of this file.
2013-07-01 06:50:58 +02:00
Simon Heimberg
3fb7bd830f check-code: do not warn on printf \\x or \\[1-9]
When there is a double backslash the following char does not have any special
meaning. So do not warn on this.
Remove the now obsolete no-check-code statement. (It was used wrongly anyway, it
skipped checking the entire file.)
2013-07-01 06:50:58 +02:00
Simon Heimberg
6059e06d0f cleanup: drop unused variables and an unused import 2013-07-01 20:48:56 +02:00
Simon Heimberg
bfbc27c057 check-code: introduce function for using re2 when available
Do it similar as in mercurial.util. For simplicity only support flag
multiline which is the only one used.
2013-06-08 20:20:14 +02:00
Simon Heimberg
11469e2f90 check-code: compile filters when loading 2013-06-08 20:20:14 +02:00
Simon Heimberg
1f8c40a6d5 check-code: compile all patterns on initialisation
They where compiled once for every checked file (when calling finditer).
2013-06-08 20:20:14 +02:00
Simon Heimberg
5fb5cb59f5 check-code: only fix patterns once
The patterns were fixed once for every file. Now only do it once when loading
the file.
2013-06-08 20:20:14 +02:00