diff -r 57875cf423c9 -r 2372284d9457 contrib/check-code.py --- a/contrib/check-code.py Sat Oct 05 10:29:34 2019 -0400 +++ b/contrib/check-code.py Sun Oct 06 09:45:02 2019 -0400 @@ -26,11 +26,15 @@ import os import re import sys + if sys.version_info[0] < 3: opentext = open else: + def opentext(f): return open(f, encoding='latin1') + + try: xrange except NameError: @@ -42,6 +46,7 @@ import testparseutil + def compilere(pat, multiline=False): if multiline: pat = '(?m)' + pat @@ -52,10 +57,22 @@ pass return re.compile(pat) + # check "rules depending on implementation of repquote()" in each # patterns (especially pypats), before changing around repquote() -_repquotefixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q', - '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'} +_repquotefixedmap = { + ' ': ' ', + '\n': '\n', + '.': 'p', + ':': 'q', + '%': '%', + '\\': 'b', + '*': 'A', + '+': 'P', + '-': 'M', +} + + def _repquoteencodechr(i): if i > 255: return 'u' @@ -67,13 +84,17 @@ if c.isdigit(): return 'n' return 'o' + + _repquotett = ''.join(_repquoteencodechr(i) for i in xrange(256)) + def repquote(m): t = m.group('text') t = t.translate(_repquotett) return m.group('quote') + t + m.group('quote') + def reppython(m): comment = m.group('comment') if comment: @@ -81,86 +102,103 @@ return "#" * l + comment[l:] return repquote(m) + def repcomment(m): return m.group(1) + "#" * len(m.group(2)) + def repccomment(m): t = re.sub(r"((?<=\n) )|\S", "x", m.group(2)) return m.group(1) + t + "*/" + def repcallspaces(m): t = re.sub(r"\n\s+", "\n", m.group(2)) return m.group(1) + t + def repinclude(m): return m.group(1) + "" + def rephere(m): t = re.sub(r"\S", "x", m.group(2)) return m.group(1) + t testpats = [ - [ - (r'\b(push|pop)d\b', "don't use 'pushd' or 'popd', use 'cd'"), - (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), - (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), - (r'(?'"), - (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"), - (r'\bls\b.*-\w*R', "don't use 'ls -R', use 'find'"), - (r'printf.*[^\\]\\([1-9]|0\d)', r"don't use 'printf \NNN', use Python"), - (r'printf.*[^\\]\\x', "don't use printf \\x, use Python"), - (r'rm -rf \*', "don't use naked rm -rf, target a directory"), - (r'\[[^\]]+==', '[ foo == bar ] is a bashism, use [ foo = bar ] instead'), - (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w', - "use egrep for extended grep syntax"), - (r'(^|\|\s*)e?grep .*\\S', "don't use \\S in regular expression"), - (r'(?\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), - (r'^stop\(\)', "don't use 'stop' as a shell function name"), - (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), - (r'\[\[\s+[^\]]*\]\]', "don't use '[[ ]]', use '[ ]'"), - (r'^alias\b.*=', "don't use alias, use a function"), - (r'if\s*!', "don't use '!' to negate exit status"), - (r'/dev/u?random', "don't use entropy, use /dev/zero"), - (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"), - (r'sed (-e )?\'(\d+|/[^/]*/)i(?!\\\n)', - "put a backslash-escaped newline after sed 'i' command"), - (r'^diff *-\w*[uU].*$\n(^ \$ |^$)', "prefix diff -u/-U with cmp"), - (r'^\s+(if)? diff *-\w*[uU]', "prefix diff -u/-U with cmp"), - (r'[\s="`\']python\s(?!bindings)', "don't use 'python', use '$PYTHON'"), - (r'seq ', "don't use 'seq', use $TESTDIR/seq.py"), - (r'\butil\.Abort\b', "directly use error.Abort"), - (r'\|&', "don't use |&, use 2>&1"), - (r'\w = +\w', "only one space after = allowed"), - (r'\bsed\b.*[^\\]\\n', "don't use 'sed ... \\n', use a \\ and a newline"), - (r'env.*-u', "don't use 'env -u VAR', use 'unset VAR'"), - (r'cp.* -r ', "don't use 'cp -r', use 'cp -R'"), - (r'grep.* -[ABC]', "don't use grep's context flags"), - (r'find.*-printf', - "don't use 'find -printf', it doesn't exist on BSD find(1)"), - (r'\$RANDOM ', "don't use bash-only $RANDOM to generate random values"), - ], - # warnings - [ - (r'^function', "don't use 'function', use old style"), - (r'^diff.*-\w*N', "don't use 'diff -N'"), - (r'\$PWD|\${PWD}', "don't use $PWD, use `pwd`"), - (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\^', "^ must be quoted"), - (r'kill (`|\$\()', "don't use kill, use killdaemons.py") - ] + [ + (r'\b(push|pop)d\b', "don't use 'pushd' or 'popd', use 'cd'"), + (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"), + (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"), + (r'(?'"), + (r'sha1sum', "don't use sha1sum, use $TESTDIR/md5sum.py"), + (r'\bls\b.*-\w*R', "don't use 'ls -R', use 'find'"), + (r'printf.*[^\\]\\([1-9]|0\d)', r"don't use 'printf \NNN', use Python"), + (r'printf.*[^\\]\\x', "don't use printf \\x, use Python"), + (r'rm -rf \*', "don't use naked rm -rf, target a directory"), + ( + r'\[[^\]]+==', + '[ foo == bar ] is a bashism, use [ foo = bar ] instead', + ), + ( + r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w', + "use egrep for extended grep syntax", + ), + (r'(^|\|\s*)e?grep .*\\S', "don't use \\S in regular expression"), + (r'(?\n]>\s*\$HGRCPATH', "don't overwrite $HGRCPATH, append to it"), + (r'^stop\(\)', "don't use 'stop' as a shell function name"), + (r'(\[|\btest\b).*-e ', "don't use 'test -e', use 'test -f'"), + (r'\[\[\s+[^\]]*\]\]', "don't use '[[ ]]', use '[ ]'"), + (r'^alias\b.*=', "don't use alias, use a function"), + (r'if\s*!', "don't use '!' to negate exit status"), + (r'/dev/u?random', "don't use entropy, use /dev/zero"), + (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"), + ( + r'sed (-e )?\'(\d+|/[^/]*/)i(?!\\\n)', + "put a backslash-escaped newline after sed 'i' command", + ), + (r'^diff *-\w*[uU].*$\n(^ \$ |^$)', "prefix diff -u/-U with cmp"), + (r'^\s+(if)? diff *-\w*[uU]', "prefix diff -u/-U with cmp"), + (r'[\s="`\']python\s(?!bindings)', "don't use 'python', use '$PYTHON'"), + (r'seq ', "don't use 'seq', use $TESTDIR/seq.py"), + (r'\butil\.Abort\b', "directly use error.Abort"), + (r'\|&', "don't use |&, use 2>&1"), + (r'\w = +\w', "only one space after = allowed"), + ( + r'\bsed\b.*[^\\]\\n', + "don't use 'sed ... \\n', use a \\ and a newline", + ), + (r'env.*-u', "don't use 'env -u VAR', use 'unset VAR'"), + (r'cp.* -r ', "don't use 'cp -r', use 'cp -R'"), + (r'grep.* -[ABC]', "don't use grep's context flags"), + ( + r'find.*-printf', + "don't use 'find -printf', it doesn't exist on BSD find(1)", + ), + (r'\$RANDOM ', "don't use bash-only $RANDOM to generate random values"), + ], + # warnings + [ + (r'^function', "don't use 'function', use old style"), + (r'^diff.*-\w*N', "don't use 'diff -N'"), + (r'\$PWD|\${PWD}', "don't use $PWD, use `pwd`"), + (r'^([^"\'\n]|("[^"\n]*")|(\'[^\'\n]*\'))*\^', "^ must be quoted"), + (r'kill (`|\$\()', "don't use kill, use killdaemons.py"), + ], ] testfilters = [ @@ -170,45 +208,72 @@ uprefix = r"^ \$ " utestpats = [ - [ - (r'^(\S.*|| [$>] \S.*)[ \t]\n', "trailing whitespace on non-output"), - (uprefix + r'.*\|\s*sed[^|>\n]*\n', - "use regex test output patterns instead of sed"), - (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), - (uprefix + r'.*(? for continued lines"), - (uprefix + r'.*:\.\S*/', "x:.y in a path does not work on msys, rewrite " - "as x://.y, or see `hg log -k msys` for alternatives", r'-\S+:\.|' #-Rxxx - '# no-msys'), # in test-pull.t which is skipped on windows - (r'^ [^$>].*27\.0\.0\.1', - 'use $LOCALIP not an explicit loopback address'), - (r'^ (?![>$] ).*\$LOCALIP.*[^)]$', - 'mark $LOCALIP output lines with (glob) to help tests in BSD jails'), - (r'^ (cat|find): .*: \$ENOENT\$', - 'use test -f to test for file existence'), - (r'^ diff -[^ -]*p', - "don't use (external) diff with -p for portability"), - (r' readlink ', 'use readlink.py instead of readlink'), - (r'^ [-+][-+][-+] .* [-+]0000 \(glob\)', - "glob timezone field in diff output for portability"), - (r'^ @@ -[0-9]+ [+][0-9]+,[0-9]+ @@', - "use '@@ -N* +N,n @@ (glob)' style chunk header for portability"), - (r'^ @@ -[0-9]+,[0-9]+ [+][0-9]+ @@', - "use '@@ -N,n +N* @@ (glob)' style chunk header for portability"), - (r'^ @@ -[0-9]+ [+][0-9]+ @@', - "use '@@ -N* +N* @@ (glob)' style chunk header for portability"), - (uprefix + r'hg( +-[^ ]+( +[^ ]+)?)* +extdiff' - r'( +(-[^ po-]+|--(?!program|option)[^ ]+|[^-][^ ]*))*$', - "use $RUNTESTDIR/pdiff via extdiff (or -o/-p for false-positives)"), - ], - # warnings - [ - (r'^ (?!.*\$LOCALIP)[^*?/\n]* \(glob\)$', - "glob match with no glob string (?, *, /, and $LOCALIP)"), - ] + [ + (r'^(\S.*|| [$>] \S.*)[ \t]\n', "trailing whitespace on non-output"), + ( + uprefix + r'.*\|\s*sed[^|>\n]*\n', + "use regex test output patterns instead of sed", + ), + (uprefix + r'(true|exit 0)', "explicit zero exit unnecessary"), + (uprefix + r'.*(? for continued lines"), + ( + uprefix + r'.*:\.\S*/', + "x:.y in a path does not work on msys, rewrite " + "as x://.y, or see `hg log -k msys` for alternatives", + r'-\S+:\.|' '# no-msys', # -Rxxx + ), # in test-pull.t which is skipped on windows + ( + r'^ [^$>].*27\.0\.0\.1', + 'use $LOCALIP not an explicit loopback address', + ), + ( + r'^ (?![>$] ).*\$LOCALIP.*[^)]$', + 'mark $LOCALIP output lines with (glob) to help tests in BSD jails', + ), + ( + r'^ (cat|find): .*: \$ENOENT\$', + 'use test -f to test for file existence', + ), + ( + r'^ diff -[^ -]*p', + "don't use (external) diff with -p for portability", + ), + (r' readlink ', 'use readlink.py instead of readlink'), + ( + r'^ [-+][-+][-+] .* [-+]0000 \(glob\)', + "glob timezone field in diff output for portability", + ), + ( + r'^ @@ -[0-9]+ [+][0-9]+,[0-9]+ @@', + "use '@@ -N* +N,n @@ (glob)' style chunk header for portability", + ), + ( + r'^ @@ -[0-9]+,[0-9]+ [+][0-9]+ @@', + "use '@@ -N,n +N* @@ (glob)' style chunk header for portability", + ), + ( + r'^ @@ -[0-9]+ [+][0-9]+ @@', + "use '@@ -N* +N* @@ (glob)' style chunk header for portability", + ), + ( + uprefix + r'hg( +-[^ ]+( +[^ ]+)?)* +extdiff' + r'( +(-[^ po-]+|--(?!program|option)[^ ]+|[^-][^ ]*))*$', + "use $RUNTESTDIR/pdiff via extdiff (or -o/-p for false-positives)", + ), + ], + # warnings + [ + ( + r'^ (?!.*\$LOCALIP)[^*?/\n]* \(glob\)$', + "glob match with no glob string (?, *, /, and $LOCALIP)", + ), + ], ] # transform plain test rules to unified test's @@ -234,148 +299,212 @@ # common patterns to check *.py commonpypats = [ - [ - (r'\\$', 'Use () to wrap long lines in Python, not \\'), - (r'^\s*def\s*\w+\s*\(.*,\s*\(', - "tuple parameter unpacking not available in Python 3+"), - (r'lambda\s*\(.*,.*\)', - "tuple parameter unpacking not available in Python 3+"), - (r'(?\s', '<> operator is not available in Python 3+, use !='), - (r'^\s*\t', "don't use tabs"), - (r'\S;\s*\n', "semicolon"), - (r'[^_]_\([ \t\n]*(?:"[^"]+"[ \t\n+]*)+%', "don't use % inside _()"), - (r"[^_]_\([ \t\n]*(?:'[^']+'[ \t\n+]*)+%", "don't use % inside _()"), - (r'(\w|\)),\w', "missing whitespace after ,"), - (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), - (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), - (( - # a line ending with a colon, potentially with trailing comments - r':([ \t]*#[^\n]*)?\n' - # one that is not a pass and not only a comment - r'(?P[ \t]+)[^#][^\n]+\n' - # more lines at the same indent level - r'((?P=indent)[^\n]+\n)*' - # a pass at the same indent level, which is bogus - r'(?P=indent)pass[ \t\n#]' - ), 'omit superfluous pass'), - (r'[^\n]\Z', "no trailing newline"), - (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), -# (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', -# "don't use underbars in identifiers"), - (r'^\s+(self\.)?[A-Za-z][a-z0-9]+[A-Z]\w* = ', - "don't use camelcase in identifiers", r'#.*camelcase-required'), - (r'^\s*(if|while|def|class|except|try)\s[^[\n]*:\s*[^\\n]#\s]+', - "linebreak after :"), - (r'class\s[^( \n]+:', "old-style class, use class foo(object)", - r'#.*old-style'), - (r'class\s[^( \n]+\(\):', - "class foo() creates old style object, use class foo(object)", - r'#.*old-style'), - (r'\b(%s)\(' % '|'.join(k for k in keyword.kwlist - if k not in ('print', 'exec')), - "Python keyword is not a function"), -# (r'class\s[A-Z][^\(]*\((?!Exception)', -# "don't capitalize non-exception classes"), -# (r'in range\(', "use xrange"), -# (r'^\s*print\s+', "avoid using print in core and extensions"), - (r'[\x80-\xff]', "non-ASCII character literal"), - (r'("\')\.format\(', "str.format() has no bytes counterpart, use %"), - (r'([\(\[][ \t]\S)|(\S[ \t][\)\]])', "gratuitous whitespace in () or []"), -# (r'\s\s=', "gratuitous whitespace before ="), - (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', - "missing whitespace around operator"), - (r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\s', - "missing whitespace around operator"), - (r'\s(\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', - "missing whitespace around operator"), - (r'[^^+=*/!<>&| %-](\s=|=\s)[^= ]', - "wrong whitespace around ="), - (r'\([^()]*( =[^=]|[^<>!=]= )', - "no whitespace around = for named parameters"), - (r'raise [^,(]+, (\([^\)]+\)|[^,\(\)]+)$', - "don't use old-style two-argument raise, use Exception(message)"), - (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), - (r' [=!]=\s+(True|False|None)', - "comparison with singleton, use 'is' or 'is not' instead"), - (r'^\s*(while|if) [01]:', - "use True/False for constant Boolean expression"), - (r'^\s*if False(:| +and)', 'Remove code instead of using `if False`'), - (r'(?:(?\s', '<> operator is not available in Python 3+, use !='), + (r'^\s*\t', "don't use tabs"), + (r'\S;\s*\n', "semicolon"), + (r'[^_]_\([ \t\n]*(?:"[^"]+"[ \t\n+]*)+%', "don't use % inside _()"), + (r"[^_]_\([ \t\n]*(?:'[^']+'[ \t\n+]*)+%", "don't use % inside _()"), + (r'(\w|\)),\w', "missing whitespace after ,"), + (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), + (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), + ( + ( + # a line ending with a colon, potentially with trailing comments + r':([ \t]*#[^\n]*)?\n' + # one that is not a pass and not only a comment + r'(?P[ \t]+)[^#][^\n]+\n' + # more lines at the same indent level + r'((?P=indent)[^\n]+\n)*' + # a pass at the same indent level, which is bogus + r'(?P=indent)pass[ \t\n#]' + ), + 'omit superfluous pass', + ), + (r'[^\n]\Z', "no trailing newline"), + (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), + # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', + # "don't use underbars in identifiers"), + ( + r'^\s+(self\.)?[A-Za-z][a-z0-9]+[A-Z]\w* = ', + "don't use camelcase in identifiers", + r'#.*camelcase-required', + ), + ( + r'^\s*(if|while|def|class|except|try)\s[^[\n]*:\s*[^\\n]#\s]+', + "linebreak after :", + ), + ( + r'class\s[^( \n]+:', + "old-style class, use class foo(object)", + r'#.*old-style', + ), + ( + r'class\s[^( \n]+\(\):', + "class foo() creates old style object, use class foo(object)", + r'#.*old-style', + ), + ( + r'\b(%s)\(' + % '|'.join(k for k in keyword.kwlist if k not in ('print', 'exec')), + "Python keyword is not a function", + ), + # (r'class\s[A-Z][^\(]*\((?!Exception)', + # "don't capitalize non-exception classes"), + # (r'in range\(', "use xrange"), + # (r'^\s*print\s+', "avoid using print in core and extensions"), + (r'[\x80-\xff]', "non-ASCII character literal"), + (r'("\')\.format\(', "str.format() has no bytes counterpart, use %"), + ( + r'([\(\[][ \t]\S)|(\S[ \t][\)\]])', + "gratuitous whitespace in () or []", + ), + # (r'\s\s=', "gratuitous whitespace before ="), + ( + r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', + "missing whitespace around operator", + ), + ( + r'[^>< ](\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\s', + "missing whitespace around operator", + ), + ( + r'\s(\+=|-=|!=|<>|<=|>=|<<=|>>=|%=)\S', + "missing whitespace around operator", + ), + (r'[^^+=*/!<>&| %-](\s=|=\s)[^= ]', "wrong whitespace around ="), + ( + r'\([^()]*( =[^=]|[^<>!=]= )', + "no whitespace around = for named parameters", + ), + ( + r'raise [^,(]+, (\([^\)]+\)|[^,\(\)]+)$', + "don't use old-style two-argument raise, use Exception(message)", + ), + (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), + ( + r' [=!]=\s+(True|False|None)', + "comparison with singleton, use 'is' or 'is not' instead", + ), + ( + r'^\s*(while|if) [01]:', + "use True/False for constant Boolean expression", + ), + (r'^\s*if False(:| +and)', 'Remove code instead of using `if False`'), + ( + r'(?:(?\#.*?$)| + ( + r"""(?msx)(?P\#.*?$)| ((?P('''|\"\"\"|(?(([^\\]|\\.)*?)) - (?P=quote))""", reppython), + (?P=quote))""", + reppython, + ), ] # filters to convert normal *.py files -pyfilters = [ -] + commonpyfilters +pyfilters = [] + commonpyfilters # non-filter patterns pynfpats = [ [ - (r'pycompat\.osname\s*[=!]=\s*[\'"]nt[\'"]', "use pycompat.iswindows"), - (r'pycompat\.osname\s*[=!]=\s*[\'"]posix[\'"]', "use pycompat.isposix"), - (r'pycompat\.sysplatform\s*[!=]=\s*[\'"]darwin[\'"]', - "use pycompat.isdarwin"), + (r'pycompat\.osname\s*[=!]=\s*[\'"]nt[\'"]', "use pycompat.iswindows"), + (r'pycompat\.osname\s*[=!]=\s*[\'"]posix[\'"]', "use pycompat.isposix"), + ( + r'pycompat\.sysplatform\s*[!=]=\s*[\'"]darwin[\'"]', + "use pycompat.isdarwin", + ), ], # warnings [], ] # filters to convert *.py for embedded ones in test script -embeddedpyfilters = [ -] + commonpyfilters +embeddedpyfilters = [] + commonpyfilters # extension non-filter patterns pyextnfpats = [ @@ -445,41 +578,40 @@ txtfilters = [] txtpats = [ - [ - (r'\s$', 'trailing whitespace'), - ('.. note::[ \n][^\n]', 'add two newlines after note::') - ], - [] + [ + (r'\s$', 'trailing whitespace'), + ('.. note::[ \n][^\n]', 'add two newlines after note::'), + ], + [], ] cpats = [ - [ - (r'//', "don't use //-style comments"), - (r'\S\t', "don't use tabs except for indent"), - (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), - (r'(while|if|do|for)\(', "use space after while/if/do/for"), - (r'return\(', "return is not a function"), - (r' ;', "no space before ;"), - (r'[^;] \)', "no space before )"), - (r'[)][{]', "space between ) and {"), - (r'\w+\* \w+', "use int *foo, not int* foo"), - (r'\W\([^\)]+\) \w+', "use (int)foo, not (int) foo"), - (r'\w+ (\+\+|--)', "use foo++, not foo ++"), - (r'\w,\w', "missing whitespace after ,"), - (r'^[^#]\w[+/*]\w', "missing whitespace in expression"), - (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), - (r'^#\s+\w', "use #foo, not # foo"), - (r'[^\n]\Z', "no trailing newline"), - (r'^\s*#import\b', "use only #include in standard C code"), - (r'strcpy\(', "don't use strcpy, use strlcpy or memcpy"), - (r'strcat\(', "don't use strcat"), - - # rules depending on implementation of repquote() - ], - # warnings - [ - # rules depending on implementation of repquote() - ] + [ + (r'//', "don't use //-style comments"), + (r'\S\t', "don't use tabs except for indent"), + (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), + (r'(while|if|do|for)\(', "use space after while/if/do/for"), + (r'return\(', "return is not a function"), + (r' ;', "no space before ;"), + (r'[^;] \)', "no space before )"), + (r'[)][{]', "space between ) and {"), + (r'\w+\* \w+', "use int *foo, not int* foo"), + (r'\W\([^\)]+\) \w+', "use (int)foo, not (int) foo"), + (r'\w+ (\+\+|--)', "use foo++, not foo ++"), + (r'\w,\w', "missing whitespace after ,"), + (r'^[^#]\w[+/*]\w', "missing whitespace in expression"), + (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), + (r'^#\s+\w', "use #foo, not # foo"), + (r'[^\n]\Z', "no trailing newline"), + (r'^\s*#import\b', "use only #include in standard C code"), + (r'strcpy\(', "don't use strcpy, use strlcpy or memcpy"), + (r'strcat\(', "don't use strcat"), + # rules depending on implementation of repquote() + ], + # warnings + [ + # rules depending on implementation of repquote() + ], ] cfilters = [ @@ -490,82 +622,109 @@ ] inutilpats = [ - [ - (r'\bui\.', "don't use ui in util"), - ], - # warnings - [] + [(r'\bui\.', "don't use ui in util"),], + # warnings + [], ] inrevlogpats = [ - [ - (r'\brepo\.', "don't use repo in revlog"), - ], - # warnings - [] + [(r'\brepo\.', "don't use repo in revlog"),], + # warnings + [], ] webtemplatefilters = [] webtemplatepats = [ - [], - [ - (r'{desc(\|(?!websub|firstline)[^\|]*)+}', - 'follow desc keyword with either firstline or websub'), - ] + [], + [ + ( + r'{desc(\|(?!websub|firstline)[^\|]*)+}', + 'follow desc keyword with either firstline or websub', + ), + ], ] allfilesfilters = [] allfilespats = [ - [ - (r'(http|https)://[a-zA-Z0-9./]*selenic.com/', - 'use mercurial-scm.org domain URL'), - (r'mercurial@selenic\.com', - 'use mercurial-scm.org domain for mercurial ML address'), - (r'mercurial-devel@selenic\.com', - 'use mercurial-scm.org domain for mercurial-devel ML address'), - ], - # warnings - [], + [ + ( + r'(http|https)://[a-zA-Z0-9./]*selenic.com/', + 'use mercurial-scm.org domain URL', + ), + ( + r'mercurial@selenic\.com', + 'use mercurial-scm.org domain for mercurial ML address', + ), + ( + r'mercurial-devel@selenic\.com', + 'use mercurial-scm.org domain for mercurial-devel ML address', + ), + ], + # warnings + [], ] py3pats = [ - [ - (r'os\.environ', "use encoding.environ instead (py3)", r'#.*re-exports'), - (r'os\.name', "use pycompat.osname instead (py3)"), - (r'os\.getcwd', "use encoding.getcwd instead (py3)", r'#.*re-exports'), - (r'os\.sep', "use pycompat.ossep instead (py3)"), - (r'os\.pathsep', "use pycompat.ospathsep instead (py3)"), - (r'os\.altsep', "use pycompat.osaltsep instead (py3)"), - (r'sys\.platform', "use pycompat.sysplatform instead (py3)"), - (r'getopt\.getopt', "use pycompat.getoptb instead (py3)"), - (r'os\.getenv', "use encoding.environ.get instead"), - (r'os\.setenv', "modifying the environ dict is not preferred"), - (r'(?