Skip to content

Commit 86ab39a

Browse files
committed
refactor: 化繁为简,改用@antfu/eslint-config + simple-git-hooks
1 parent 78dd188 commit 86ab39a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3674
-2263
lines changed

.commitlintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ export default {
2828
'subject-full-stop': [0, 'never'],
2929
'subject-case': [0, 'never'],
3030
},
31-
};
31+
}

.husky/commit-msg

-3
This file was deleted.

.husky/pre-commit

-5
This file was deleted.

.prettierignore

-6
This file was deleted.

.prettierrc.js

-31
This file was deleted.

.stylelintignore

-5
This file was deleted.

.vscode/settings.json

+38-39
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
{
2-
// 开启自动修复
2+
// Disable the default formatter
3+
"prettier.enable": false,
4+
"editor.formatOnSave": false,
5+
6+
// Auto fix
37
"editor.codeActionsOnSave": {
4-
"source.fixAll": "never",
58
"source.fixAll.eslint": "explicit",
6-
"source.fixAll.stylelint": "explicit"
7-
},
8-
// 保存的时候自动格式化
9-
"editor.formatOnSave": true,
10-
// 默认格式化工具选择prettier
11-
"editor.defaultFormatter": "esbenp.prettier-vscode",
12-
// 配置该项,新建文件时默认就是space:2
13-
"editor.tabSize": 2,
14-
// stylelint校验的文件格式
15-
"stylelint.validate": ["css", "scss", "html"],
16-
"[typescriptreact]": {
17-
"editor.defaultFormatter": "esbenp.prettier-vscode"
18-
},
19-
"[typescript]": {
20-
"editor.defaultFormatter": "esbenp.prettier-vscode"
21-
},
22-
"[javascript]": {
23-
"editor.defaultFormatter": "esbenp.prettier-vscode"
24-
},
25-
"[javascriptreact]": {
26-
"editor.defaultFormatter": "esbenp.prettier-vscode"
27-
},
28-
"[json]": {
29-
"editor.defaultFormatter": "esbenp.prettier-vscode"
30-
},
31-
"[html]": {
32-
"editor.defaultFormatter": "esbenp.prettier-vscode"
33-
},
34-
"[css]": {
35-
"editor.defaultFormatter": "esbenp.prettier-vscode"
36-
},
37-
"[scss]": {
38-
"editor.defaultFormatter": "esbenp.prettier-vscode"
39-
},
40-
"[markdown]": {
41-
"editor.defaultFormatter": "esbenp.prettier-vscode"
42-
}
9+
"source.organizeImports": "never"
10+
},
11+
12+
// Silent the stylistic rules in you IDE, but still auto fix them
13+
"eslint.rules.customizations": [
14+
{ "rule": "style/*", "severity": "off" },
15+
{ "rule": "format/*", "severity": "off" },
16+
{ "rule": "*-indent", "severity": "off" },
17+
{ "rule": "*-spacing", "severity": "off" },
18+
{ "rule": "*-spaces", "severity": "off" },
19+
{ "rule": "*-order", "severity": "off" },
20+
{ "rule": "*-dangle", "severity": "off" },
21+
{ "rule": "*-newline", "severity": "off" },
22+
{ "rule": "*quotes", "severity": "off" },
23+
{ "rule": "*semi", "severity": "off" }
24+
],
25+
26+
// The following is optional.
27+
// It's better to put under project setting `.vscode/settings.json`
28+
// to avoid conflicts with working with different eslint configs
29+
// that does not support all formats.
30+
"eslint.validate": [
31+
"javascript",
32+
"javascriptreact",
33+
"typescript",
34+
"typescriptreact",
35+
"vue",
36+
"html",
37+
"markdown",
38+
"json",
39+
"jsonc",
40+
"yaml"
41+
]
4342
}

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ GitHub 项目地址:[React-Mobile-Template](https://github.com/huangmingfu/rea
7979
8080
## 注意
8181

82-
1.目前有一些ui库还未支持React19,本项目使用的是18.3.1版本,谨慎升级react版本。
83-
2.postcss-pxtorem插件不支持内联样式,所以 `utils` 里面配备了 `px2rem` 函数解决。示例:`<div style={{ width: px2rem(100) }}>test</div>`
84-
3. 以下场景pxtorem插件不会转换rem:
85-
(1).在main.ts里引入样式,如 `import '@/styles/scss/global.scss';`,建议引入不涉及px的样式,如reset.css。
82+
1. 目前有一些ui库还未支持React19,本项目使用的是18.3.1版本,谨慎升级react版本。
83+
2. postcss-pxtorem插件不支持内联样式,所以 `utils` 里面配备了 `px2rem` 函数解决。示例:`<div style={{ width: px2rem(100) }}>test</div>`
84+
3. 以下场景pxtorem插件不会转换rem:
85+
(1).在main.ts里引入样式,如 `import '@/styles/scss/global.scss';`,建议引入不涉及px的样式,如reset.css。

eslint.config.js

+13-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,15 @@
1-
import js from '@eslint/js';
2-
import react from 'eslint-plugin-react';
3-
import reactHooks from 'eslint-plugin-react-hooks';
4-
import reactRefresh from 'eslint-plugin-react-refresh';
5-
import globals from 'globals';
6-
import tseslint from 'typescript-eslint';
1+
import antfu from '@antfu/eslint-config'
72

8-
export default tseslint.config(
9-
{ ignores: ['dist', 'dist*', 'node_modules'] },
10-
{
11-
settings: { react: { version: '18.3' } },
12-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
13-
files: ['**/*.{ts,tsx}'],
14-
languageOptions: {
15-
ecmaVersion: 2020,
16-
globals: globals.browser,
17-
},
18-
plugins: {
19-
react,
20-
'react-hooks': reactHooks,
21-
'react-refresh': reactRefresh,
22-
},
23-
rules: {
24-
...reactHooks.configs.recommended.rules,
25-
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
26-
...react.configs.recommended.rules,
27-
...react.configs['jsx-runtime'].rules,
28-
'@typescript-eslint/no-unused-vars': 'off', // 禁用 TypeScript 未使用变量的警告
29-
'react-refresh/only-export-components': 'off', // 禁用 react-refresh 插件中仅导出组件的规则
30-
'@typescript-eslint/no-explicit-any': 'off', // 允许使用any
31-
'@typescript-eslint/no-unused-expressions': 'off', // 关闭对未使用的表达式的检查
32-
'react-hooks/exhaustive-deps': 'off', // 关闭依赖项检查规则
33-
},
34-
languageOptions: {
35-
parserOptions: {
36-
project: ['./tsconfig.json'],
37-
tsconfigRootDir: import.meta.dirname,
38-
},
39-
},
3+
export default antfu({
4+
vue: false,
5+
react: true, // @eslint-react/eslint-plugin
6+
typescript: true,
7+
stylistic: true,
8+
formatters: true, // eslint-plugin-format 格式化
9+
rules: {
10+
'react/no-array-index-key': 'off',
11+
'react/no-children-to-array': 'off',
12+
'jsdoc/check-alignment': 'off',
13+
'react-hooks/exhaustive-deps': 'off',
4014
},
41-
);
15+
})

index.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6-
<meta
7-
name="viewport"
8-
content="width=device-width, viewport-fit=cover, initial-scale=1.0, user-scalable=no"
9-
/>
6+
<meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1.0, user-scalable=no" />
107
<!-- 动态设置网页标题 -->
118
<title>%VITE_APP_TITLE%</title>
129
</head>

lint-staged.config.js

-6
This file was deleted.

package.json

+22-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "react-mobile-template",
3-
"description": "一套基于react18、ts、vite6的移动端项目模板",
4-
"version": "1.0.0",
53
"type": "module",
4+
"version": "1.0.0",
65
"packageManager": "[email protected]",
6+
"description": "一套基于react18、ts、vite6的移动端项目模板",
77
"author": "huangmingfu <[email protected]>",
88
"license": "MIT",
99
"homepage": "https://github.com/huangmingfu/react-mobile-template",
@@ -21,6 +21,10 @@
2121
"antd-mobile",
2222
"vite"
2323
],
24+
"engines": {
25+
"node": "^18.0.0 || ^20.0.0 || >=22.0.0",
26+
"pnpm": ">=9"
27+
},
2428
"scripts": {
2529
"dev": "vite -m dev",
2630
"dev:test": "vite -m test",
@@ -31,13 +35,12 @@
3135
"preview:dev": "pnpm vite preview -m dev",
3236
"preview:test": "pnpm vite preview -m test",
3337
"preview:pro": "pnpm vite preview -m pro",
34-
"ts:check": "tsc --noEmit",
35-
"lint:eslint": "eslint --max-warnings 0 \"**/*.{ts,tsx,js,jsx,cjs,mjs}\" --fix --cache",
36-
"lint:format": "prettier --write --cache \"**/*.{ts,tsx,js,jsx,cjs,mjs,html,scss,css,less,json}\"",
37-
"lint:style": "stylelint \"**/*.{css,scss,less}\" --fix --cache",
38-
"lint:all": "pnpm run lint:eslint && pnpm run lint:style && pnpm run lint:format",
39-
"prepare": "husky install",
38+
"typecheck": "tsc --noEmit",
39+
"lint": "eslint .",
40+
"lint:fix": "eslint . --fix",
41+
"lint:inspector": "npx @eslint/config-inspector",
4042
"preinstall": "npx only-allow pnpm",
43+
"postinstall": "npx simple-git-hooks",
4144
"clean": "rm -rf node_modules dist dist-*",
4245
"deps:check": "pnpm outdated -r",
4346
"deps:update": "pnpm update --latest"
@@ -56,41 +59,34 @@
5659
"zustand": "^5.0.2"
5760
},
5861
"devDependencies": {
62+
"@antfu/eslint-config": "^3.12.1",
5963
"@commitlint/cli": "^19.6.1",
6064
"@commitlint/config-conventional": "^19.6.0",
61-
"@commitlint/prompt-cli": "^19.6.1",
62-
"@eslint/js": "^9.17.0",
65+
"@eslint-react/eslint-plugin": "^1.22.1",
6366
"@react-dev-inspector/vite-plugin": "^2.0.1",
64-
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
6567
"@types/node": "^22.10.2",
6668
"@types/react": "^19.0.2",
6769
"@types/react-dom": "^19.0.2",
6870
"@vitejs/plugin-react-swc": "^3.7.2",
6971
"amfe-flexible": "^2.2.1",
70-
"autoprefixer": "^10.4.20",
7172
"eslint": "^9.17.0",
72-
"eslint-plugin-react": "^7.37.3",
73-
"eslint-plugin-react-hooks": "^5.1.0",
74-
"eslint-plugin-react-refresh": "^0.4.16",
73+
"eslint-plugin-format": "^0.1.3",
7574
"globals": "^15.14.0",
76-
"husky": "^9.1.7",
7775
"lint-staged": "^15.2.11",
76+
"postcss-preset-env": "^10.1.2",
7877
"postcss-pxtorem": "^6.1.0",
79-
"prettier": "^3.4.2",
8078
"react-dev-inspector": "^2.0.1",
8179
"sass": "^1.83.0",
82-
"stylelint": "^16.12.0",
83-
"stylelint-config-recess-order": "^5.1.1",
84-
"stylelint-config-standard": "^36.0.1",
85-
"stylelint-config-standard-scss": "^14.0.0",
86-
"stylelint-order": "^6.0.4",
80+
"simple-git-hooks": "^2.11.1",
8781
"typescript": "~5.7.2",
88-
"typescript-eslint": "^8.18.2",
8982
"vite": "^6.0.5",
9083
"vite-plugin-checker": "^0.8.0"
9184
},
92-
"engines": {
93-
"node": "^18.0.0 || ^20.0.0 || >=22.0.0",
94-
"pnpm": ">=9"
85+
"simple-git-hooks": {
86+
"pre-commit": "npx lint-staged",
87+
"commit-msg": "npx --no -- commitlint --edit"
88+
},
89+
"lint-staged": {
90+
"*": "eslint --fix"
9591
}
9692
}

0 commit comments

Comments
 (0)