Skip to content

Commit

Permalink
refactor: 更换 ESLint 配置为 @antfu/eslint-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 10, 2024
1 parent 5101dd1 commit bfc8e42
Show file tree
Hide file tree
Showing 148 changed files with 6,982 additions and 4,714 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

68 changes: 0 additions & 68 deletions .eslintrc.cjs

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierignore

This file was deleted.

14 changes: 0 additions & 14 deletions .prettierrc.js

This file was deleted.

52 changes: 43 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
{
// 配置该项, 新建文件时默认就是space: 2
"editor.tabSize": 2,
// 保存的时候自动格式化
// Enable the ESlint flat config support
// (remove this if your ESLint extension above v3.0.5)
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": true,
// 默认格式化工具选择prettier
"editor.defaultFormatter": "esbenp.prettier-vscode",
// 开启自动修复

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll": "never",
"source.fixAll.eslint": "explicit"
}
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"gql",
"graphql",
"astro"
]
}
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ pnpm dev
## 项目结构

```
continew-admin-ui # 前端项目
├─ config # Vite 插件配置
├─ public # 公共静态资源(favicon.ico、logo.svg)
continew-admin-ui
├─ config # Vite 插件配置
├─ public # 公共静态资源(favicon.ico、logo.svg)
├─ src
│ ├─ apis # 请求接口
│ │ ├─ auth # 认证模块
Expand Down Expand Up @@ -275,13 +275,10 @@ continew-admin-ui # 前端项目
│ │ └─ user # 用户管理
│ ├─ App.vue
│ └─ main.ts
├─ .env.development
├─ .env.production
├─ .env.test
├─ .eslintignore
├─ .eslintrc.cjs
├─ .prettierignore
├─ .prettierrc.js
├─ .env.development # 开发环境配置
├─ .env.production # 生产环境配置
├─ .env.test # 测试环境配置
├─ eslint.config.js # ESLint 配置
├─ index.html
├─ package.json
├─ package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion config/plugins/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function createAutoImport() {
imports: [
'vue',
'vue-router',
'pinia',
'pinia'
],
dts: './src/types/auto-imports.d.ts'
})
Expand Down
2 changes: 1 addition & 1 deletion config/plugins/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default function createComponents() {
dirs: ['src/components'],
extensions: ['vue', 'tsx'],
// 配置文件生成位置
dts: './src/types/components.d.ts',
dts: './src/types/components.d.ts'
})
}
2 changes: 1 addition & 1 deletion config/plugins/svg-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default function createSvgIcon(isBuild) {
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
// 指定 symbolId 格式
symbolId: 'icon-[dir]-[name]',
svgoOptions: isBuild,
svgoOptions: isBuild
})
}
55 changes: 55 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import antfu from '@antfu/eslint-config'

// https://github.com/antfu/eslint-config
export default antfu(
{
vue: true,
typescript: true,
ignores: [
'README.md',
'src/types/shims-vue.d.ts'
]
},
{
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
files: ['**/*.vue'],
rules: {
'vue/block-order': [2, {
order: [['script', 'template'], 'style']
}], // 强制组件顶级元素的顺序
'vue/html-self-closing': [0, {
html: {
void: 'never',
normal: 'always',
component: 'never'
}
}], // 强制自结束样式
'vue/custom-event-name-casing': [2, 'kebab-case'], // 对自定义事件名称强制使用特定大小写
'vue/singleline-html-element-content-newline': 0, // 要求在单行元素的内容前后换行
'vue/first-attribute-linebreak': 0, // 强制第一个属性的位置
'vue/define-macros-order': [2, {
order: ['defineOptions', 'defineModel', 'defineProps', 'defineEmits', 'defineSlots'],
defineExposeLast: false
}], // 强制执行定义限制和定义弹出编译器宏的顺序
'vue/html-indent': 0, // 在《模板》中强制一致的缩进
'vue/html-closing-bracket-newline': 0 // 要求或不允许在标记的右括号前换行
}
},
{
// Without `files`, they are general rules for all files
rules: {
'curly': [0, 'all'], // 对所有控制语句强制使用一致的大括号样式
'dot-notation': 0, // 尽可能强制使用点表示法。 在 JavaScript 中,可以使用点表示法 (foo.bar) 或方括号表示法 (foo["bar"]) 访问属性
'no-new': 0, // 不允许在赋值或比较之外使用 new 运算符
// 'no-console': 2, // 禁止使用 console
'no-process-env': 0,
'style/arrow-parens': [2, 'always'], // 箭头函数参数需要括号
'style/brace-style': [2, '1tbs', { allowSingleLine: true }], // 对块执行一致的大括号样式
'style/comma-dangle': [2, 'never'], // 要求或不允许尾随逗号
'ts/consistent-type-definitions': 0,
'node/prefer-global/process': 0,
'antfu/top-level-function': 0,
'antfu/if-newline': 0
}
}
)
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "continew-admin-ui",
"type": "module",
"version": "3.1.0-SNAPSHOT",
"private": "true",
"scripts": {
Expand All @@ -9,7 +10,7 @@
"preview": "vite preview --port 5050",
"typecheck": "vue-tsc --noEmit",
"lint": "eslint src",
"fix": "eslint src --fix"
"lint:fix": "eslint src --fix"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
Expand Down Expand Up @@ -54,24 +55,21 @@
"xgplayer": "^2.31.6"
},
"devDependencies": {
"@antfu/eslint-config": "^2.16.3",
"@arco-design/web-vue": "^2.55.0",
"@rushstack/eslint-patch": "^1.3.1",
"@types/crypto-js": "^4.2.2",
"@types/lodash": "^4.14.195",
"@types/node": "^20.2.5",
"@types/query-string": "^6.3.0",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.3",
"@vue/tsconfig": "^0.1.3",
"eslint": "^8.41.0",
"eslint-plugin-vue": "^9.13.0",
"eslint": "^9.0.0",
"less": "^4.1.3",
"less-loader": "^11.0.0",
"prettier": "^2.8.8",
"lint-staged": "^15.2.2",
"sass": "^1.62.1",
"sass-loader": "^13.2.2",
"simple-git-hooks": "^2.11.1",
"typescript": "~5.0.4",
"unplugin-auto-import": "^0.16.4",
"unplugin-vue-components": "^0.25.1",
Expand All @@ -80,5 +78,11 @@
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svg-icons": "^2.0.1",
"vue-tsc": "^2.0.6"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading

0 comments on commit bfc8e42

Please sign in to comment.