集成ESLint代码规范校验

This commit is contained in:
ray
2024-09-18 00:23:06 +08:00
parent 3a70cb6724
commit 08c6855f49
3 changed files with 48 additions and 6 deletions

38
eslint.config.mjs Normal file
View File

@@ -0,0 +1,38 @@
import globals from "globals"; // 全局变量配置
import pluginJs from "@eslint/js"; // JavaScript 的推荐配置
import tseslint from "typescript-eslint"; // TypeScript 配置
import pluginVue from "eslint-plugin-vue"; // Vue 配置
export default [
{files: ["**/*.{js,mjs,cjs,ts,vue}"]}, // 校验的文件类型
{languageOptions: { globals: globals.browser }}, // 设置浏览器环境的全局变量
pluginJs.configs.recommended, // JavaScript 推荐配置
...tseslint.configs.recommended, // TypeScript 推荐配置
...pluginVue.configs["flat/essential"], // Vue 推荐配置
{files: ["**/*.vue"], languageOptions: {parserOptions: {parser: tseslint.parser}}}, // 对 .vue 文件使用 TypeScript 解析器
// 添加忽略的文件或目录
{
ignores: [
"/dist",
"/public",
"/node_modules",
"**/*.min.js",
"**/*.config.mjs",
"**/*.tsbuildinfo",
"/src/manifest.json",
]
},
// 添加规则配置
{
rules: {
"vue/multi-word-component-names": "off", // 关闭多单词名称检查
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"quotes": ["error", "double"], // 强制使用双引号
"quote-props": ["error", "always"] // 强制对象的属性名使用引号
}
},
];

View File

@@ -40,7 +40,8 @@
"build:quickapp-webview": "uni build -p quickapp-webview",
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
"type-check": "vue-tsc --noEmit"
"type-check": "vue-tsc --noEmit",
"lint:eslint": "eslint --fix ./src"
},
"dependencies": {
"@dcloudio/uni-app": "3.0.0-4020420240722002",
@@ -67,10 +68,14 @@
"@dcloudio/uni-cli-shared": "3.0.0-4020420240722002",
"@dcloudio/uni-stacktracey": "3.0.0-4020420240722002",
"@dcloudio/vite-plugin-uni": "3.0.0-4020420240722002",
"@vue/tsconfig": "^0.1.3",
"@eslint/js": "^9.10.0",
"@vue/runtime-core": "^3.4.21",
"eslint": "^9.10.0",
"eslint-plugin-vue": "^9.28.0",
"globals": "^15.9.0",
"typescript": "^4.9.4",
"typescript-eslint": "^8.6.0",
"vite": "5.2.8",
"vue-tsc": "^1.0.24"
}
},
}

5
src/env.d.ts vendored
View File

@@ -1,8 +1,7 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
declare module "*.vue" {
import { DefineComponent } from "vue"
const component: DefineComponent<{}, {}, any>
export default component
}