Check more flake8 in pre-commit
See original GitHub issueRight now we use a small subset of flake8 in pre-commit. Given that pre-commit runs primarily on PR diffs, it seems fine to check for more problems. There are hundreds of violations of the full flake8 checks, so I think we should sequentially add codes to pre-commit to keep correction PRs small (the PRs should either fix the problems and/or add the appropriate noqa
).
PRs TODO
- F401 : module imported but unused (#13853)
- F402 : import module from line N shadowed by loop variable (#13853)
- F403 ‘from module import *’ used; unable to detect undefined names
- F404 : future import(s) name after other statements (#13853)
- F405 : name may be undefined, or defined from star imports: module (#13853)
- F406 : ‘from module import *’ only allowed at module level (#13853)
- F407 : an undefined future feature name was imported (#13853)
- F501 : invalid % format literal (#13853)
- F502 : % format expected mapping but got sequence (#13853)
- F503 : % format expected sequence but got mapping (#13853)
- F504 : % format unused named arguments (#13853)
- F505 : % format missing named arguments (#13853)
- F506 : % format mixed positional and named arguments (#13853)
- F507 : % format mismatch of placeholder and argument count (#13853)
- F508 : % format with * specifier requires a sequence (#13853)
- F509 : % format with unsupported format character (#13853)
- F521 : .format(…) invalid format string
- F522 : .format(…) unused named arguments
- F523 : .format(…) unused positional arguments
- F524 : .format(…) missing argument
- F525 : .format(…) mixing automatic and manual numbering
- F541 : f-string without any placeholders
- 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 is always True
- F632 : use ==/!= to compare str, bytes, and int literals
- F633 : use of >> is invalid with print function
- F634 : if test is a tuple, which is always True
- F701 : a break statement outside of a while or for loop (#13853)
- F702 : a continue statement outside of a while or for loop (#13853)
- F703 : a continue statement in a finally block in a loop (#13853)
- F704 : a yield or yield from statement outside of a function (#13853)
- F706 : a return statement outside of a function/method (#13853)
- F707 : an except: block as not the last exception handler (#13853)
- F721 : syntax error in doctest
- F722 : syntax error in forward annotation
- F723 : syntax error in type comment
- F811 : redefinition of unused name from line N
- F821 : undefined name name
- F822 : undefined name name in all
- F823 : local variable name … referenced before assignment
- F831 : duplicate argument name in function definition
- F841 : local variable name is assigned to but never used
- F901 : raise NotImplemented should be raise NotImplementedError (#13853)
- C901
- E101 | indentation contains mixed spaces and tabs
- E111 | indentation is not a multiple of four
- E112 | expected an indented block
- E113 | unexpected indentation
- E114 | indentation is not a multiple of four (comment)
- E115 | expected an indented block (comment)
- E116 | unexpected indentation (comment)
- E117 | over-indented
- E121 (*^) | continuation line under-indented for hanging indent
- E122 (^) | continuation line missing indentation or outdented
- E123 (*) | closing bracket does not match indentation of opening bracket’s line
- E124 (^) | closing bracket does not match visual indentation
- E125 (^) | continuation line with same indent as next logical line
- E126 (*^) | continuation line over-indented for hanging indent
- E127 (^) | continuation line over-indented for visual indent
- E128 (^) | continuation line under-indented for visual indent
- E129 (^) | visually indented line with same indent as next logical line
- E131 (^) | continuation line unaligned for hanging indent
- E133 (*) | closing bracket is missing indentation
- E201 | whitespace after ‘(’
- E202 | whitespace before ‘)’
- E203 | whitespace before ‘,’, ‘;’, or ‘:’
- E211 | whitespace before ‘(’
- E221 | multiple spaces before operator
- E222 | multiple spaces after operator
- E223 | tab before operator
- E224 | tab after operator
- E225 | missing whitespace around operator
- E226 (*) | missing whitespace around arithmetic operator
- E227 | missing whitespace around bitwise or shift operator
- E228 | missing whitespace around modulo operator
- E231 | missing whitespace after ‘,’, ‘;’, or ‘:’
- E241 (*) | multiple spaces after ‘,’
- E242 (*) | tab after ‘,’
- E251 | unexpected spaces around keyword / parameter equals
- E261 | at least two spaces before inline comment
- E262 | inline comment should start with ‘# ‘
- E265 | block comment should start with ‘# ‘
- E266 | too many leading ‘#’ for block comment
- E271 | multiple spaces after keyword
- E272 | multiple spaces before keyword
- E273 | tab after keyword
- E274 | tab before keyword
- E275 | missing whitespace after keyword
- E301 | expected 1 blank line, found 0
- E302 | expected 2 blank lines, found 0
- E303 | too many blank lines (3)
- E304 | blank lines found after function decorator
- E305 | expected 2 blank lines after end of function or class
- E306 | expected 1 blank line before a nested definition
- E401 | multiple imports on one line
- E402 | module level import not at top of file
- E501 (^) | line too long (82 > 79 characters)
- E502 | the backslash is redundant between brackets
- E701 | multiple statements on one line (colon)
- E702 | multiple statements on one line (semicolon)
- E703 | statement ends with a semicolon
- E704 (*) | multiple statements on one line (def)
- E711 (^) | comparison to None should be ‘if cond is None:’
- E712 (^) | comparison to True should be ‘if cond is True:’ or ‘if cond:’
- E713 | test for membership should be ‘not in’
- E714 | test for object identity should be ‘is not’
- E721 (^) | do not compare types, use ‘isinstance()’
- E722 | do not use bare except, specify exception instead
- E731 | do not assign a lambda expression, use a def
- E741 | do not use variables named ‘l’, ‘O’, or ‘I’
- 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
- E999
- W191 | indentation contains tabs
- W291 | trailing whitespace
- W292 | no newline at end of file
- W293 | blank line contains whitespace
- W391 | blank line at end of file
- W503 (*) | line break before binary operator
- W504 (*) | line break after binary operator
- W505 (*^) | doc line too long (82 > 79 characters)
- W605 | invalid escape sequence ‘x’
- W606 | ‘async’ and ‘await’ are reserved keywords starting with Python 3.7
Issue Analytics
- State:
- Created a year ago
- Comments:22 (22 by maintainers)
Top Results From Across the Web
Using Version Control Hooks — flake8 6.0.0 documentation
Flake8 can be included as a hook for pre-commit. ... Checked-in python files will be passed as positional arguments. flake8 will always lint...
Read more >Create a Global GIT Hook to Check Flake8 Before Each Commit
Create a global GIT hook to check Flake8 before each commit · 1. Enable git templates: $ git config –global init. · 2....
Read more >flake8 hook checks all python files in the repo, not ... - GitHub
pre-commit rejects any commit containing python files if unstaged python files in the repo fail flake8. This is pretty much insufferable ...
Read more >pre-commit: Flake8 for Python - Calmcode
Calmcode - pre-commit: Flake8 for Python This opens in a new window. The config file that contans flake8 which we use in the...
Read more >Correctly using pre-commit with flake8 plugins - Stack Overflow
If the versions are left unconstrained, pre-commit may use a different linting configuration in different environments, but then if an exact ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After doing some of the simpler sub-packages, yes I agree.
@nstarman - Sure, one of the benefit of using black is that the formatting should then be pep8 compliant, except maybe a few specific cases. So I guess once black has been applied we could switch to a flake8 config where we just exclude a few rules.