From dc6dcf155ccaaaf4b0f4262abaaa09f6592e3f4f Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Tue, 5 Nov 2024 16:08:13 +1000 Subject: [PATCH] Upgrade ESLint to v9 --- .eslintignore | 2 - .eslintrc.cjs | 91 ----------------------- eslint.config.js | 50 +++++++++++++ package.json | 22 +++--- test/suite/specification-prettier.spec.ts | 3 - 5 files changed, 62 insertions(+), 106 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.cjs create mode 100644 eslint.config.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index f4e51ac..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -/artifacts/ -/node_modules/ diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index fe7bc8f..0000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,91 +0,0 @@ -module.exports = { - extends: [ - "eslint:recommended", - "plugin:n/recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "plugin:promise/recommended", - "prettier", - ], - parserOptions: { - sourceType: "module", - ecmaFeatures: { - jsx: true, - }, - }, - env: { - es2022: true, - node: true, - }, - rules: { - "import/no-nodejs-modules": [ - "error", - { - allow: [ - "node:buffer", - "node:console", - "node:os", - "node:path", - "node:stream", - "node:url", - ], - }, - ], - "no-unused-vars": [ - "error", - { - // allow unused args if they start with _ - argsIgnorePattern: "^_", - }, - ], - // handled by import/no-unresolved - "n/no-missing-import": "off", - // don't check for unsupported features - too much config to make this work - "n/no-unsupported-features/es-builtins": "off", - "n/no-unsupported-features/es-syntax": "off", - "n/no-unsupported-features/node-builtins": "off", - }, - overrides: [ - { - files: ["*.ts", "*.tsx"], - extends: [ - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", - ], - parserOptions: { - project: "./tsconfig.json", - }, - settings: { - "import/resolver": "typescript", - }, - rules: { - "@typescript-eslint/no-unused-vars": [ - "error", - { - // allow unused args if they start with _ - argsIgnorePattern: "^_", - }, - ], - }, - }, - { - files: [ - "*.spec.js", - "*.spec.jsx", - "*.spec.ts", - "*.spec.tsx", - "*.test.js", - "*.test.jsx", - "*.test.ts", - "*.test.tsx", - ], - extends: ["plugin:vitest/recommended"], - plugins: ["vitest"], - settings: { - vitest: { - typecheck: true, - }, - }, - }, - ], -}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..38bd297 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,50 @@ +import js from "@eslint/js"; +import import_ from "eslint-plugin-import"; +import node from "eslint-plugin-n"; +import promise from "eslint-plugin-promise"; +import globals from "globals"; +import ts from "typescript-eslint"; + +export default ts.config( + { + ignores: [".makefiles", "artifacts"], + }, + js.configs.recommended, + // eslint-disable-next-line import/no-named-as-default-member + ...ts.configs.recommended, + node.configs["flat/recommended-module"], + import_.flatConfigs.recommended, + import_.flatConfigs.typescript, + promise.configs["flat/recommended"], + { + languageOptions: { + ecmaVersion: 2022, + sourceType: "module", + globals: { + ...globals.es2022, + ...globals.node, + }, + }, + settings: { + "import/resolver": { + typescript: true, + node: true, + }, + }, + rules: { + "@typescript-eslint/no-unused-vars": [ + "error", + { + // allow unused args if they start with _ + argsIgnorePattern: "^_", + }, + ], + // handled by import/no-unresolved + "n/no-missing-import": "off", + // don't check for unsupported features - too much config to make this work + "n/no-unsupported-features/es-builtins": "off", + "n/no-unsupported-features/es-syntax": "off", + "n/no-unsupported-features/node-builtins": "off", + }, + }, +); diff --git a/package.json b/package.json index b56aea3..d8715af 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "/artifacts/dist/" ], "engines": { - "node": ">=14" + "node": ">=18" }, "scripts": { "prepublishOnly": "make artifacts/dist" @@ -75,27 +75,29 @@ }, "devDependencies": { "@arethetypeswrong/cli": "^0.16.4", + "@eslint/js": "^9.14.0", "@skypack/package-check": "^0.2.2", "@stryker-mutator/core": "^8.0.0", "@stryker-mutator/typescript-checker": "^8.0.0", "@stryker-mutator/vitest-runner": "^8.2.6", + "@types/eslint__js": "^8.42.3", "@types/mdast": "^4.0.3", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^8.0.0", - "@typescript-eslint/parser": "^8.0.0", "@vitest/coverage-v8": "^2.0.0", - "eslint": "^8.17.0", - "eslint-config-prettier": "^9.0.0", - "eslint-import-resolver-typescript": "^3.2.5", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-n": "^17.0.0", - "eslint-plugin-promise": "^7.0.0", - "eslint-plugin-vitest": "^0.4.0", + "@vitest/eslint-plugin": "^1.1.7", + "eslint": "^9.14.0", + "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-typescript": "^3.6.3", + "eslint-plugin-import": "^2.31.0", + "eslint-plugin-n": "^17.12.0", + "eslint-plugin-promise": "^7.1.0", + "globals": "^15.12.0", "prettier": "^3.0.0", "prettier-plugin-organize-imports": "^4.0.0", "publint": "^0.2.12", "ts-node": "^10.9.1", "typescript": "^5.0.4", + "typescript-eslint": "^8.13.0", "vite-tsconfig-paths": "^5.1.0", "vitest": "^2.0.0" } diff --git a/test/suite/specification-prettier.spec.ts b/test/suite/specification-prettier.spec.ts index fcb7773..1343134 100644 --- a/test/suite/specification-prettier.spec.ts +++ b/test/suite/specification-prettier.spec.ts @@ -38,7 +38,6 @@ describe("Specification documents (Prettier unavailable)", () => { describe("when Prettier is not installed", () => { beforeAll(() => { - // eslint-disable-next-line @typescript-eslint/require-await vi.doMock("prettier", async () => { throw new Error('Cannot find module "prettier"'); }); @@ -63,14 +62,12 @@ describe("Specification documents (Prettier unavailable)", () => { describe("when Prettier is installed but not configured", () => { beforeAll(() => { - // eslint-disable-next-line @typescript-eslint/require-await vi.doMock("prettier", async () => { const prettier = await vi.importActual("prettier"); return { ...prettier, - // eslint-disable-next-line @typescript-eslint/require-await async resolveConfig() { return null; },