添加 Typescript/集成eslint和prettier.patch
This commit is contained in:
112
Typescript/集成eslint和prettier.patch
Normal file
112
Typescript/集成eslint和prettier.patch
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
diff --git a/.husky/pre-commit b/.husky/pre-commit
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..c2bc65e
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/.husky/pre-commit
|
||||||
|
@@ -0,0 +1,2 @@
|
||||||
|
+pnpm run compile
|
||||||
|
+npx --no-install lint-staged
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/.prettierrc.cjs b/.prettierrc.cjs
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..cedeaa0
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/.prettierrc.cjs
|
||||||
|
@@ -0,0 +1,18 @@
|
||||||
|
+module.exports = {
|
||||||
|
+ // 字符串使用单引号
|
||||||
|
+ singleQuote: true,
|
||||||
|
+ // 大括号内的首尾需要空格
|
||||||
|
+ bracketSpacing: true,
|
||||||
|
+ // 末尾不需要逗号
|
||||||
|
+ trailingComma: 'none',
|
||||||
|
+ // 箭头函数参数括号
|
||||||
|
+ arrowParens: 'avoid',
|
||||||
|
+ // 在jsx中把'>' 是否单独放一行
|
||||||
|
+ jsxBracketSameLine: true,
|
||||||
|
+ // 使用默认的折行标准
|
||||||
|
+ proseWrap: 'preserve',
|
||||||
|
+ // 根据显示样式决定 html 要不要折行
|
||||||
|
+ htmlWhitespaceSensitivity: 'css',
|
||||||
|
+ // 换行符使用 crlf/lf/auto
|
||||||
|
+ endOfLine: 'auto'
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/eslint.config.mjs b/eslint.config.mjs
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..a7be3cf
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/eslint.config.mjs
|
||||||
|
@@ -0,0 +1,18 @@
|
||||||
|
+// @ts-check
|
||||||
|
+
|
||||||
|
+import eslint from '@eslint/js';
|
||||||
|
+import tseslint from 'typescript-eslint';
|
||||||
|
+import prettier from 'eslint-plugin-prettier';
|
||||||
|
+
|
||||||
|
+export default tseslint.config(
|
||||||
|
+ eslint.configs.recommended,
|
||||||
|
+ tseslint.configs.recommended,
|
||||||
|
+ {
|
||||||
|
+ plugins: {
|
||||||
|
+ prettier,
|
||||||
|
+ },
|
||||||
|
+ rules: {
|
||||||
|
+ 'prettier/prettier': 'error',
|
||||||
|
+ },
|
||||||
|
+ }
|
||||||
|
+);
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/package.json b/package.json
|
||||||
|
index 9d799c6..30b1f40 100644
|
||||||
|
--- a/package.json
|
||||||
|
+++ b/package.json
|
||||||
|
@@ -10,7 +10,9 @@
|
||||||
|
"compile": "tsc --noEmit",
|
||||||
|
"tauri": "tauri",
|
||||||
|
"tauri:dev": "tauri dev",
|
||||||
|
- "tauri:build": "tauri build"
|
||||||
|
+ "tauri:build": "tauri build",
|
||||||
|
+ "format": "prettier --write \"{src,tests}/**/*.{js,jsx,ts,tsx}\"",
|
||||||
|
+ "prepare": "husky install"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@emotion/react": "^11.14.0",
|
||||||
|
@@ -42,6 +44,7 @@
|
||||||
|
"zustand": "^5.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
+ "@eslint/js": "^9.23.0",
|
||||||
|
"@tauri-apps/cli": "^2",
|
||||||
|
"@types/node": "^22.13.1",
|
||||||
|
"@types/react": "^18.3.1",
|
||||||
|
@@ -53,8 +56,14 @@
|
||||||
|
"@unocss/preset-web-fonts": "^65.4.3",
|
||||||
|
"@unocss/reset": "^65.4.3",
|
||||||
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
|
+ "eslint": "^9.23.0",
|
||||||
|
+ "eslint-plugin-prettier": "^5.2.6",
|
||||||
|
+ "husky": "^9.1.7",
|
||||||
|
+ "lint-staged": "^15.5.0",
|
||||||
|
+ "prettier": "^3.5.3",
|
||||||
|
"tsx": "^4.19.3",
|
||||||
|
- "typescript": "~5.6.2",
|
||||||
|
+ "typescript": "~5.6.3",
|
||||||
|
+ "typescript-eslint": "^8.29.0",
|
||||||
|
"unocss": "^65.4.3",
|
||||||
|
"vite": "^6.1.0",
|
||||||
|
"vite-plugin-compression": "^0.5.1"
|
||||||
|
@@ -63,5 +72,11 @@
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"esbuild"
|
||||||
|
]
|
||||||
|
+ },
|
||||||
|
+ "lint-staged": {
|
||||||
|
+ "*.{ts,tsx}": [
|
||||||
|
+ "eslint --fix",
|
||||||
|
+ "prettier --write"
|
||||||
|
+ ]
|
||||||
|
}
|
||||||
|
-}
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
Reference in New Issue
Block a user