2018-01-24 03:09:52 +03:00
|
|
|
|
[flake8]
|
2018-02-08 19:15:04 +03:00
|
|
|
|
select =
|
2018-02-10 04:31:41 +03:00
|
|
|
|
F401, # module imported but unused
|
2018-02-08 19:15:04 +03:00
|
|
|
|
F402, # import module from line N shadowed by loop variable
|
|
|
|
|
F403, # ‘from module import *’ used; unable to detect undefined names
|
|
|
|
|
F404, # future import(s) name after other statements
|
|
|
|
|
F405, # name may be undefined, or defined from star imports: module
|
|
|
|
|
F406, # ‘from module import *’ only allowed at module level
|
|
|
|
|
F407, # an undefined __future__ feature name was imported
|
|
|
|
|
F601, # dictionary key name repeated with different values
|
|
|
|
|
F602, # dictionary key variable name repeated with different values
|
|
|
|
|
F621, # too many expressions in an assignment with star-unpacking
|
|
|
|
|
F622, # two or more starred expressions in an assignment (a, *b, *c = d)
|
|
|
|
|
F631, # assertion test is a tuple, which are always True
|
|
|
|
|
F701, # a break statement outside of a while or for loop
|
|
|
|
|
F702, # a continue statement outside of a while or for loop
|
|
|
|
|
F703, # a continue statement in a finally block in a loop
|
|
|
|
|
F704, # a yield or yield from statement outside of a function
|
|
|
|
|
F705, # a return statement with arguments inside a generator
|
|
|
|
|
F706, # a return statement outside of a function/method
|
|
|
|
|
F707, # an except: block as not the last exception handler
|
2018-02-10 04:31:41 +03:00
|
|
|
|
F811, # redefinition of unused name from line N
|
|
|
|
|
F812, # list comprehension redefines name from line N
|
flake8: enable F821 check
Summary:
This check is useful and detects real errors (ex. fbconduit). Unfortunately
`arc lint` will run it with both py2 and py3 so a lot of py2 builtins will
still be warned.
I didn't find a clean way to disable py3 check. So this diff tries to fix them.
For `xrange`, the change was done by a script:
```
import sys
import redbaron
headertypes = {'comment', 'endl', 'from_import', 'import', 'string',
'assignment', 'atomtrailers'}
xrangefix = '''try:
xrange(0)
except NameError:
xrange = range
'''
def isxrange(x):
try:
return x[0].value == 'xrange'
except Exception:
return False
def main(argv):
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
content = open(path).read()
try:
red = redbaron.RedBaron(content)
except Exception:
print(' warning: failed to parse')
continue
hasxrange = red.find('atomtrailersnode', value=isxrange)
hasxrangefix = 'xrange = range' in content
if hasxrangefix or not hasxrange:
print(' no need to change')
continue
# find a place to insert the compatibility statement
changed = False
for node in red:
if node.type in headertypes:
continue
# node.insert_before is an easier API, but it has bugs changing
# other "finally" and "except" positions. So do the insert
# manually.
# # node.insert_before(xrangefix)
line = node.absolute_bounding_box.top_left.line - 1
lines = content.splitlines(1)
content = ''.join(lines[:line]) + xrangefix + ''.join(lines[line:])
changed = True
break
if changed:
# "content" is faster than "red.dumps()"
open(path, 'w').write(content)
print(' updated')
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
```
For other py2 builtins that do not have a py3 equivalent, some `# noqa`
were added as a workaround for now.
Reviewed By: DurhamG
Differential Revision: D6934535
fbshipit-source-id: 546b62830af144bc8b46788d2e0fd00496838939
2018-02-10 04:31:44 +03:00
|
|
|
|
F821, # undefined name name
|
2018-02-08 19:15:04 +03:00
|
|
|
|
F822, # undefined name name in __all__
|
|
|
|
|
F823, # local variable name … referenced before assignment
|
|
|
|
|
F831, # duplicate argument name in function definition
|
2018-02-10 04:31:41 +03:00
|
|
|
|
F841, # local variable name is assigned to but never used
|
2018-02-08 19:15:04 +03:00
|
|
|
|
E101, # indentation contains mixed spaces and tabs
|
|
|
|
|
E112, # expected an indented block
|
|
|
|
|
E113, # unexpected indentation
|
|
|
|
|
E133, # closing bracket is missing indentation
|
|
|
|
|
E223, # tab before operator
|
|
|
|
|
E224, # tab after operator
|
|
|
|
|
E242, # tab after ‘,’
|
|
|
|
|
E272, # multiple spaces before keyword
|
|
|
|
|
E273, # tab after keyword
|
|
|
|
|
E274, # tab before keyword
|
|
|
|
|
E304, # blank lines found after function decorator
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
# BLACK can make lines longer than 80 characters
|
|
|
|
|
# E501, # line too long (82 > 79 characters)
|
2018-02-08 19:15:04 +03:00
|
|
|
|
E703, # statement ends with a semicolon
|
|
|
|
|
E704, # multiple statements on one line (def)
|
2018-02-10 04:31:46 +03:00
|
|
|
|
E711, # comparison to None should be ‘if cond is None:’
|
2018-02-08 19:15:04 +03:00
|
|
|
|
E712, # comparison to True should be ‘if cond is True:’ or ‘if cond:’
|
|
|
|
|
E714, # test for object identity should be ‘is not’
|
|
|
|
|
E742, # do not define classes named ‘l’, ‘O’, or ‘I’
|
|
|
|
|
E743, # do not define functions named ‘l’, ‘O’, or ‘I’
|
|
|
|
|
E901, # SyntaxError or IndentationError
|
|
|
|
|
E902, # IOError
|
|
|
|
|
W191, # indentation contains tabs
|
|
|
|
|
W291, # trailing whitespace
|
|
|
|
|
W292, # no newline at end of file
|
|
|
|
|
W504, # line break after binary operator
|
|
|
|
|
W601, # .has_key() is deprecated, use ‘in’
|
|
|
|
|
W602, # deprecated form of raising exception
|
|
|
|
|
W603, # ‘<>’ is deprecated, use ‘!=’
|
|
|
|
|
W604, # backticks are deprecated, use ‘repr()’
|
|
|
|
|
W605, # invalid escape sequence ‘x’
|