Skip to content

Commit

Permalink
Update pre-commit hooks, switch from ESLint to biome
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jun 1, 2024
1 parent 0bef06e commit 9971261
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 111 deletions.
32 changes: 0 additions & 32 deletions .eslintrc.js

This file was deleted.

25 changes: 10 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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: v4.6.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand All @@ -14,7 +14,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.15.0
rev: 1.18.0
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
Expand All @@ -23,7 +23,7 @@ repos:
hooks:
- id: absolufy-imports
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.7"
rev: "v0.4.7"
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -33,21 +33,16 @@ repos:
- id: prettier
args: [--list-different, --no-semi]
exclude: "^conf/|.*\\.html$"
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.54.0
hooks:
- id: eslint
additional_dependencies:
- eslint
- eslint-config-prettier
- "@babel/core"
- "@babel/eslint-parser"
- "@babel/preset-env"
- repo: https://github.com/biomejs/pre-commit
rev: "v0.1.0"
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/biome@1.7.3"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.5.1
rev: 2.1.3
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
rev: v0.18
hooks:
- id: validate-pyproject
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Next version
``UseRootMiddlewareResponse`` so that it can be used in advanced or exotic
scenarios to allow the root middleware to run even after views return a 404
response.
- Switched from ESLint to biome.


4.6 (2024-02-26)
Expand Down
25 changes: 25 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noForEach": "off"
}
}
}
}
2 changes: 1 addition & 1 deletion feincms3/plugins/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Provides an image plugin with support for setting the primary point of
interest. This is very useful especially when cropping images. Depends on
`django-imagefield <https://django-imagefield.readthedocs.io>`__. """
`django-imagefield <https://django-imagefield.readthedocs.io>`__."""

import os

Expand Down
1 change: 1 addition & 0 deletions feincms3/plugins/old_richtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
`django-ckeditor <https://github.com/django-ckeditor/django-ckeditor/>`__ and
`html-sanitizer <https://pypi.org/project/html-sanitizer>`__.
"""

import warnings

from content_editor.admin import ContentEditorInline
Expand Down
6 changes: 2 additions & 4 deletions feincms3/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ def template_name(model, template_name_suffix):
"auth/user_form.html"
"""

return "{}/{}{}.html".format(
model._meta.app_label,
model._meta.model_name,
template_name_suffix,
return (
f"{model._meta.app_label}/{model._meta.model_name}{template_name_suffix}.html"
)


Expand Down
18 changes: 9 additions & 9 deletions feincms3/static/feincms3/box-drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ document.addEventListener("DOMContentLoaded", () => {
const nodes = {}
const parents = []

for (let toggle of root.querySelectorAll(".collapse-toggle")) {
for (const toggle of root.querySelectorAll(".collapse-toggle")) {
const node = toggle.closest("tr")
const pk = +toggle.dataset.pk
const treeDepth = +toggle.dataset.treeDepth
const rec =
(parents[treeDepth] =
nodes[pk] =
[pk, treeDepth, [], node, toggle])
const rec = [pk, treeDepth, [], node, toggle]
parents[treeDepth] = rec
nodes[pk] = rec

if (treeDepth > 0) {
// parent may be on the previous page if the changelist is paginated.
let parent = parents[treeDepth - 1]
const parent = parents[treeDepth - 1]
if (parent) {
parent[CHILDREN].push(rec)
parent[TOGGLE].classList.remove("collapse-hide")
Expand All @@ -30,22 +30,22 @@ document.addEventListener("DOMContentLoaded", () => {

function setCollapsed(pk, collapsed) {
nodes[pk][TOGGLE].classList.toggle("collapsed", collapsed)
for (let rec of nodes[pk][CHILDREN]) {
for (const rec of nodes[pk][CHILDREN]) {
rec[TR].classList.toggle("collapse-hide", collapsed)
setCollapsed(rec[PK], collapsed)
}
}

function initiallyCollapse(minDepth) {
for (let rec of Object.values(nodes)) {
for (const rec of Object.values(nodes)) {
if (rec[DEPTH] >= minDepth && rec[CHILDREN].length) {
setCollapsed(rec[PK], true)
}
}
}

root.addEventListener("click", (e) => {
let collapseToggle = e.target.closest(".collapse-toggle")
const collapseToggle = e.target.closest(".collapse-toggle")
if (collapseToggle) {
e.preventDefault()
setCollapsed(
Expand Down
4 changes: 2 additions & 2 deletions feincms3/static/feincms3/inline-ckeditor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global CKEDITOR, django */
;(function () {
;(() => {
function onReady(fn) {
if (
document.readyState === "complete" ||
Expand All @@ -12,7 +12,7 @@
}
}

onReady(function () {
onReady(() => {
const configs = {}
const scripts = document.querySelectorAll("[data-inline-cke-config]")
scripts.forEach(function parseConfig(script) {
Expand Down
4 changes: 2 additions & 2 deletions feincms3/static/feincms3/static-path-style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", () => {
const staticPathField = document.querySelector("#id_static_path")
const pathField = document.querySelector("#id_path")

Expand All @@ -19,7 +19,7 @@ document.addEventListener("DOMContentLoaded", function () {
background: var(--selected-bg, #e4e4e4);
}
`
document.head.appendChild(style)
document.head.append(style)

update()
staticPathField.addEventListener("change", update)
Expand Down
93 changes: 47 additions & 46 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ requires = [
name = "feincms3"
description = "CMS-building toolkit for Django"
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 = [
Expand All @@ -34,94 +34,95 @@ dynamic = [
]
dependencies = [
"asgiref>=3.6",
"Django>=3.2",
"django>=3.2",
"django-content-editor>=6",
"django-js-asset>=2",
"django-tree-queries>=0.15",
]
[project.optional-dependencies]
all = [
optional-dependencies.all = [
"django-imagefield",
"html-sanitizer>=1.1.1",
"requests",
]
tests = [
optional-dependencies.tests = [
"coverage",
"django-ckeditor",
"requests-mock",
]
[project.urls]
Homepage = "https://github.com/matthiask/feincms3/"
urls.Homepage = "https://github.com/matthiask/feincms3/"

[tool.hatch.build]
include = ["feincms3/"]
include = [
"feincms3/",
]

[tool.hatch.version]
path = "feincms3/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
"/feincms3",
"/feincms3",
]

[tool.ruff]
extend-select = [
# pyflakes, pycodestyle
"F", "E", "W",
# mmcabe
"C90",
# isort
"I",
# pep8-naming
"N",
# pyupgrade
"UP",
# flake8-2020
"YTT",
# flake8-boolean-trap
"FBT",
target-version = "py39"

fix = true
show-fixes = true
lint.extend-select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# mmcabe
"C90",
# flake8-django
"DJ",
# flake8-implicit-string-concatenation
"ISC",
# flake8-pie
"PIE",
# flake8-simplify
"SIM",
"E",
# pyflakes, pycodestyle
"F",
# flake8-boolean-trap
"FBT",
# isort
"I",
# flake8-gettext
"INT",
# flake8-implicit-string-concatenation
"ISC",
# pep8-naming
"N",
# pygrep-hooks
"PGH",
# flake8-pie
"PIE",
# pylint
"PLC", "PLE", "PLW",
"PLC",
"PLE",
"PLW",
# unused noqa
"RUF100",
# flake8-simplify
"SIM",
# pyupgrade
"UP",
"W",
# flake8-2020
"YTT",
]
extend-ignore = [
lint.extend-ignore = [
# Allow zip() without strict=
"B905",
# No line length errors
"E501",
# Do not warn about percent formatting for now
"UP031",
]
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*/*" = [
lint.per-file-ignores."*/migrat*/*" = [
# Allow using PascalCase model names in migrations
"N806",
# Ignore the fact that migration files are invalid module names
"N999",
]
lint.isort.combine-as-imports = true
lint.isort.lines-after-imports = 2
lint.mccabe.max-complexity = 15

0 comments on commit 9971261

Please sign in to comment.