r-util-js/eslint.config.js

114 lines
2.6 KiB
JavaScript

import js from "@eslint/js";
import ts from "typescript-eslint";
import prettier from "eslint-config-prettier";
import prettierPlugin from "eslint-plugin-prettier";
import globals from "globals";
import importPlugin from "eslint-plugin-import-x";
export default [
// 应用推荐规则
js.configs.recommended,
...ts.configs.recommended,
prettier,
// 基础配置
{
files: ["**/*.{js,mjs,cjs,ts,vue}"],
ignores: [
"**/node_modules/*",
"**/dist/*",
"build/",
"public/",
"docs/",
"bin/",
"pnpm-lock.yaml",
".vscode/",
".idea/",
".husky/",
"Dockerfile",
".hbuilderx/",
".vite/",
"uni_modules/",
"libs/",
"static/",
"patches/",
"wxcomponents/",
"lib/",
"scripts/",
],
plugins: { prettier: prettierPlugin, "import-x": importPlugin },
settings: {
"import-x/resolver": {
typescript: {
project: "tsconfig.eslint.json",
},
node: true,
},
},
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
ecmaVersion: "latest",
sourceType: "module",
parserOptions: {
ecmaFeatures: {
impliedStrict: true,
},
},
},
rules: {
...importPlugin.flatConfigs.recommended.rules,
// Prettier 规则
"prettier/prettier": "warn",
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
// Import 规则
"import-x/no-self-import": "error",
"import-x/no-cycle": "error",
"import-x/no-useless-path-segments": "error",
"import-x/no-extraneous-dependencies": "error",
"import-x/no-mutable-exports": "error",
"import-x/no-named-as-default": "error",
"import-x/no-named-as-default-member": "error",
"import-x/no-duplicates": "warn",
"import-x/no-deprecated": "warn",
"import-x/newline-after-import": "warn",
"import-x/first": "warn",
"import-x/order": [
"warn",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type",
],
alphabetize: {
order: "asc",
},
},
],
},
},
// 测试文件覆盖配置
{
files: ["**/__tests__/*.{j,t}s?(x)", "**/tests/unit/**/*.spec.{j,t}s?(x)"],
languageOptions: {
globals: {
...globals.mocha,
...globals.jest,
},
},
},
];