From 05d15940fbca5d69b15d57a2fdc4ac23724ab991 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 12 Nov 2024 08:43:47 +0100 Subject: [PATCH] Update our pre-commit hooks --- .pre-commit-config.yaml | 37 ++++++----------- biome.json | 57 +++++++++++++++++++++++++++ feincms3_language_sites/middleware.py | 2 +- pyproject.toml | 39 +++++++++--------- tests/testapp/urls.py | 2 +- tests/testapp/views.py | 4 +- 6 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 biome.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8fdc202..1a1a7c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-builtin-literals @@ -14,40 +14,27 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/adamchainz/django-upgrade - rev: 1.15.0 + rev: 1.22.1 hooks: - id: django-upgrade args: [--target-version, "3.2"] - - repo: https://github.com/MarcoGorelli/absolufy-imports - rev: v0.3.1 - hooks: - - id: absolufy-imports - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.1.3" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.7.0" hooks: - id: ruff + args: [--unsafe-fixes] - id: ruff-format - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.3 - hooks: - - id: prettier - args: [--list-different, --no-semi] - exclude: "^conf/|.*\\.html$" - - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.52.0 + - repo: https://github.com/biomejs/pre-commit + rev: "v0.5.0" hooks: - - id: eslint - additional_dependencies: - - eslint - - eslint-config-prettier - - "@babel/core" - - "@babel/eslint-parser" - - "@babel/preset-env" + - id: biome-check + additional_dependencies: ["@biomejs/biome@1.9.4"] + args: [--unsafe] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.3.0 + rev: 2.4.3 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.15 + rev: v0.21 hooks: - id: validate-pyproject diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..dea25a7 --- /dev/null +++ b/biome.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "organizeImports": { + "enabled": false + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2 + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "a11y": { + "noSvgWithoutTitle": "off" + }, + "correctness": { + "noUndeclaredVariables": "error", + "noUnusedImports": "error", + "noUnusedVariables": "error", + "useArrayLiterals": "error", + "useHookAtTopLevel": "error" + }, + "security": { + "noDangerouslySetInnerHtml": "warn" + }, + "style": { + "noParameterAssign": "off", + "useForOf": "warn" + }, + "suspicious": { + "noArrayIndexKey": "warn", + "noAssignInExpressions": "off" + } + } + }, + "javascript": { + "formatter": { + "semicolons": "asNeeded" + }, + "globals": ["django", "CKEDITOR"] + }, + "css": { + "formatter": { + "enabled": true + }, + "linter": { + "enabled": true + } + }, + "json": { + "formatter": { + "enabled": false + } + } +} diff --git a/feincms3_language_sites/middleware.py b/feincms3_language_sites/middleware.py index 94903b4..ee6ee87 100644 --- a/feincms3_language_sites/middleware.py +++ b/feincms3_language_sites/middleware.py @@ -10,7 +10,7 @@ def site_middleware(get_response): def middleware(request): request.site = site_for_host(request.get_host()) if request.site is None: - raise DisallowedHost("No configuration found for %r" % request.get_host()) + raise DisallowedHost(f"No configuration found for {request.get_host()!r}") translation.activate(request.site["language_code"]) request.LANGUAGE_CODE = translation.get_language() diff --git a/pyproject.toml b/pyproject.toml index 7a08588..f741257 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,9 +8,9 @@ requires = [ name = "feincms3-language-sites" description = "Multisite support for feincms3" readme = "README.rst" -license = {text="BSD-3-Clause"} +license = { text = "BSD-3-Clause" } authors = [ - { name = "Matthias Kestenholz", email = "mk@feinheit.ch" }, + { name = "Matthias Kestenholz", email = "mk@feinheit.ch" }, ] requires-python = ">=3.9" classifiers = [ @@ -24,6 +24,8 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Application Frameworks", @@ -32,24 +34,28 @@ dynamic = [ "version", ] dependencies = [ - "Django>=3.2", + "django>=3.2", "feincms3>=5.0a2", ] -[project.optional-dependencies] -tests = [ +optional-dependencies.tests = [ "coverage", "feincms3[all]", ] -[project.urls] -Homepage = "https://github.com/matthiask/feincms3-language-sites/" +urls.Homepage = "https://github.com/matthiask/feincms3-language-sites/" [tool.hatch.version] path = "feincms3_language_sites/__init__.py" [tool.ruff] +target-version = "py39" + +fix = true +show-fixes = true extend-select = [ # pyflakes, pycodestyle - "F", "E", "W", + "F", + "E", + "W", # mmcabe "C90", # isort @@ -87,19 +93,10 @@ extend-ignore = [ # No line length errors "E501", ] -fix = true -show-fixes = true -target-version = "py39" - -[tool.ruff.isort] -combine-as-imports = true -lines-after-imports = 2 - -[tool.ruff.mccabe] -max-complexity = 15 - -[tool.ruff.per-file-ignores] -"*/migrat*/*" = [ +isort.combine-as-imports = true +isort.lines-after-imports = 2 +mccabe.max-complexity = 15 +per-file-ignores."*/migrat*/*" = [ # Allow using PascalCase model names in migrations "N806", # Ignore the fact that migration files are invalid module names diff --git a/tests/testapp/urls.py b/tests/testapp/urls.py index 6f1178b..1b68173 100644 --- a/tests/testapp/urls.py +++ b/tests/testapp/urls.py @@ -9,7 +9,7 @@ pages_urlpatterns = ( [ - path("", lambda request: HttpResponseRedirect("/%s/" % request.LANGUAGE_CODE)), + path("", lambda request: HttpResponseRedirect(f"/{request.LANGUAGE_CODE}/")), re_path(r"^(?P[-\w/]+)/$", views.page_detail, name="page"), path("", views.page_detail, name="root"), ], diff --git a/tests/testapp/views.py b/tests/testapp/views.py index 0480e9b..a5b2103 100644 --- a/tests/testapp/views.py +++ b/tests/testapp/views.py @@ -14,9 +14,7 @@ def page_detail(request, path=None): - page = get_object_or_404( - Page.objects.active(), path=("/%s/" % path) if path else "/" - ) + page = get_object_or_404(Page.objects.active(), path=(f"/{path}/") if path else "/") page.activate_language(request) return render(