@polyv/eslint-config 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +5 -0
- package/.eslintrc.js +3 -0
- package/.gitattributes +12 -0
- package/README.md +51 -0
- package/lib/for-js.js +141 -0
- package/lib/for-ts.js +52 -0
- package/lib/for-vue.js +42 -0
- package/lib/util.js +1 -0
- package/package.json +27 -0
package/.editorconfig
ADDED
package/.eslintrc.js
ADDED
package/.gitattributes
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# 保利威前端工程 ESLint 通用配置
|
|
2
|
+
|
|
3
|
+
## 用法
|
|
4
|
+
|
|
5
|
+
### 安装配置
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @polyv/eslint-config --save-dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 调用配置
|
|
12
|
+
|
|
13
|
+
创建 `.eslintrc.js`(一般在工程根目录下创建),并配置 `extends` 字段:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
/* eslint-env node */
|
|
17
|
+
|
|
18
|
+
// TypeScript 工程的配置
|
|
19
|
+
module.exports = {
|
|
20
|
+
root: true,
|
|
21
|
+
extends: [
|
|
22
|
+
'./node_modules/@polyv/eslint-config/lib/for-js',
|
|
23
|
+
'./node_modules/@polyv/eslint-config/lib/for-ts'
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
/* eslint-env node */
|
|
30
|
+
|
|
31
|
+
// Vue.js 工程(不含 TypeScript)的配置
|
|
32
|
+
module.exports = {
|
|
33
|
+
root: true,
|
|
34
|
+
extends: [
|
|
35
|
+
'./node_modules/@polyv/eslint-config/lib/for-vue'
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
/* eslint-env node */
|
|
43
|
+
|
|
44
|
+
// JavaScript 工程的配置
|
|
45
|
+
module.exports = {
|
|
46
|
+
root: true,
|
|
47
|
+
extends: [
|
|
48
|
+
'./node_modules/@polyv/eslint-config/lib/for-js'
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
```
|
package/lib/for-js.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript 验证规则(基础规则)。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { devWarnProdError } = require('./util');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
parser: '@babel/eslint-parser',
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 2020,
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
requireConfigFile: false
|
|
13
|
+
},
|
|
14
|
+
env: {
|
|
15
|
+
browser: true,
|
|
16
|
+
es6: true
|
|
17
|
+
},
|
|
18
|
+
plugins: [
|
|
19
|
+
'promise',
|
|
20
|
+
'sonarjs'
|
|
21
|
+
],
|
|
22
|
+
extends: [
|
|
23
|
+
'eslint:recommended',
|
|
24
|
+
'plugin:sonarjs/recommended',
|
|
25
|
+
],
|
|
26
|
+
// add your custom rules here
|
|
27
|
+
rules: {
|
|
28
|
+
// 调试
|
|
29
|
+
'no-console': [
|
|
30
|
+
devWarnProdError,
|
|
31
|
+
{ 'allow': ['info', 'warn', 'error', 'time', 'timeEnd'] }
|
|
32
|
+
],
|
|
33
|
+
'no-debugger': devWarnProdError,
|
|
34
|
+
|
|
35
|
+
// 基本
|
|
36
|
+
'semi': ['error', 'always'],
|
|
37
|
+
'indent': ['error', 2, {
|
|
38
|
+
'SwitchCase': 1
|
|
39
|
+
}],
|
|
40
|
+
'brace-style': ['error', '1tbs', {
|
|
41
|
+
'allowSingleLine': true
|
|
42
|
+
}],
|
|
43
|
+
'quotes': ['error', 'single'],
|
|
44
|
+
|
|
45
|
+
// 变量
|
|
46
|
+
'new-cap': 'error',
|
|
47
|
+
'camelcase': 'error',
|
|
48
|
+
'no-use-before-define': ['error', {
|
|
49
|
+
functions: false,
|
|
50
|
+
classes: false,
|
|
51
|
+
variables: true
|
|
52
|
+
}],
|
|
53
|
+
'no-unused-vars': [devWarnProdError, {
|
|
54
|
+
vars: 'all',
|
|
55
|
+
args: 'after-used'
|
|
56
|
+
}],
|
|
57
|
+
|
|
58
|
+
// 空白与换行
|
|
59
|
+
'semi-spacing': 'error',
|
|
60
|
+
'array-bracket-spacing': ['error', 'never'],
|
|
61
|
+
'block-spacing': ['error', 'always'],
|
|
62
|
+
'computed-property-spacing': 'error',
|
|
63
|
+
'comma-spacing': 'error',
|
|
64
|
+
'func-call-spacing': 'error',
|
|
65
|
+
'key-spacing': 'error',
|
|
66
|
+
'keyword-spacing': 'error',
|
|
67
|
+
'no-trailing-spaces': 'error',
|
|
68
|
+
'no-whitespace-before-property': 'error',
|
|
69
|
+
'space-before-blocks': 'error',
|
|
70
|
+
'space-before-function-paren': ['error', {
|
|
71
|
+
anonymous: 'never',
|
|
72
|
+
named: 'never',
|
|
73
|
+
asyncArrow: 'always'
|
|
74
|
+
}],
|
|
75
|
+
'space-in-parens': 'error',
|
|
76
|
+
'space-infix-ops': 'error',
|
|
77
|
+
'space-unary-ops': 'error',
|
|
78
|
+
'spaced-comment': ['error', 'always', {
|
|
79
|
+
'block': {
|
|
80
|
+
'markers': ['!'],
|
|
81
|
+
'balanced': true
|
|
82
|
+
}
|
|
83
|
+
}],
|
|
84
|
+
'object-curly-spacing': ['error', 'always'],
|
|
85
|
+
'object-property-newline': ['error', {
|
|
86
|
+
allowAllPropertiesOnSameLine: true
|
|
87
|
+
}],
|
|
88
|
+
'operator-linebreak': ['error', 'after'],
|
|
89
|
+
'eol-last': ['error', 'always'],
|
|
90
|
+
'padded-blocks': 'off',
|
|
91
|
+
|
|
92
|
+
// 逗号
|
|
93
|
+
'comma-dangle': ['error', 'only-multiline'],
|
|
94
|
+
'comma-style': 'error',
|
|
95
|
+
|
|
96
|
+
// 其他
|
|
97
|
+
'no-extra-bind': 'error',
|
|
98
|
+
'no-extra-label': 'error',
|
|
99
|
+
'no-floating-decimal': 'error',
|
|
100
|
+
'no-implied-eval': 'error',
|
|
101
|
+
'no-iterator': 'error',
|
|
102
|
+
'no-loop-func': 'error',
|
|
103
|
+
'no-multi-spaces': 'error',
|
|
104
|
+
'no-proto': 'error',
|
|
105
|
+
'no-script-url': 'error',
|
|
106
|
+
'no-throw-literal': 'error',
|
|
107
|
+
'no-useless-call': 'error',
|
|
108
|
+
'no-new': 'off',
|
|
109
|
+
'no-with': 'error',
|
|
110
|
+
'no-constant-condition': devWarnProdError,
|
|
111
|
+
'no-cond-assign': ['error', 'except-parens'],
|
|
112
|
+
'no-empty': [devWarnProdError, {
|
|
113
|
+
'allowEmptyCatch': true
|
|
114
|
+
}],
|
|
115
|
+
'no-lonely-if': 'off',
|
|
116
|
+
'curly': ['error', 'multi-line'],
|
|
117
|
+
'wrap-iife': ['error', 'inside'],
|
|
118
|
+
|
|
119
|
+
// ES6
|
|
120
|
+
'no-var': 'error',
|
|
121
|
+
'prefer-const': 'error',
|
|
122
|
+
'no-duplicate-imports': 'error',
|
|
123
|
+
'prefer-promise-reject-errors': 'error',
|
|
124
|
+
'template-curly-spacing': ['error', 'never'],
|
|
125
|
+
'no-template-curly-in-string': 'off',
|
|
126
|
+
'arrow-spacing': 'error',
|
|
127
|
+
'no-confusing-arrow': 'error',
|
|
128
|
+
'import/order': 'off',
|
|
129
|
+
'unicorn/prefer-includes': 'off',
|
|
130
|
+
'promise/prefer-await-to-then': 'error',
|
|
131
|
+
|
|
132
|
+
// Node
|
|
133
|
+
'node/no-callback-literal': 'off',
|
|
134
|
+
|
|
135
|
+
// SonarJS
|
|
136
|
+
'sonarjs/cognitive-complexity': ['error', 18],
|
|
137
|
+
'sonarjs/no-duplicate-string': ['error', 5],
|
|
138
|
+
'sonarjs/prefer-single-boolean-return': 'off',
|
|
139
|
+
'sonarjs/no-collection-size-mischeck': 'off'
|
|
140
|
+
}
|
|
141
|
+
};
|
package/lib/for-ts.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript 工程的附加验证规则。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { devWarnProdError } = require('./util');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
overrides: [{
|
|
9
|
+
files: ['*.ts', '*.tsx'],
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: [
|
|
12
|
+
'@typescript-eslint'
|
|
13
|
+
],
|
|
14
|
+
extends: [
|
|
15
|
+
'plugin:@typescript-eslint/recommended'
|
|
16
|
+
],
|
|
17
|
+
rules: {
|
|
18
|
+
'semi': 'off',
|
|
19
|
+
'indent': 'off',
|
|
20
|
+
'no-use-before-define': 'off',
|
|
21
|
+
'no-unused-vars': 'off',
|
|
22
|
+
'comma-spacing': 'off',
|
|
23
|
+
'@typescript-eslint/semi': ['error', 'always'],
|
|
24
|
+
'@typescript-eslint/indent': ['error', 2, {
|
|
25
|
+
'SwitchCase': 1
|
|
26
|
+
}],
|
|
27
|
+
'@typescript-eslint/comma-spacing': ['error'],
|
|
28
|
+
'@typescript-eslint/no-duplicate-imports': ['error'],
|
|
29
|
+
'@typescript-eslint/type-annotation-spacing': ['error', {
|
|
30
|
+
after: true,
|
|
31
|
+
before: false,
|
|
32
|
+
overrides: {
|
|
33
|
+
arrow: {
|
|
34
|
+
before: true,
|
|
35
|
+
after: true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}],
|
|
39
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
40
|
+
'@typescript-eslint/no-unused-vars': [devWarnProdError, {
|
|
41
|
+
vars: 'all',
|
|
42
|
+
args: 'after-used'
|
|
43
|
+
}],
|
|
44
|
+
'@typescript-eslint/no-use-before-define': ['error', {
|
|
45
|
+
'functions': false,
|
|
46
|
+
'classes': false,
|
|
47
|
+
'variables': true
|
|
48
|
+
}],
|
|
49
|
+
'@typescript-eslint/explicit-module-boundary-types': ['error']
|
|
50
|
+
}
|
|
51
|
+
}]
|
|
52
|
+
};
|
package/lib/for-vue.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue.js 工程的验证规则。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const jsConfig = require('./for-js');
|
|
6
|
+
|
|
7
|
+
module.exports = Object.assign({}, jsConfig, {
|
|
8
|
+
parser: 'vue-eslint-parser',
|
|
9
|
+
parserOptions: {
|
|
10
|
+
parser: '@babel/eslint-parser',
|
|
11
|
+
...jsConfig.parserOptions
|
|
12
|
+
},
|
|
13
|
+
extends: [
|
|
14
|
+
...jsConfig.extends,
|
|
15
|
+
'@vue/standard',
|
|
16
|
+
'plugin:vue/essential'
|
|
17
|
+
],
|
|
18
|
+
rules: {
|
|
19
|
+
...jsConfig.rules,
|
|
20
|
+
'vue/html-indent': ['error', 2],
|
|
21
|
+
'vue/html-self-closing': ['error', {
|
|
22
|
+
html: {
|
|
23
|
+
void: 'always',
|
|
24
|
+
normal: 'never',
|
|
25
|
+
component: 'always'
|
|
26
|
+
}
|
|
27
|
+
}],
|
|
28
|
+
'vue/no-v-html': 'off',
|
|
29
|
+
'vue/max-attributes-per-line': ['error', {
|
|
30
|
+
singleline: 3,
|
|
31
|
+
multiline: 1
|
|
32
|
+
}],
|
|
33
|
+
'vue/singleline-html-element-content-newline': 'off',
|
|
34
|
+
|
|
35
|
+
// 为兼容以前代码而设为 warn
|
|
36
|
+
'vue/custom-event-name-casing': ['warn', 'kebab-case'],
|
|
37
|
+
'vue/no-mutating-props': 'warn',
|
|
38
|
+
'vue/multi-word-component-names': 'warn',
|
|
39
|
+
'vue/attribute-hyphenation': ['warn', 'always'],
|
|
40
|
+
'vue/v-on-event-hyphenation': ['warn', 'always']
|
|
41
|
+
}
|
|
42
|
+
});
|
package/lib/util.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.devWarnProdError = process.env.NODE_ENV === 'production' ? 'error' : 'warn';
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polyv/eslint-config",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Universal ESLint configuration for Polyv projects.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@babel/core": "^7.18.10",
|
|
8
|
+
"@babel/eslint-parser": "^7.18.9",
|
|
9
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
10
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
11
|
+
"@vue/eslint-config-standard": "^6.1.0",
|
|
12
|
+
"eslint-plugin-import": "^2.26.0",
|
|
13
|
+
"eslint-plugin-node": "^11.1.0",
|
|
14
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
15
|
+
"eslint-plugin-sonarjs": "^0.15.0",
|
|
16
|
+
"eslint-plugin-vue": "^9.3.0",
|
|
17
|
+
"vue-eslint-parser": "^9.0.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"eslint": ">=8.0.0",
|
|
21
|
+
"typescript": ">=4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"eslint": "^8.21.0",
|
|
25
|
+
"typescript": "^4.7.4"
|
|
26
|
+
}
|
|
27
|
+
}
|