From de74d8a08c0d884525ee21fbe25735b8b86a730b Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Sat, 8 Feb 2025 21:20:39 -0500 Subject: [PATCH] [Lint] Lint unused imports (#493) --- eslint.config.js | 12 ++++++++++++ package-lock.json | 17 +++++++++++++++++ package.json | 5 ++++- src/CanvasPointer.ts | 1 - src/LGraphCanvas.ts | 11 ++--------- src/LGraphNode.ts | 4 ++-- src/types/events.ts | 1 - src/utils/arrange.ts | 2 +- 8 files changed, 38 insertions(+), 15 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 990aa12e6..afa4bde27 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,6 +2,7 @@ import globals from "globals" import eslint from "@eslint/js" import tseslint from "typescript-eslint" import stylistic from "@stylistic/eslint-plugin" +import unusedImports from "eslint-plugin-unused-imports" export default tseslint.config( { files: ["**/*.{js,mjs,ts,mts}"] }, @@ -161,4 +162,15 @@ export default tseslint.config( }, files: ["test/**/*.ts"], }, + { + plugins: { + "unused-imports": unusedImports, + }, + rules: { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/prefer-as-const": "off", + "unused-imports/no-unused-imports": "error", + }, + }, ) diff --git a/package-lock.json b/package-lock.json index cb7d5885e..59b05c878 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@types/eslint__js": "^8.42.3", "@types/node": "^22.1.0", "eslint": "^9.14.0", + "eslint-plugin-unused-imports": "^4.1.4", "globals": "^15.12.0", "husky": "^9.1.7", "jsdom": "^25.0.1", @@ -2696,6 +2697,22 @@ } } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.4.tgz", + "integrity": "sha512-YptD6IzQjDardkl0POxnnRBhU1OEePMV0nd6siHaRBbd+lyh6NAhFEobiznKU7kTsSsDeSD62Pe7kAM1b7dAZQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0", + "eslint": "^9.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", diff --git a/package.json b/package.json index 570892993..ab7615f9b 100755 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "preview": "vite preview", "watch": "vite build --watch", "release": "node scripts/release.js", - "test": "vitest" + "test": "vitest", + "lint": "eslint src", + "lint:fix": "eslint src --fix" }, "repository": { "type": "git", @@ -47,6 +49,7 @@ "@types/eslint__js": "^8.42.3", "@types/node": "^22.1.0", "eslint": "^9.14.0", + "eslint-plugin-unused-imports": "^4.1.4", "globals": "^15.12.0", "husky": "^9.1.7", "jsdom": "^25.0.1", diff --git a/src/CanvasPointer.ts b/src/CanvasPointer.ts index 31a03906a..e88eb40de 100644 --- a/src/CanvasPointer.ts +++ b/src/CanvasPointer.ts @@ -1,6 +1,5 @@ // @ts-strict-ignore import type { CanvasPointerEvent } from "./types/events" -import type { LGraphCanvas } from "./LGraphCanvas" import { dist2 } from "./measure" /** diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 8756c4414..8f9576dd8 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -22,7 +22,7 @@ import type { ReadOnlyPoint, ReadOnlyRect, } from "./interfaces" -import type { IBaseWidget, IWidget, TWidgetValue } from "./types/widgets" +import type { IWidget } from "./types/widgets" import { LGraphNode, type NodeId } from "./LGraphNode" import type { CanvasDragEvent, @@ -59,21 +59,14 @@ import { } from "./measure" import { LabelPosition, strokeShape } from "./draw" import { DragAndScale } from "./DragAndScale" -import { LinkReleaseContextExtended, LiteGraph, clamp } from "./litegraph" +import { LinkReleaseContextExtended, LiteGraph } from "./litegraph" import { stringOrEmpty, stringOrNull } from "./strings" import { alignNodes, distributeNodes, getBoundaryNodes } from "./utils/arrange" import { Reroute, type RerouteId } from "./Reroute" import { getAllNestedItems, findFirstNode } from "./utils/collections" import { CanvasPointer } from "./CanvasPointer" -import { BooleanWidget } from "./widgets/BooleanWidget" import { toClass } from "./utils/type" import { NodeInputSlot, NodeOutputSlot, type ConnectionColorContext } from "./NodeSlot" -import { ComboWidget } from "./widgets/ComboWidget" -import { NumberWidget } from "./widgets/NumberWidget" -import { ButtonWidget } from "./widgets/ButtonWidget" -import { TextWidget } from "./widgets/TextWidget" -import { SliderWidget } from "./widgets/SliderWidget" -import { BaseWidget } from "./widgets/BaseWidget" import { WIDGET_TYPE_MAP } from "./widgets/widgetMap" interface IShowSearchOptions { diff --git a/src/LGraphNode.ts b/src/LGraphNode.ts index ac78c38ca..a176820ff 100644 --- a/src/LGraphNode.ts +++ b/src/LGraphNode.ts @@ -16,12 +16,12 @@ import type { Size, } from "./interfaces" import type { LGraph } from "./LGraph" -import type { IWidget, TWidgetType, TWidgetValue } from "./types/widgets" +import type { IWidget, TWidgetValue } from "./types/widgets" import type { ISerialisedNode } from "./types/serialisation" import type { LGraphCanvas } from "./LGraphCanvas" import type { CanvasMouseEvent } from "./types/events" import type { DragAndScale } from "./DragAndScale" -import type { Reroute, RerouteId } from "./Reroute" +import type { RerouteId } from "./Reroute" import { LGraphEventMode, NodeSlotType, diff --git a/src/types/events.ts b/src/types/events.ts index 8fcc43720..ec9893a74 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -6,7 +6,6 @@ import type { ConnectingLink, LinkReleaseContextExtended } from "../litegraph" import type { IWidget } from "./widgets" import type { LGraphNode } from "../LGraphNode" import type { LGraphGroup } from "../LGraphGroup" -import type { LGraphCanvas } from "../LGraphCanvas" /** For Canvas*Event - adds graph space co-ordinates (property names are shipped) */ export interface ICanvasPosition { diff --git a/src/utils/arrange.ts b/src/utils/arrange.ts index 1088ae420..847461cd8 100644 --- a/src/utils/arrange.ts +++ b/src/utils/arrange.ts @@ -1,4 +1,4 @@ -import type { Dictionary, Direction, IBoundaryNodes } from "../interfaces" +import type { Direction, IBoundaryNodes } from "../interfaces" import type { LGraphNode } from "../LGraphNode" /**