From eef8ac541425f9b0178564f3c999965b92c92168 Mon Sep 17 00:00:00 2001 From: Marco Braak Date: Sat, 5 Oct 2024 14:06:22 +0200 Subject: [PATCH] eslint-plugin-perfectionist (#579) --- frontend/django_mptt_admin.ts | 36 ++++++++++++++++----------------- frontend/eslint.config.mjs | 2 ++ frontend/package.json | 1 + frontend/pnpm-lock.yaml | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/frontend/django_mptt_admin.ts b/frontend/django_mptt_admin.ts index fe76a2eb..ec7e83ed 100644 --- a/frontend/django_mptt_admin.ts +++ b/frontend/django_mptt_admin.ts @@ -1,5 +1,5 @@ -import "jqtree"; import * as cookie from "cookie"; +import "jqtree"; interface JQTreeMoveEvent extends JQuery.Event { move_info: { @@ -25,14 +25,14 @@ interface JQTreeLoadDataEvent extends JQuery.Event { } interface Parameters { - animationSpeed: number | string | null; + animationSpeed: null | number | string; autoEscape: boolean; autoOpen: boolean | number; csrfCookieName: string; dragAndDrop: boolean; hasAddPermission: boolean; hasChangePermission: boolean; - mouseDelay: number | null; + mouseDelay: null | number; rtl: boolean; } @@ -120,17 +120,11 @@ function initTree( e.preventDefault(); void jQuery.ajax({ - type: "POST", - url: info.moved_node.move_url as string, - data, beforeSend: (xhr) => { // Set Django csrf token xhr.setRequestHeader("X-CSRFToken", getCsrfToken()); }, - success: () => { - info.do_move(); - handleLoaded(null); - }, + data, error: () => { handleLoaded(null); const $node = $el.find(".jqtree-element"); @@ -142,6 +136,12 @@ function initTree( errorNode = info.moved_node; }, + success: () => { + info.do_move(); + handleLoaded(null); + }, + type: "POST", + url: info.moved_node.move_url as string, }); function removeErrorMessage() { @@ -158,14 +158,14 @@ function initTree( const spinners: Record = {}; - function getSpinnerId(node: INode | null): string | number | null { + function getSpinnerId(node: INode | null): null | number | string { if (!node) { return "__root__"; } else { if (node.id == null) { return null; } else { - return node.id as string | number; + return node.id as number | string; } } } @@ -208,7 +208,7 @@ function initTree( function handleSelect(eventParam: JQuery.Event) { const e = eventParam as JQTreeSelectEvent; - const { node, deselected_node } = e; + const { deselected_node, node } = e; if (deselected_node) { // deselected node: remove tabindex @@ -234,8 +234,8 @@ function initTree( } const treeOptions: Record = { - autoOpen, autoEscape, + autoOpen, buttonLeft: rtl, closedIcon: rtl ? "◀" : "►", dragAndDrop: dragAndDrop && hasChangePermission, @@ -266,24 +266,24 @@ jQuery(() => { if ($tree.length) { const animationSpeed = $tree.data("tree-animation-speed") as + | null | number - | string - | null; + | string; const autoOpen = $tree.data("auto_open") as boolean | number; const autoEscape = Boolean($tree.data("autoescape")); const hasAddPermission = Boolean($tree.data("has-add-permission")); const hasChangePermission = Boolean( $tree.data("has-change-permission") ); - const mouseDelay = $tree.data("tree-mouse-delay") as number | null; + const mouseDelay = $tree.data("tree-mouse-delay") as null | number; const dragAndDrop = $tree.data("drag-and-drop") as boolean; const rtl = $tree.data("rtl") === "1"; const csrfCookieName = $tree.data("csrf-cookie-name") as string; initTree($tree, { animationSpeed, - autoOpen, autoEscape, + autoOpen, csrfCookieName, dragAndDrop, hasAddPermission, diff --git a/frontend/eslint.config.mjs b/frontend/eslint.config.mjs index a3a651ab..6c6fbc84 100644 --- a/frontend/eslint.config.mjs +++ b/frontend/eslint.config.mjs @@ -1,6 +1,7 @@ import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import importPlugin from "eslint-plugin-import"; +import perfectionistPlugin from "eslint-plugin-perfectionist"; export default [ eslint.configs.recommended, @@ -8,6 +9,7 @@ export default [ ...tseslint.configs.stylisticTypeChecked, importPlugin.flatConfigs.recommended, importPlugin.flatConfigs.typescript, + perfectionistPlugin.configs["recommended-natural"], { languageOptions: { parserOptions: { diff --git a/frontend/package.json b/frontend/package.json index 22a5e967..12a1fe85 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -39,6 +39,7 @@ "babel-plugin-istanbul": "^7.0.0", "eslint": "^9.11.1", "eslint-plugin-import": "^2.31.0", + "eslint-plugin-perfectionist": "^3.8.0", "sass": "^1.79.4", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index f41684f9..4c092591 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: eslint-plugin-import: specifier: ^2.31.0 version: 2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.11.1)(typescript@5.6.2))(eslint@9.11.1) + eslint-plugin-perfectionist: + specifier: ^3.8.0 + version: 3.8.0(eslint@9.11.1)(typescript@5.6.2) sass: specifier: ^1.79.4 version: 1.79.4 @@ -1267,6 +1270,25 @@ packages: '@typescript-eslint/parser': optional: true + eslint-plugin-perfectionist@3.8.0: + resolution: {integrity: sha512-BYJWbQVOjvIGK9V1xUfn790HuvkePjxti8epOi1H6sdzo0N4RehBmQ8coHPbgA/f12BUG1NIoDtQhI9mUm+o2A==} + engines: {node: ^18.0.0 || >=20.0.0} + peerDependencies: + astro-eslint-parser: ^1.0.2 + eslint: '>=8.0.0' + svelte: '>=3.0.0' + svelte-eslint-parser: ^0.41.1 + vue-eslint-parser: '>=9.0.0' + peerDependenciesMeta: + astro-eslint-parser: + optional: true + svelte: + optional: true + svelte-eslint-parser: + optional: true + vue-eslint-parser: + optional: true + eslint-scope@5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} @@ -1733,6 +1755,9 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + natural-compare-lite@1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -3749,6 +3774,17 @@ snapshots: - eslint-import-resolver-webpack - supports-color + eslint-plugin-perfectionist@3.8.0(eslint@9.11.1)(typescript@5.6.2): + dependencies: + '@typescript-eslint/types': 8.8.0 + '@typescript-eslint/utils': 8.8.0(eslint@9.11.1)(typescript@5.6.2) + eslint: 9.11.1 + minimatch: 9.0.5 + natural-compare-lite: 1.4.0 + transitivePeerDependencies: + - supports-color + - typescript + eslint-scope@5.1.1: dependencies: esrecurse: 4.3.0 @@ -4204,6 +4240,8 @@ snapshots: ms@2.1.3: {} + natural-compare-lite@1.4.0: {} + natural-compare@1.4.0: {} neo-async@2.6.2: {}