-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.js
173 lines (170 loc) · 5.71 KB
/
vue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* eslint-disable max-len */
/* eslint-disable id-length */
module.exports = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: { /* jsx: true */ },
// debugLevel:true,
// 用于eslint-config-airbnb-typescript
// project: './tsconfig.json',
},
env: {
browser: true,
node: true,
},
extends: ['airbnb-base', 'plugin:vue/recommended', '@vue/typescript/recommended'],
rules: {
// http://eslint.cn/docs/rules/#stylistic-issues
'array-bracket-newline': ['error', { multiline: true }],
'array-element-newline': ['error', { multiline: true, minItems: 6 }],
'consistent-return': 'off',
'comma-spacing': ['error', { before: false, after: true }],
'id-length': [
'error',
{
min: 3,
max: 40,
/* eslint-disable-next-line array-element-newline */
exceptions: ['d', 'dd', 'e', 'fn', 'from', 'h', 'i', 'id', 'j', 'k', 'MB', 'ol', 'on', 'to', 'ua', 'UA', 'v', 'x', 'y'],
},
],
'max-len': [
'error',
{
code: 148,
comments: 100,
ignoreComments: true,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
'max-lines': ['error', { max: 600, skipBlankLines: true, skipComments: true }],
'no-console': 'warn',
'no-use-before-define': ['error', { functions: false }],
'object-curly-newline': ['error', { minProperties: 6, multiline: true }],
'operator-linebreak': ['error', 'after', { overrides: { ':': 'before', '?': 'before' } }],
semi: ['error', 'never'],
// 'multiline-comment-style': ['error', 'starred-block'],
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
'@typescript-eslint/explicit-module-boundary-types': 'off',
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': [
'error',
'ignorePackages',
{
vue: 'never',
ts: 'never',
tsx: 'never',
js: 'never',
mjs: 'never',
jsx: 'never',
},
],
// 全局用@typescript-eslint/indent,不用indent
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md#how-to-use
indent: 'off',
// https://github.com/airbnb/javascript/blob/1eadb93e377da1e56c3f91f26610e5d0a00738a9/packages/eslint-config-airbnb-base/rules/style.js#L130
'@typescript-eslint/indent': [
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
// MemberExpression: null,
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
ignoredNodes: [
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXFragment',
'JSXOpeningFragment',
'JSXClosingFragment',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
],
ignoreComments: false,
},
],
},
overrides: [
{
// https://github.com/typescript-eslint/typescript-eslint/blob/v4.6.1/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md#configuring-in-a-mixed-jsts-codebase
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': ['error'],
// https://github.com/typescript-eslint/typescript-eslint/blob/v4.22.0/packages/eslint-plugin/docs/rules/ban-ts-comment.md#rule-details
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': false }],
},
},
{
files: ['*.vue'],
rules: {
'vue/max-attributes-per-line': [
'error',
{
singleline: {
max: 6,
allowFirstLine: true,
},
multiline: {
max: 1,
allowFirstLine: false,
},
},
],
'vue/singleline-html-element-content-newline': 'off',
},
},
// 目前仅对vue文件进行Prettier格式化,用以支持render中JSX的格式化
{
files: ['*.jsx.vue'],
// https://github.com/prettier/eslint-plugin-prettier
// eslint-plugin-prettier v3.4.0 通过eslint可视化展示prettier结果
plugins: ['prettier'],
// https://github.com/prettier/eslint-config-prettier/tree/v8.3.0
// eslint-config-prettier 关闭prettier和eslint冲突的规则
extends: ['prettier'],
rules: {
// https://github.com/prettier/eslint-plugin-prettier#installation
'prettier/prettier': 'warn',
},
},
],
// 以下在项目中配置
// // settings参考:https://github.com/vuejs/eslint-config-airbnb/blob/master/index.js
// settings: {
// 'import/extensions': ['.js', '.ts', '.mjs', '.jsx', '.tsx'],
// 'import/resolver': {
// // https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-511007063
// // node: {},
// webpack: { config: require.resolve('@vue/cli-service/webpack.config.js') },
// },
// },
}