From 68777ec421d41be0da27013afd4165ae7d658d26 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 23:17:25 +0530 Subject: refactor: added linting with esling and also resolved warnings for it --- eslint.config.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 eslint.config.js (limited to 'eslint.config.js') diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..4f528f4 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,96 @@ +import js from "@eslint/js"; +import stylistic from "@stylistic/eslint-plugin"; +import importX from "eslint-plugin-import-x"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + +export default tseslint.config( + { + ignores: [ + "**/dist/**", + "**/node_modules/**", + "**/*.wasm.js", + "**/static/**" + ] + }, + + js.configs.recommended, + + ...tseslint.configs.strictTypeChecked, + ...tseslint.configs.stylisticTypeChecked, + + stylistic.configs.recommended, + + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.webextensions + }, + parserOptions: { + projectService: true, + tsconfigRootDir: import.meta.dirname + } + }, + + plugins: { + "import-x": importX + }, + + rules: { + "@stylistic/indent": ["error", "tab"], + "@stylistic/quotes": ["error", "double"], + "@stylistic/semi": ["error", "always"], + "@stylistic/comma-dangle": ["error", "never"], + "@stylistic/max-len": ["warn", { code: 120, ignoreUrls: true, ignoreStrings: true, ignoreTemplateLiterals: true }], + "@stylistic/arrow-parens": ["error", "always"], + "@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }], + "@stylistic/no-multiple-empty-lines": ["error", { max: 1, maxEOF: 1 }], + "@stylistic/no-trailing-spaces": "error", + "@stylistic/eol-last": ["error", "always"], + "@stylistic/no-tabs": "off", + "@stylistic/space-before-function-paren": ["error", "never"], + "@stylistic/member-delimiter-style": ["error", { multiline: { delimiter: "semi", requireLast: false }, singleline: { delimiter: "semi", requireLast: false } }], + + "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_" }], + "@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true, allowTypedFunctionExpressions: true }], + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/prefer-readonly": "warn", + "@typescript-eslint/consistent-type-definitions": ["error", "type"], + "@typescript-eslint/method-signature-style": ["error", "property"], + + "no-console": "warn", + "no-alert": "error", + + "import-x/order": ["error", { + "groups": ["builtin", "external", "internal", ["parent", "sibling"], "index"], + "newlines-between": "always", + "alphabetize": { order: "asc", orderImportKind: "asc" } + }], + "import-x/no-duplicates": "error", + "import-x/first": "error", + "import-x/newline-after-import": "error" + } + }, + + { + files: ["**/*.js"], + ...tseslint.configs.disableTypeChecked + }, + + { + files: ["webpack.config.js", "config/**/*.js"], + languageOptions: { + globals: { + ...globals.node, + ROOT_DIR: "writable", + CONFIG_DIR: "writable", + SOURCE_DIR: "writable", + production: "writable" + } + }, + rules: { + "no-console": "off" + } + } +); -- cgit v1.2.3 From dfba7ff6fff7bde33b40a343a2318b35c429b40f Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 23:28:46 +0530 Subject: refactor: fixed all of the eslint warnings and errors --- .../webpack/loader/arrange-shared-module-loader.js | 6 ++- ...reate-injected-shared-modules-webpack-plugin.js | 1 + .../create-manifest-webpack-plugin/index.js | 1 + .../webpack/plugins/create-rules-webpack-plugin.js | 1 + .../plugins/inject-script-webpack-plugin.js | 7 ++- eslint.config.js | 11 ++++- src/scripts/common/stop-blocking.ts | 53 ++++++++++++++++------ 7 files changed, 60 insertions(+), 20 deletions(-) (limited to 'eslint.config.js') diff --git a/config/webpack/loader/arrange-shared-module-loader.js b/config/webpack/loader/arrange-shared-module-loader.js index 31c5d61..63fd62d 100644 --- a/config/webpack/loader/arrange-shared-module-loader.js +++ b/config/webpack/loader/arrange-shared-module-loader.js @@ -27,7 +27,11 @@ export default function(source) { if (moduleIndex >= 0) { const currentSharedModuleName = sharedModules[moduleIndex]; - if (!(sortedSharedModules.includes(currentSharedModuleName) || modulesToBeIncluded.includes(currentSharedModuleName))) { + const alreadyIncluded = ( + sortedSharedModules.includes(currentSharedModuleName) + || modulesToBeIncluded.includes(currentSharedModuleName)); + + if (!alreadyIncluded) { modulesToBeIncluded.push(currentSharedModuleName); } } diff --git a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js index 6cd8523..c94ae86 100644 --- a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js +++ b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js @@ -21,6 +21,7 @@ class CreateInjectedSharedModulesPlugin { /** * @param {import("webpack").Compiler} compiler + * @returns {void} */ apply(compiler) { compiler.hooks.compilation.tap("CreateInjectedSharedModulesPlugin", (compilation) => { diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index f5a4963..95d0be8 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -38,6 +38,7 @@ class CreateManifestPlugin { /** * @param {import("webpack").Compiler} compiler + * @returns {void} */ apply(compiler) { compiler.hooks.compilation.tap("CreateManifestPlugin", (compilation) => { diff --git a/config/webpack/plugins/create-rules-webpack-plugin.js b/config/webpack/plugins/create-rules-webpack-plugin.js index 10e5fdd..ce2fbef 100644 --- a/config/webpack/plugins/create-rules-webpack-plugin.js +++ b/config/webpack/plugins/create-rules-webpack-plugin.js @@ -11,6 +11,7 @@ import webpack from "webpack"; class CreateRulesPlugin { /** * @param {import("webpack").Compiler} compiler + * @returns {void} */ apply(compiler) { compiler.hooks.compilation.tap("CreateRulesPlugin", (compilation) => { diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js index 0a5d784..16b2e98 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin.js +++ b/config/webpack/plugins/inject-script-webpack-plugin.js @@ -14,6 +14,7 @@ import { getInjectedCode } from "../utils/injected-code.js"; class InjectScriptPlugin { /** * @param {import("webpack").Compiler} compiler + * @returns {void} */ apply(compiler) { compiler.hooks.compilation.tap("InjectScriptPlugin", (compilation) => { @@ -26,14 +27,16 @@ class InjectScriptPlugin { async(assets) => { for (const assetName in assets) { if (/\.js$/.test(assetName)) { - const injectedCodeResponse = getInjectedCode(compilation.getAsset(assetName).source.source()); + const assetSource = compilation.getAsset(assetName).source.source(); + const injectedCodeResponse = getInjectedCode(assetSource); const scriptInjectorModuleName = getFileName("script-injector", "shared", true); compilation.updateAsset( assetName, new webpack.sources.RawSource(injectedCodeResponse[0]) ); + const injectedFileName = `scripts/injected/${path.basename(assetName)}`; assets["scripts/" + path.basename(assetName)] = new webpack.sources.RawSource( - `$${scriptInjectorModuleName}.injectScriptHead("scripts/injected/${path.basename(assetName)}", ${injectedCodeResponse[1]});` + `$${scriptInjectorModuleName}.injectScriptHead("${injectedFileName}", ${injectedCodeResponse[1]});` ); } } diff --git a/eslint.config.js b/eslint.config.js index 4f528f4..adbbe97 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -75,11 +75,16 @@ export default tseslint.config( { files: ["**/*.js"], - ...tseslint.configs.disableTypeChecked + ...tseslint.configs.disableTypeChecked, + rules: { + ...tseslint.configs.disableTypeChecked.rules, + "@typescript-eslint/explicit-function-return-type": "off" + } }, { files: ["webpack.config.js", "config/**/*.js"], + ...tseslint.configs.disableTypeChecked, languageOptions: { globals: { ...globals.node, @@ -90,7 +95,9 @@ export default tseslint.config( } }, rules: { - "no-console": "off" + ...tseslint.configs.disableTypeChecked.rules, + "no-console": "off", + "@typescript-eslint/explicit-function-return-type": "off" } } ); diff --git a/src/scripts/common/stop-blocking.ts b/src/scripts/common/stop-blocking.ts index bdebfe9..8588834 100644 --- a/src/scripts/common/stop-blocking.ts +++ b/src/scripts/common/stop-blocking.ts @@ -4,26 +4,49 @@ * is disabled. Reverts the prototypes after patching to avoid * interfering with other code. */ + +type JQueryBindFn = ( + eventName: string, + handler: (event: JQuery.Event) => unknown +) => JQuery; + +type JQueryKeydownFn = ( + handler: (event: JQuery.Event) => unknown +) => JQuery; + +type JQueryPrototypeShape = { + bind: JQueryBindFn; + keydown: JQueryKeydownFn +}; + +const jQueryPrototype = $.prototype as unknown as JQueryPrototypeShape; + document.addEventListener("DOMContentLoaded", () => { - const proxiedBind = $.prototype.bind; + const proxiedBind = jQueryPrototype.bind; /** Proxies jQuery `.bind()` to no-op the `"cut copy paste"` event. */ - $.prototype.bind = function() { - if (arguments[0].trim() === "cut copy paste") { - arguments[1] = (_: any) => {}; - } - - return proxiedBind.apply(this, Array.from(arguments) as any); + jQueryPrototype.bind = function( + this: JQuery, + ...args: Parameters + ): JQuery { + const [eventName, handler] = args; + const noop = (): undefined => undefined; + return proxiedBind.call( + this, + eventName, + eventName.trim() === "cut copy paste" ? noop : handler + ); }; - const proxiedKeydown = $.prototype.keydown; + const proxiedKeydown = jQueryPrototype.keydown; /** Proxies jQuery `.keydown()` so all key presses are allowed. */ - $.prototype.keydown = function() { - arguments[0] = (_: any) => true; - - return proxiedKeydown.apply(this, Array.from(arguments) as any); + jQueryPrototype.keydown = function( + this: JQuery, + ..._args: Parameters + ): JQuery { + return proxiedKeydown.call(this, () => true); }; - $.prototype.bind = proxiedBind; - $.prototype.keydown = proxiedKeydown; - document.oncontextmenu = () => true; + jQueryPrototype.bind = proxiedBind; + jQueryPrototype.keydown = proxiedKeydown; + document.oncontextmenu = (): boolean => true; }); -- cgit v1.2.3