liangjing-lint-start
Version:
增强版 React/TypeScript 项目 lint 和 prettier 配置工具 - 支持智能检测、多框架、配置预设
108 lines (103 loc) • 2.81 kB
JavaScript
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"@typescript-eslint/recommended",
"@typescript-eslint/recommended-requiring-type-checking",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: "latest",
sourceType: "module",
project: "./tsconfig.json",
},
plugins: ["react", "@typescript-eslint", "react-hooks", "jsx-a11y", "import"],
rules: {
// TypeScript 特定规则
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/prefer-const": "error",
"@typescript-eslint/no-var-requires": "error",
// React 特定规则
"react/react-in-jsx-scope": "off", // React 17+ 不需要导入 React
"react/prop-types": "off", // TypeScript 已提供类型检查
"react/jsx-uses-react": "off",
"react/jsx-uses-vars": "error",
"react/jsx-key": "error",
"react/no-array-index-key": "warn",
"react/no-unused-state": "error",
// React Hooks 规则
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
// 导入规则
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
"import/no-unresolved": "error",
"import/no-cycle": "error",
"import/no-unused-modules": "warn",
// 通用规则
"no-console": "warn",
"no-debugger": "error",
"no-alert": "error",
"prefer-const": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-template": "error",
},
settings: {
react: {
version: "detect",
},
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: "./tsconfig.json",
},
},
},
overrides: [
{
files: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"],
env: {
jest: true,
},
extends: ["plugin:testing-library/react"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"no-console": "off",
},
},
],
};