From a560d3d2668288a873626774c141e85fadcf2cd7 Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Fri, 8 Nov 2024 15:43:27 +0800 Subject: [PATCH] chore: eslint migrate --- eslint.config.js | 17 ------------ eslint.config.mjs | 70 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 72 insertions(+), 17 deletions(-) delete mode 100644 eslint.config.js create mode 100644 eslint.config.mjs diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index a3be09587..000000000 --- a/eslint.config.js +++ /dev/null @@ -1,17 +0,0 @@ -import globals from "globals"; -import pluginJs from "@eslint/js"; -import tseslint from "typescript-eslint"; - -export default [ - { files: ["**/*.{js,mjs,cjs,ts}"] }, - { languageOptions: { globals: globals.browser } }, - pluginJs.configs.recommended, - ...tseslint.configs.recommended, - { - rules: { - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-vars": "off", - "semi": ["error", "always"] - } - } -]; \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..adf72e5e6 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,70 @@ +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import _import from "eslint-plugin-import"; +import { fixupPluginRules } from "@eslint/compat"; +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 [{ + ignores: ["src/core/proto/"], +}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), { + plugins: { + "@typescript-eslint": typescriptEslint, + import: fixupPluginRules(_import), + }, + + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + + parser: tsParser, + ecmaVersion: "latest", + sourceType: "module", + }, + + settings: { + "import/parsers": { + "@typescript-eslint/parser": [".ts"], + }, + + "import/resolver": { + typescript: { + alwaysTryTypes: true, + }, + }, + }, + + rules: { + indent: ["error", 4], + semi: ["error", "always"], + "no-unused-vars": "off", + "no-async-promise-executor": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-var-requires": "off", + "object-curly-spacing": ["error", "always"], + }, +}, { + files: ["**/.eslintrc.{js,cjs}"], + + languageOptions: { + globals: { + ...globals.node, + }, + ecmaVersion: 5, + sourceType: "commonjs", + }, +}]; diff --git a/package.json b/package.json index 8743f6d64..6f3a3a580 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "devDependencies": { "@babel/preset-typescript": "^7.24.7", + "@eslint/compat": "^1.2.2", + "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.14.0", "@log4js-node/log4js-api": "^1.0.2", "@napneko/nap-proto-core": "^0.0.2",