From b4688e18f96f5022ccdb98460c79aa72729112eb Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Fri, 28 Feb 2025 19:53:29 +1100 Subject: [PATCH] [Refactor] Prefer includes over indexOf -1 (#646) Enables ESLint auto-fix rule. --- eslint.config.js | 1 - src/LGraphCanvas.ts | 6 +++--- src/LiteGraphGlobal.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index dbb73d8a8..f09f0abff 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -71,7 +71,6 @@ export default tseslint.config( "unicorn/prefer-structured-clone": "off", "unicorn/prefer-switch": "off", "unicorn/prefer-ternary": "off", - "unicorn/prefer-includes": "off", // Disable rules "unicorn/consistent-function-scoping": "off", diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 7d517beb4..69a2c8f2e 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -836,7 +836,7 @@ export class LGraphCanvas implements ConnectionColorContext { : base_category + category_name + "/" let name = category_name - if (name.indexOf("::") != -1) + if (name.includes("::")) // in case it has a namespace like "shader::math/rand" it hides the namespace name = name.split("::")[1] @@ -6493,8 +6493,8 @@ export class LGraphCanvas implements ConnectionColorContext { if (filter && ctor.filter != filter) return false if ( (!options.show_all_if_empty || str) && - type.toLowerCase().indexOf(str) === -1 && - (!ctor.title || ctor.title.toLowerCase().indexOf(str) === -1) + !type.toLowerCase().includes(str) && + (!ctor.title || !ctor.title.toLowerCase().includes(str)) ) { return false } diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index abbe9af92..c11b1b7e4 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -613,7 +613,7 @@ export class LiteGraphGlobal { type_b = type_b.toLowerCase() // For nodes supporting multiple connection types - if (type_a.indexOf(",") == -1 && type_b.indexOf(",") == -1) + if (!type_a.includes(",") && !type_b.includes(",")) return type_a == type_b // Check all permutations to see if one is valid