Commit 74642e97 authored by 高滢's avatar 高滢

feat(框架): 配置代码校验规则 eslint

parent 8f209df0
# 忽略build目录下类型为js的文件的语法检查
build/*.js
# 忽略src/assets目录下文件的语法检查
src/assets
# 忽略public目录下文件的语法检查
public/*
# 忽略当前目录下为js的文件的语法检查
*.js
# 忽略当前目录下为vue的文件的语法检查
# *.vue
node_modules/*
src/api/monitor
src/views/tool/*
src/utils
src/components
src/layout/*
packages/*
module.exports = {
root: true, // 默认情况下,ESLint 会在所有父级目录里寻找配置文件,一直到根目录; 一旦发现配置文件中有 "root": true,它就会停止在父级目录中寻找
env: {
browser: true,
node: true,
es6: true,
},
extends: [
'eslint-config-prettier',
'eslint:recommended', // 使用推荐的eslint
'plugin:vue/vue3-recommended', // 使用插件支持vue3
'plugin:vue/vue3-essential',
//1.继承.prettierrc.js文件规则2.开启rules的 "prettier/prettier": "error"3.eslint fix的同时执行prettier格式化
'plugin:prettier/recommended',
],
parser: 'vue-eslint-parser',
parserOptions: {
ecmaVersion: 2020,
type: 'module',
// sourceType: 'moudule',
},
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly',
},
rules: {
// 添加组件命名忽略规则 vue官方默认规则是多单词驼峰来进行组件命名, 如果为off 则表示关闭命名规范校验
'vue/multi-word-component-names': [
'warn',
{
ignores: ['index', 'home', 'layout', 'user'], //需要忽略的组件名
},
],
'no-func-assign': 2, //禁止重复的函数声明
'no-implicit-coercion': 1, //禁止隐式转换
'no-implied-eval': 2, //禁止使用隐式eval
'no-inline-comments': 0, //禁止行内备注
'block-scoped-var': 0, //块语句中使用var
eqeqeq: 2, //必须使用全等
indent: ['error', 4], //缩进风格
"complexity": [1, 10], // 添加复杂度
},
}
# 忽略build目录下类型为js的文件的语法检查
build/*.js
# 忽略src/assets目录下文件的语法检查
src/assets
# 忽略public目录下文件的语法检查
public/*
# 忽略当前目录下为js的文件的语法检查
*.js
# 忽略当前目录下为vue的文件的语法检查
# *.vue
node_modules/*
src/api/monitor
src/views/tool/*
src/utils
src/components
src/layout/*
packages/*
module.exports = {
// 超过80就换行
printWidth: 80,
// tab缩进大小,默认为2
tabWidth: 2,
// 使用tab缩进,默认false
useTabs: false,
// 使用分号,默认true
semi: false,
// 使用单引号, 默认false,(在jsx中配置无效, 默认都是双引号)
singleQuote: true,
// 行尾逗号,默认none,可选(none|es5|all),es5 包括es5中的数组、对象,all 包括函数对象等所有可选
trailingComma: 'none',
// 对象中的空格 默认true,true: { foo: bar },false: {foo: bar}
bracketSpacing: true,
// JSX标签闭合位置 默认false
jsxBracketSameLine: false,
// 箭头函数参数括号 默认avoid 可选(avoid|always),avoid 能省略括号的时候就省略 例如x => x ,always 总是有括号
arrowParens: 'avoid',
// 不使用prettier格式化的文件填写在项目的.prettierignore文件中
ignorePath: '.prettierignore',
// 在jsx中把'>' 是否单独放一行
jsxBracketSameLine: false
}
......@@ -9,7 +9,9 @@
"dev": "vite",
"build:prod": "vite build",
"build:stage": "vite build --mode staging",
"preview": "vite preview"
"preview": "vite preview",
"lint": "eslint src",
"fix": "eslint src --fix"
},
"repository": {
"type": "git",
......@@ -37,7 +39,14 @@
"vuedraggable": "4.1.0"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
"@vitejs/plugin-vue": "5.0.5",
"eslint": "^8.57.0",
"eslint-config-prettier": "^10.0.2",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-vue": "^9.32.0",
"globals": "^16.0.0",
"prettier": "^3.5.2",
"sass": "1.77.5",
"unplugin-auto-import": "0.17.6",
"unplugin-vue-setup-extend-plus": "1.0.1",
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment