瀏覽代碼

Update eslint

JC Brand 1 月之前
父節點
當前提交
ca1d28a050
共有 5 個文件被更改,包括 448 次插入411 次删除
  1. 101 103
      eslint.config.mjs
  2. 337 299
      package-lock.json
  3. 6 3
      package.json
  4. 0 2
      src/log/index.js
  5. 4 4
      src/utils/html.js

+ 101 - 103
.eslintrc.json → eslint.config.mjs

@@ -1,30 +1,51 @@
-{
-    "parser": "@typescript-eslint/parser",
-    "parserOptions": {
-        "ecmaVersion": 2020,
-        "sourceType": "module",
-        "allowImportExportEverywhere": true
-    },
-    "env": {
-        "browser": true,
-        "jasmine": true,
-        "es6": true
-    },
-    "plugins": ["@typescript-eslint"],
-    "extends": [
+import { defineConfig } from "eslint/config";
+import typescriptEslint from "@typescript-eslint/eslint-plugin";
+import globals from "globals";
+import tsParser from "@typescript-eslint/parser";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import js from "@eslint/js";
+import { FlatCompat } from "@eslint/eslintrc";
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const compat = new FlatCompat({
+    baseDirectory: __dirname,
+    recommendedConfig: js.configs.recommended,
+    allConfig: js.configs.all
+});
+
+export default defineConfig([{
+    extends: compat.extends(
         "eslint:recommended",
         "plugin:@typescript-eslint/eslint-recommended",
-        "plugin:@typescript-eslint/recommended"
-    ],
-    "globals": {
-        "Uint8Array": true,
-        "Promise": true,
-        "define": true,
-        "require": true,
-        "sinon": true,
-        "window": true
+        "plugin:@typescript-eslint/recommended",
+    ),
+
+    plugins: {
+        "@typescript-eslint": typescriptEslint,
+    },
+
+    languageOptions: {
+        globals: {
+            ...globals.browser,
+            ...globals.jasmine,
+            Uint8Array: true,
+            Promise: true,
+            define: true,
+            require: true,
+            sinon: true,
+            window: true,
+        },
+        parser: tsParser,
+        ecmaVersion: 2020,
+        sourceType: "module",
+        parserOptions: {
+            allowImportExportEverywhere: true,
+        },
     },
-    "rules": {
+
+    rules: {
         "accessor-pairs": "error",
         "array-bracket-spacing": "off",
         "array-callback-return": "error",
@@ -35,33 +56,26 @@
         "block-spacing": "off",
         "brace-style": "off",
         "callback-return": "off",
-        "camelcase": "off",
+        camelcase: "off",
         "capitalized-comments": "off",
         "class-methods-use-this": "off",
         "comma-dangle": "off",
         "comma-spacing": "off",
         "comma-style": "off",
-        "complexity": "off",
-        "computed-property-spacing": [
-            "error",
-            "never"
-        ],
+        complexity: "off",
+        "computed-property-spacing": ["error", "never"],
         "consistent-return": "off",
         "consistent-this": "off",
-        "curly": "off",
+        curly: "off",
         "default-case": "off",
-        "dot-location": [
-            "error",
-            "property"
-        ],
-        "dot-notation": [
-            "off",
-            {
-                "allowKeywords": true
-            }
-        ],
+        "dot-location": ["error", "property"],
+
+        "dot-notation": ["off", {
+            allowKeywords: true,
+        }],
+
         "eol-last": "error",
-        "eqeqeq": "off",
+        eqeqeq: "off",
         "func-call-spacing": "off",
         "no-spaced-func": "off",
         "no-redeclare": "off",
@@ -75,25 +89,24 @@
         "id-blacklist": "error",
         "id-length": "off",
         "id-match": "error",
-        "indent": "off",
+        indent: "off",
         "init-declarations": "off",
         "jsx-quotes": "error",
         "key-spacing": "off",
         "keyword-spacing": "off",
         "line-comment-position": "off",
-        "linebreak-style": [
-            "error",
-            "unix"
-        ],
+        "linebreak-style": ["error", "unix"],
         "lines-around-comment": "off",
         "lines-around-directive": "off",
         "max-depth": "error",
+
         "max-len": ["error", {
-            "code": 120,
-            "ignoreStrings": true,
-            "ignoreComments": true,
-            "ignoreUrls": true
+            code: 120,
+            ignoreStrings: true,
+            ignoreComments: true,
+            ignoreUrls: true,
         }],
+
         "max-lines": "off",
         "max-nested-callbacks": "off",
         "max-params": "off",
@@ -111,10 +124,7 @@
         "no-caller": "error",
         "no-console": "off",
         "no-catch-shadow": "off",
-        "no-cond-assign": [
-            "off",
-            "except-parens"
-        ],
+        "no-cond-assign": ["off", "except-parens"],
         "no-confusing-arrow": "off",
         "no-continue": "off",
         "no-div-regex": "error",
@@ -131,10 +141,7 @@
         "no-implicit-globals": "off",
         "no-implied-eval": "error",
         "no-inline-comments": "off",
-        "no-inner-declarations": [
-            "error",
-            "functions"
-        ],
+        "no-inner-declarations": ["error", "functions"],
         "no-invalid-this": "off",
         "no-iterator": "error",
         "no-label-var": "error",
@@ -189,19 +196,21 @@
         "no-underscore-dangle": "off",
         "no-unmodified-loop-condition": "error",
         "no-unneeded-ternary": "off",
-        "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
-        "@typescript-eslint/no-unused-vars": [
-            "error",
-            {
-                "args": "all",
-                "argsIgnorePattern": "^_",
-                "caughtErrors": "all",
-                "caughtErrorsIgnorePattern": "^_",
-                "destructuredArrayIgnorePattern": "^_",
-                "varsIgnorePattern": "^_",
-                "ignoreRestSiblings": true
-            }
-        ],
+
+        "no-unused-vars": ["error", {
+            argsIgnorePattern: "^_",
+        }],
+
+        "@typescript-eslint/no-unused-vars": ["error", {
+            args: "all",
+            argsIgnorePattern: "^_",
+            caughtErrors: "all",
+            caughtErrorsIgnorePattern: "^_",
+            destructuredArrayIgnorePattern: "^_",
+            varsIgnorePattern: "^_",
+            ignoreRestSiblings: true,
+        }],
+
         "no-unused-expressions": "off",
         "no-use-before-define": "off",
         "no-useless-call": "error",
@@ -219,12 +228,11 @@
         "no-with": "error",
         "object-curly-newline": "off",
         "object-curly-spacing": "off",
-        "object-property-newline": [
-            "off",
-            {
-                "allowMultiplePropertiesPerLine": true
-            }
-        ],
+
+        "object-property-newline": ["off", {
+            allowMultiplePropertiesPerLine: true,
+        }],
+
         "object-shorthand": "off",
         "one-var": "off",
         "one-var-declaration-per-line": "off",
@@ -233,13 +241,12 @@
         "padded-blocks": "off",
         "prefer-arrow-callback": "off",
         "prefer-const": "error",
-        "prefer-destructuring": [
-            "error",
-            {
-                "array": false,
-                "object": false
-            }
-        ],
+
+        "prefer-destructuring": ["error", {
+            array: false,
+            object: false,
+        }],
+
         "prefer-numeric-literals": "error",
         "prefer-promise-reject-errors": "off",
         "prefer-reflect": "off",
@@ -247,16 +254,13 @@
         "prefer-spread": "off",
         "prefer-template": "off",
         "quote-props": "off",
-        "quotes": "off",
-        "radix": [
-            "error",
-            "always"
-        ],
+        quotes: "off",
+        radix: ["error", "always"],
         "require-atomic-updates": "off",
         "require-await": "error",
         "require-jsdoc": "off",
         "rest-spread-spacing": "error",
-        "semi": "off",
+        semi: "off",
         "semi-spacing": "off",
         "sort-imports": "off",
         "sort-keys": "off",
@@ -267,21 +271,15 @@
         "space-infix-ops": "off",
         "space-unary-ops": "off",
         "spaced-comment": "off",
-        "strict": "off",
+        strict: "off",
         "symbol-description": "error",
         "template-curly-spacing": "off",
-        "unicode-bom": [
-            "error",
-            "never"
-        ],
+        "unicode-bom": ["error", "never"],
         "valid-jsdoc": "off",
         "vars-on-top": "off",
-        "wrap-iife": [
-            "error",
-            "any"
-        ],
+        "wrap-iife": ["error", "any"],
         "wrap-regex": "error",
         "yield-star-spacing": "error",
-        "yoda": "off"
-    }
-}
+        yoda: "off",
+    },
+}]);

File diff suppressed because it is too large
+ 337 - 299
package-lock.json


+ 6 - 3
package.json

@@ -78,20 +78,23 @@
     "@babel/core": "^7.18.5",
     "@babel/preset-env": "^7.18.2",
     "@converse/headless": "file:src/headless",
+    "@eslint/eslintrc": "^3.3.1",
+    "@eslint/js": "^9.24.0",
     "@types/bootstrap": "^5.2.10",
     "@types/lodash-es": "^4.17.12",
     "@types/sizzle": "^2.3.8",
     "@types/webappsec-credential-management": "^0.6.8",
-    "@typescript-eslint/eslint-plugin": "^7.12.0",
-    "@typescript-eslint/parser": "^7.12.0",
+    "@typescript-eslint/eslint-plugin": "^8.29.0",
+    "@typescript-eslint/parser": "^8.29.0",
     "autoprefixer": "^10.4.5",
     "babel-loader": "^9.1.0",
     "circular-dependency-plugin": "^5.2.2",
     "clean-css-cli": "^5.6.2",
     "copy-webpack-plugin": "^12.0.2",
     "css-loader": "^7.1.2",
-    "eslint": "^8.57.0",
+    "eslint": "^9.24.0",
     "fast-text-encoding": "^1.0.3",
+    "globals": "^16.0.0",
     "http-server": "^14.1.0",
     "imports-loader": "^5.0.0",
     "install": "^0.13.0",

+ 0 - 2
src/log/index.js

@@ -9,7 +9,6 @@ export const LEVELS = {
     fatal: 4,
 };
 
-/* eslint-disable @typescript-eslint/no-empty-function */
 const logger = Object.assign(
     {
         debug: console?.log ? console.log.bind(console) : function noop() {},
@@ -19,7 +18,6 @@ const logger = Object.assign(
     },
     console
 );
-/* eslint-enable @typescript-eslint/no-empty-function */
 
 /**
  * Logs messages to the console.

+ 4 - 4
src/utils/html.js

@@ -189,7 +189,7 @@ export function hasClass (className, el) {
  * @param {Element} el
  */
 export function addClass (className, el) {
-    el instanceof Element && el.classList.add(className);
+    if (el instanceof Element) el.classList.add(className);
     return el;
 }
 
@@ -199,7 +199,7 @@ export function addClass (className, el) {
  * @param {Element} el
  */
 export function removeClass (className, el) {
-    el instanceof Element && el.classList.remove(className);
+    if (el instanceof Element) el.classList.remove(className);
     return el;
 }
 
@@ -208,7 +208,7 @@ export function removeClass (className, el) {
  * @param {Element} el
  */
 export function removeElement (el) {
-    el instanceof Element && el.parentNode && el.parentNode.removeChild(el);
+    if (el instanceof Element && el.parentNode) el.parentNode.removeChild(el);
     return el;
 }
 
@@ -233,7 +233,7 @@ function showElement (el) {
  * @param {Element} el
  */
 function hideElement (el) {
-    el instanceof Element && el.classList.add('hidden');
+    if (el instanceof Element) el.classList.add('hidden');
     return el;
 }
 

Some files were not shown because too many files changed in this diff