Commit 940a29af authored by v_liuhuaizhi's avatar v_liuhuaizhi

eslint--init

parent 0a697f79
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
build/*.js build/*.js
# 忽略src/assets目录下文件的语法检查 # 忽略src/assets目录下文件的语法检查
src/assets src/assets
src/utils
# 忽略public目录下文件的语法检查 # 忽略public目录下文件的语法检查
public public
# 忽略当前目录下为js的文件的语法检查 # 忽略permission
*.js src/store/modules/permission.js
# 忽略当前目录下为vue的文件的语法检查 # 忽略打包文件
*.vue dist
\ No newline at end of file
// ESlint 检查配置 // ESlint 检查配置
module.exports = { module.exports = {
// 此项是用来告诉eslint找当前配置文件不能往父级查找
root: true, root: true,
// 此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式
parserOptions: { parserOptions: {
parser: 'babel-eslint', parser: 'babel-eslint',
sourceType: 'module' sourceType: 'module'
}, },
// 此项指定环境的全局变量
env: { env: {
browser: true, browser: true,
node: true, node: true,
es6: true, es6: true
}, },
extends: ['plugin:vue/recommended', 'eslint:recommended'], extends: ['plugin:vue/recommended', 'eslint:recommended'],
// add your custom rules here // add your custom rules here
//it is base on https://github.com/vuejs/eslint-config-vue // 下面这些rules是用来设置从插件来的规范代码的规则,使用必须去掉前缀eslint-plugin-
// 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致
// "off" -> 0 关闭规则
// "warn" -> 1 开启警告规则
// "error" -> 2 开启错误规则
// it is base on https://github.com/vuejs/eslint-config-vue
rules: { rules: {
"vue/max-attributes-per-line": [2, { // 强制规定每行的最大属性数
"singleline": 10, 'vue/max-attributes-per-line': [2, {
"multiline": { 'singleline': 10,
"max": 1, 'multiline': {
"allowFirstLine": false 'max': 1,
'allowFirstLine': false
} }
}], }],
"vue/singleline-html-element-content-newline": "off", 'vue/singleline-html-element-content-newline': 'off',
"vue/multiline-html-element-content-newline":"off", 'vue/multiline-html-element-content-newline': 'off',
"vue/name-property-casing": ["error", "PascalCase"], 'vue/name-property-casing': ['error', 'PascalCase'],
"vue/no-v-html": "off", 'vue/no-v-html': 'off',
'vue/require-prop-types': 'off',
'vue/no-mutating-props': 'off',
'vue/require-valid-default-prop': 'off',
'vue/require-default-prop': 'off',
'no-return-assign': 'off',
'no-labels': 'off',
'no-constant-condition': 'off',
'vue/no-side-effects-in-computed-properties': 'off',
'no-prototype-builtins': 'off',
// 定义对象的set存取器属性时,强制定义get
'accessor-pairs': 2, 'accessor-pairs': 2,
// =>的前/后括号
'arrow-spacing': [2, { 'arrow-spacing': [2, {
'before': true, 'before': true,
'after': true 'after': true
}], }],
// 规则在打开的块令牌内和同一行上的下一个令牌内强制执行一致的间距。此规则还会在同一行中的关闭块标记和以前的标记内强制实施一致的间距。
'block-spacing': [2, 'always'], 'block-spacing': [2, 'always'],
// 述了花括号相对于其控制语句和正文的位置。1tbs强制执行一个真正的大括号风格
'brace-style': [2, '1tbs', { 'brace-style': [2, '1tbs', {
'allowSingleLine': true 'allowSingleLine': true // "allowSingleLine": true(默认false)允许一个块打开和关闭括号在同一行上
}], }],
'camelcase': [0, { 'camelcase': [0, {
'properties': 'always' 'properties': 'always'
}], }],
// 尾随逗号
'comma-dangle': [2, 'never'], 'comma-dangle': [2, 'never'],
// 逗号周围的间距
'comma-spacing': [2, { 'comma-spacing': [2, {
'before': false, 'before': false,
'after': true 'after': true
...@@ -48,7 +72,7 @@ module.exports = { ...@@ -48,7 +72,7 @@ module.exports = {
'curly': [2, 'multi-line'], 'curly': [2, 'multi-line'],
'dot-location': [2, 'property'], 'dot-location': [2, 'property'],
'eol-last': 2, 'eol-last': 2,
'eqeqeq': ["error", "always", {"null": "ignore"}], 'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
'generator-star-spacing': [2, { 'generator-star-spacing': [2, {
'before': true, 'before': true,
'after': true 'after': true
...@@ -71,11 +95,11 @@ module.exports = { ...@@ -71,11 +95,11 @@ module.exports = {
'capIsNew': false 'capIsNew': false
}], }],
'new-parens': 2, 'new-parens': 2,
'no-array-constructor': 2, 'no-array-constructor': 0,
'no-caller': 2, 'no-caller': 2,
'no-console': 'off', 'no-console': 'off',
'no-class-assign': 2, 'no-class-assign': 2,
'no-cond-assign': 2, 'no-cond-assign': 0,
'no-const-assign': 2, 'no-const-assign': 2,
'no-control-regex': 0, 'no-control-regex': 0,
'no-delete-var': 2, 'no-delete-var': 2,
...@@ -100,10 +124,6 @@ module.exports = { ...@@ -100,10 +124,6 @@ module.exports = {
'no-irregular-whitespace': 2, 'no-irregular-whitespace': 2,
'no-iterator': 2, 'no-iterator': 2,
'no-label-var': 2, 'no-label-var': 2,
'no-labels': [2, {
'allowLoop': false,
'allowSwitch': false
}],
'no-lone-blocks': 2, 'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2, 'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2, 'no-multi-spaces': 2,
...@@ -124,7 +144,6 @@ module.exports = { ...@@ -124,7 +144,6 @@ module.exports = {
'no-proto': 2, 'no-proto': 2,
'no-redeclare': 2, 'no-redeclare': 2,
'no-regex-spaces': 2, 'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2, 'no-self-assign': 2,
'no-self-compare': 2, 'no-self-compare': 2,
'no-sequences': 2, 'no-sequences': 2,
......
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
File deleted
...@@ -10,18 +10,8 @@ ...@@ -10,18 +10,8 @@
"build:prod": "vue-cli-service build", "build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging", "build:stage": "vue-cli-service build --mode staging",
"preview": "node build/index.js --preview", "preview": "node build/index.js --preview",
"lint": "eslint --ext .js,.vue src" "lint": "eslint --ext .js,.vue src",
}, "prepare": "husky install"
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,vue}": [
"eslint --fix",
"git add"
]
}, },
"keywords": [ "keywords": [
"vue", "vue",
...@@ -79,7 +69,8 @@ ...@@ -79,7 +69,8 @@
"sass-loader": "10.1.1", "sass-loader": "10.1.1",
"script-ext-html-webpack-plugin": "2.1.5", "script-ext-html-webpack-plugin": "2.1.5",
"svg-sprite-loader": "5.1.1", "svg-sprite-loader": "5.1.1",
"vue-template-compiler": "2.6.12" "vue-template-compiler": "2.6.12",
"husky": "^8.0.0"
}, },
"engines": { "engines": {
"node": ">=8.9", "node": ">=8.9",
......
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