From e6d14e54be18757a44baead487ae964ce573a75f Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Tue, 22 Oct 2024 15:33:19 +0200 Subject: [PATCH] chore(eslint): migrate config file --- .eslintrc.json | 30 -------------- __tests__/.eslintrc.json | 11 ------ editor/js/editable-wat.ts | 1 - editor/js/editor-libs/console.ts | 3 +- eslint.config.mjs | 67 ++++++++++++++++++++++++++++++++ package-lock.json | 62 +++++++++++++++++++++++++---- package.json | 8 ++-- watify/pkg/watify.d.ts | 2 - watify/pkg/watify_bg.wasm.d.ts | 2 - 9 files changed, 128 insertions(+), 58 deletions(-) delete mode 100644 .eslintrc.json delete mode 100644 __tests__/.eslintrc.json create mode 100644 eslint.config.mjs diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 91b96b8d1..000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "env": { - "es6": true, - "browser": true, - "node": true - }, - "plugins": ["@typescript-eslint", "import"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:import/errors", - "plugin:import/typescript", - "prettier" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module" - }, - "rules": { - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-expressions": "error" - }, - "settings": { - "import/resolver": { - "typescript": true, - "node": true - } - } -} diff --git a/__tests__/.eslintrc.json b/__tests__/.eslintrc.json deleted file mode 100644 index 1274383e5..000000000 --- a/__tests__/.eslintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": ["jest"], - "env": { - "es6": true, - "node": true, - "jest": true - }, - "globals": { - "page": true - } -} diff --git a/editor/js/editable-wat.ts b/editor/js/editable-wat.ts index fe7adb098..7010a3038 100644 --- a/editor/js/editable-wat.ts +++ b/editor/js/editable-wat.ts @@ -239,7 +239,6 @@ import { // using an async function since WebAssembly.instantiate is async and // we need to await in order to capture errors const AsyncFunction = Object.getPrototypeOf( - // eslint-disable-next-line @typescript-eslint/no-empty-function async function () {}, ).constructor; await new AsyncFunction(exampleCode)(); diff --git a/editor/js/editor-libs/console.ts b/editor/js/editor-libs/console.ts index 0e3b4565d..fba874a6b 100644 --- a/editor/js/editor-libs/console.ts +++ b/editor/js/editor-libs/console.ts @@ -5,7 +5,7 @@ export default function (targetWindow?: Window & typeof globalThis) { /* Getting reference to console, either from current window or from the iframe window */ const console = targetWindow ? targetWindow.console : window.console; - const originalConsoleLogger = console.log; // eslint-disable-line no-console + const originalConsoleLogger = console.log; const originalConsoleError = console.error; console.error = function (loggedItem: any, ...otherArgs: any[]) { @@ -14,7 +14,6 @@ export default function (targetWindow?: Window & typeof globalThis) { originalConsoleError.apply(console, [loggedItem, ...otherArgs]); }; - // eslint-disable-next-line no-console console.log = function (...args) { const formattedList = []; for (let i = 0, l = args.length; i < l; i++) { diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..60281cdcd --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,67 @@ +import { + fixupConfigRules, + fixupPluginRules, + includeIgnoreFile, +} from "@eslint/compat"; +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import _import from "eslint-plugin-import"; +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, +}); +const prettierignorePath = path.resolve(__dirname, ".prettierignore"); + +export default [ + includeIgnoreFile(prettierignorePath), + ...fixupConfigRules( + compat.extends( + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:import/errors", + "plugin:import/typescript", + "plugin:jest/recommended", + "prettier", + ), + ), + { + plugins: { + "@typescript-eslint": fixupPluginRules(typescriptEslint), + import: fixupPluginRules(_import), + }, + + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + ...globals.jest, + page: true, + }, + + parser: tsParser, + ecmaVersion: 2020, + sourceType: "module", + }, + + settings: { + "import/resolver": { + typescript: true, + node: true, + }, + }, + + rules: { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-expressions": "error", + }, + }, +]; diff --git a/package-lock.json b/package-lock.json index dca851298..ebd0dd741 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "devDependencies": { "@babel/core": "^7.20.2", "@babel/eslint-parser": "^7.19.1", + "@eslint/compat": "^1.2.1", "@swc/core": "^1.3.38", "@types/clean-css": "^4.2.9", "@types/fs-extra": "^11.0.3", @@ -53,7 +54,8 @@ "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.29.0", - "eslint-plugin-jest": "^28.2.0", + "eslint-plugin-jest": "^28.8.3", + "globals": "^15.11.0", "http-server": "14.1.1", "husky": "^9.0.11", "jest": "29.7.0", @@ -824,6 +826,24 @@ "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, + "node_modules/@eslint/compat": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@eslint/compat/-/compat-1.2.1.tgz", + "integrity": "sha512-JbHG2TWuCeNzh87fXo+/46Z1LEo9DBA9T188d0fZgGxAD+cNyS6sx9fdiyxjGPBMyQVRlCutTByZ6a5+YMkF7g==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "peerDependencies": { + "eslint": "^9.10.0" + }, + "peerDependenciesMeta": { + "eslint": { + "optional": true + } + } + }, "node_modules/@eslint/config-array": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", @@ -899,6 +919,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { "version": "9.13.0", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.13.0.tgz", @@ -5360,6 +5393,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.3.tgz", "integrity": "sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" }, @@ -6315,10 +6349,11 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "15.11.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.11.0.tgz", + "integrity": "sha512-yeyNSjdbyVaWurlwCpcA6XNBrHTMIeDdj0/hnvX/OLJ9ekOXYbLsLinH/MucQyGvNnXhidTdNhTtJaffL2sMfw==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" }, @@ -13887,6 +13922,13 @@ "integrity": "sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==", "dev": true }, + "@eslint/compat": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@eslint/compat/-/compat-1.2.1.tgz", + "integrity": "sha512-JbHG2TWuCeNzh87fXo+/46Z1LEo9DBA9T188d0fZgGxAD+cNyS6sx9fdiyxjGPBMyQVRlCutTByZ6a5+YMkF7g==", + "dev": true, + "requires": {} + }, "@eslint/config-array": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", @@ -13937,6 +13979,12 @@ "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^4.1.0" } + }, + "globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true } } }, @@ -17891,9 +17939,9 @@ } }, "globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "15.11.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.11.0.tgz", + "integrity": "sha512-yeyNSjdbyVaWurlwCpcA6XNBrHTMIeDdj0/hnvX/OLJ9ekOXYbLsLinH/MucQyGvNnXhidTdNhTtJaffL2sMfw==", "dev": true }, "globalthis": { diff --git a/package.json b/package.json index 24d340172..67498d594 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,8 @@ "start-server": "http-server -p 4444 ./docs", "format": "prettier --ignore-unknown --check \"**/*\"", "format:fix": "prettier --ignore-unknown --write \"**/*\"", - "lint": "eslint --ignore-path .prettierignore .", - "lint:fix": "eslint --ignore-path .prettierignore --fix .", + "lint": "eslint .", + "lint:fix": "eslint --fix .", "fix": "npm run format:fix && npm run lint:fix", "test": "npm run prepack && npm run format && npm run lint && npm run jest", "jest": "cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs NODE_OPTIONS=--experimental-vm-modules jest", @@ -86,6 +86,7 @@ "devDependencies": { "@babel/core": "^7.20.2", "@babel/eslint-parser": "^7.19.1", + "@eslint/compat": "^1.2.1", "@swc/core": "^1.3.38", "@types/clean-css": "^4.2.9", "@types/fs-extra": "^11.0.3", @@ -98,7 +99,8 @@ "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.29.0", - "eslint-plugin-jest": "^28.2.0", + "eslint-plugin-jest": "^28.8.3", + "globals": "^15.11.0", "http-server": "14.1.1", "husky": "^9.0.11", "jest": "29.7.0", diff --git a/watify/pkg/watify.d.ts b/watify/pkg/watify.d.ts index 4e996ac0b..c62d690a7 100644 --- a/watify/pkg/watify.d.ts +++ b/watify/pkg/watify.d.ts @@ -1,5 +1,3 @@ -/* tslint:disable */ -/* eslint-disable */ /** * @param {string} text * @returns {Uint8Array} diff --git a/watify/pkg/watify_bg.wasm.d.ts b/watify/pkg/watify_bg.wasm.d.ts index 1d3d03a50..e6ad85e32 100644 --- a/watify/pkg/watify_bg.wasm.d.ts +++ b/watify/pkg/watify_bg.wasm.d.ts @@ -1,5 +1,3 @@ -/* tslint:disable */ -/* eslint-disable */ export const memory: WebAssembly.Memory; export function watify(a: number, b: number, c: number): void; export function __wbindgen_add_to_stack_pointer(a: number): number;