Skip to content

Commit

Permalink
eslint-plugin-perfectionist (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak authored Oct 5, 2024
1 parent c12f60f commit eef8ac5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
36 changes: 18 additions & 18 deletions frontend/django_mptt_admin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "jqtree";
import * as cookie from "cookie";
import "jqtree";

interface JQTreeMoveEvent extends JQuery.Event {
move_info: {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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");
Expand All @@ -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() {
Expand All @@ -158,14 +158,14 @@ function initTree(

const spinners: Record<number | string, HTMLElement | null> = {};

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;
}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -234,8 +234,8 @@ function initTree(
}

const treeOptions: Record<string, unknown> = {
autoOpen,
autoEscape,
autoOpen,
buttonLeft: rtl,
closedIcon: rtl ? "&#x25c0;" : "&#x25ba;",
dragAndDrop: dragAndDrop && hasChangePermission,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
perfectionistPlugin.configs["recommended-natural"],
{
languageOptions: {
parserOptions: {
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eef8ac5

Please sign in to comment.