From 86acc01b1a6fc5759d43dd3463d66ef4a5ee8888 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 24 Aug 2025 20:02:59 +0800 Subject: [PATCH] WebUI: prefer `Number` static properties over global ones `Number` purpose is modularization of globals in ECMAScript 2015. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt#number.parseint_vs._parseint --- src/webui/www/eslint.config.mjs | 9 ++++++--- src/webui/www/package.json | 1 + src/webui/www/private/scripts/client.js | 2 +- src/webui/www/private/scripts/dynamicTable.js | 2 +- src/webui/www/private/views/preferences.html | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/webui/www/eslint.config.mjs b/src/webui/www/eslint.config.mjs index 7cf569fb5..ac5d1b1b9 100644 --- a/src/webui/www/eslint.config.mjs +++ b/src/webui/www/eslint.config.mjs @@ -3,8 +3,9 @@ import Html from "eslint-plugin-html"; import Js from "@eslint/js"; import PluginQbtWebUI from "eslint-plugin-qbt-webui"; import PreferArrowFunctions from "eslint-plugin-prefer-arrow-functions"; -import Stylistic from "@stylistic/eslint-plugin"; import * as RegexpPlugin from "eslint-plugin-regexp"; +import Stylistic from "@stylistic/eslint-plugin"; +import Unicorn from "eslint-plugin-unicorn"; export default [ Js.configs.recommended, @@ -27,7 +28,8 @@ export default [ PluginQbtWebUI, PreferArrowFunctions, RegexpPlugin, - Stylistic + Stylistic, + Unicorn }, rules: { "curly": ["error", "multi-or-nest", "consistent"], @@ -65,7 +67,8 @@ export default [ ], "Stylistic/quote-props": ["error", "consistent-as-needed"], "Stylistic/semi": "error", - "Stylistic/spaced-comment": ["error", "always", { exceptions: ["*"] }] + "Stylistic/spaced-comment": ["error", "always", { exceptions: ["*"] }], + "Unicorn/prefer-number-properties": "error" } } ]; diff --git a/src/webui/www/package.json b/src/webui/www/package.json index 102ecb818..4e301b0a8 100644 --- a/src/webui/www/package.json +++ b/src/webui/www/package.json @@ -17,6 +17,7 @@ "eslint-plugin-prefer-arrow-functions": "*", "eslint-plugin-qbt-webui": "https://github.com/Chocobo1/eslint-plugin-qbt-webui/tarball/v1", "eslint-plugin-regexp": "*", + "eslint-plugin-unicorn": "*", "happy-dom": "*", "html-validate": "*", "js-beautify": "*", diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index adfd2ba96..f65393d35 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1618,7 +1618,7 @@ window.addEventListener("DOMContentLoaded", (event) => { }, column: "mainColumn", onResize: window.qBittorrent.Misc.createDebounceHandler(500, (e) => { - const isHidden = (parseInt(document.getElementById("propertiesPanel").style.height, 10) === 0); + const isHidden = (Number.parseInt(document.getElementById("propertiesPanel").style.height, 10) === 0); if (!isHidden) saveColumnSizes(); }), diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index e3ec5d413..2324ee50e 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -285,7 +285,7 @@ window.qBittorrent.DynamicTable ??= (() => { const onStart = function(el, event) { if (this.canResize) { this.currentHeaderAction = "resize"; - this.startWidth = parseInt(this.resizeTh.style.width, 10); + this.startWidth = Number.parseInt(this.resizeTh.style.width, 10); } else { this.currentHeaderAction = "drag"; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 80b089459..2ccbdec83 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -2928,7 +2928,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD let maxRatio = -1; if (document.getElementById("maxRatioCheckbox").checked) { maxRatio = Number(document.getElementById("maxRatioValue").value); - if (isNaN(maxRatio) || (maxRatio < 0)) { + if (Number.isNaN(maxRatio) || (maxRatio < 0)) { alert("QBT_TR(Share ratio limit must not have a negative value.)QBT_TR[CONTEXT=HttpServer]"); return; }