From ceb159a343afb8a99ce42c9fe8c657c3cae73474 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 29 Dec 2021 14:54:21 +0100 Subject: [PATCH] Switch to flakehell & wemake python styleguide --- .flake8 | 12 ------------ .pre-commit-config.yaml | 7 ++++--- pyproject.toml | 24 ++++++++++++++++++++++++ src/articles/views/feeds.py | 4 +--- src/attachments/admin.py | 4 ++-- src/manage.py | 2 +- 6 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 77fb31e..0000000 --- a/.flake8 +++ /dev/null @@ -1,12 +0,0 @@ -[flake8] -ignore = - # long lines - E501, - # deprecated rule: https://www.flake8rules.com/rules/W503.html - W503, - # conflict with black on PEP8 interpretation - E203, - # class attribute is shadowing a python builtin - A003, - -max-complexity = 10 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba1ba58..9f52db6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,10 +43,10 @@ repos: rev: v1.4.11 hooks: - id: djhtml - - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + - repo: https://github.com/mcarans/flakehell + rev: 1b84f4dd6c16232b5c0c6206511427676ab55f5b hooks: - - id: flake8 + - id: flakehell additional_dependencies: - flake8-annotations-complexity - flake8-builtins @@ -56,6 +56,7 @@ repos: - flake8-noqa - flake8-pytest-style - flake8-pyi + - wemake-python-styleguide - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.5.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index 5c0242e..b05d9e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,6 +81,30 @@ ignore_missing_imports = true [tool.django-stubs] django_settings_module = "blog.settings" +[tool.flakehell] +max_complexity = 10 +format = "grouped" + +[tool.flakehell.plugins] +"flake8-*" = [ + "+*", + # long lines + "-E501", + # conflict with black on PEP8 interpretation + "-E203", + # deprecated rule: https://www.flake8rules.com/rules/W503.html + "-W503", +] +flake8-builtins = ["-A003"] # class attribute is shadowing a python builtin +flake8-quotes = ["-Q000"] # found double quotes, conflict with black +flake8-commas = ["-C812"] # missing trailing comma, conflict with black +flake8-docstrings = ["-D1??"] # missing docstring +flake8-rst-docstrings = ["-*"] + +[tool.flakehell.exceptions."**/migrations/*"] + +[tool.flakehell.exceptions."**/tests/*"] +flake8-bandit = ["-S101"] # Use of assert detected. [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/src/articles/views/feeds.py b/src/articles/views/feeds.py index 434481b..581b743 100644 --- a/src/articles/views/feeds.py +++ b/src/articles/views/feeds.py @@ -34,9 +34,7 @@ class CompleteFeed(BaseFeed): class TagFeed(BaseFeed): - def get_object( # type: ignore[override] - self, request: WSGIRequest, *args, **kwargs - ) -> Tag: + def get_object(self, request: WSGIRequest, *args, **kwargs) -> Tag: # type: ignore[override] return Tag.objects.get(slug=kwargs.get("slug")) def title(self, tag: Tag) -> str: diff --git a/src/attachments/admin.py b/src/attachments/admin.py index 1bef54b..8fb53e6 100644 --- a/src/attachments/admin.py +++ b/src/attachments/admin.py @@ -41,7 +41,7 @@ class AttachmentAdmin(admin.ModelAdmin): def processed_file_url(self, instance): if instance.processed_file: return format_html( - '{} 📋', + '{0} 📋', instance.processed_file.url, instance.processed_file.url, ) @@ -50,7 +50,7 @@ class AttachmentAdmin(admin.ModelAdmin): def original_file_url(self, instance): if instance.original_file: return format_html( - '{} 📋', + '{0} 📋', instance.original_file.url, instance.original_file.url, ) diff --git a/src/manage.py b/src/manage.py index 75a510d..ba0201f 100755 --- a/src/manage.py +++ b/src/manage.py @@ -5,7 +5,7 @@ import sys def main(): - """Run administrative tasks.""" + """Run administrative tasks.""" # noqa: DAR401 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings") try: from django.core.management import execute_from_command_line