2020-06-11 00:54:34 +02:00
|
|
|
from typing import List
|
|
|
|
|
2018-08-05 00:15:53 +02:00
|
|
|
from zulint.linters import run_pycodestyle
|
2017-07-06 06:50:41 +02:00
|
|
|
|
2017-06-05 16:49:59 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def check_pep8(files: List[str]) -> bool:
|
2017-06-05 16:49:59 +02:00
|
|
|
ignored_rules = [
|
|
|
|
# Each of these rules are ignored for the explained reason.
|
|
|
|
|
|
|
|
# "multiple spaces before operator"
|
|
|
|
# There are several typos here, but also several instances that are
|
|
|
|
# being used for alignment in dict keys/values using the `dict`
|
|
|
|
# constructor. We could fix the alignment cases by switching to the `{}`
|
|
|
|
# constructor, but it makes fixing this rule a little less
|
|
|
|
# straightforward.
|
|
|
|
'E221',
|
|
|
|
|
|
|
|
# 'missing whitespace around arithmetic operator'
|
|
|
|
# This should possibly be cleaned up, though changing some of
|
|
|
|
# these may make the code less readable.
|
|
|
|
'E226',
|
|
|
|
|
2018-05-14 03:31:47 +02:00
|
|
|
# New rules in pycodestyle 2.4.0 that we haven't decided whether to comply with yet
|
2018-07-02 00:05:24 +02:00
|
|
|
'E252', 'W504',
|
2018-05-14 03:31:47 +02:00
|
|
|
|
2017-09-27 23:53:48 +02:00
|
|
|
# "multiple spaces after ':'"
|
|
|
|
# This is the `{}` analogue of E221, and these are similarly being used
|
|
|
|
# for alignment.
|
|
|
|
'E241',
|
|
|
|
|
2017-06-05 16:49:59 +02:00
|
|
|
# "unexpected spaces around keyword / parameter equals"
|
|
|
|
# Many of these should be fixed, but many are also being used for
|
|
|
|
# alignment/making the code easier to read.
|
|
|
|
'E251',
|
|
|
|
|
|
|
|
# "block comment should start with '#'"
|
|
|
|
# These serve to show which lines should be changed in files customized
|
|
|
|
# by the user. We could probably resolve one of E265 or E266 by
|
|
|
|
# standardizing on a single style for lines that the user might want to
|
|
|
|
# change.
|
|
|
|
'E265',
|
|
|
|
|
|
|
|
# "too many leading '#' for block comment"
|
|
|
|
# Most of these are there for valid reasons.
|
|
|
|
'E266',
|
|
|
|
|
|
|
|
# "expected 2 blank lines after class or function definition"
|
|
|
|
# Zulip only uses 1 blank line after class/function
|
|
|
|
# definitions; the PEP-8 recommendation results in super sparse code.
|
|
|
|
'E302', 'E305',
|
|
|
|
|
|
|
|
# "module level import not at top of file"
|
|
|
|
# Most of these are there for valid reasons, though there might be a
|
|
|
|
# few that could be eliminated.
|
|
|
|
'E402',
|
|
|
|
|
|
|
|
# "line too long"
|
|
|
|
# Zulip is a bit less strict about line length, and has its
|
|
|
|
# own check for this (see max_length)
|
|
|
|
'E501',
|
|
|
|
|
|
|
|
# "do not assign a lambda expression, use a def"
|
|
|
|
# Fixing these would probably reduce readability in most cases.
|
|
|
|
'E731',
|
2017-10-26 01:33:10 +02:00
|
|
|
|
|
|
|
# "line break before binary operator"
|
|
|
|
# This is a bug in the `pep8`/`pycodestyle` tool -- it's completely backward.
|
|
|
|
# See https://github.com/PyCQA/pycodestyle/issues/498 .
|
|
|
|
'W503',
|
|
|
|
|
|
|
|
# This number will probably be used for the corrected, inverse version of
|
|
|
|
# W503 when that's added: https://github.com/PyCQA/pycodestyle/pull/502
|
|
|
|
# Once that fix lands and we update to a version of pycodestyle that has it,
|
|
|
|
# we'll want the rule; but we might have to briefly ignore it while we fix
|
|
|
|
# existing code.
|
|
|
|
# 'W504',
|
2017-06-05 16:49:59 +02:00
|
|
|
]
|
|
|
|
|
2018-08-05 00:15:53 +02:00
|
|
|
return run_pycodestyle(files, ignored_rules)
|