-
Notifications
You must be signed in to change notification settings - Fork 7
/
.eslintrc.js
255 lines (234 loc) · 6.63 KB
/
.eslintrc.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
'use strict'
// Non-TS base
const baseConfigs = [
'ash-nazg/sauron',
'plugin:vue/vue3-recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:prettier/recommended',
]
// TS base
const baseTSConfigs = [
...baseConfigs,
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
]
// Todo: Remove this in favor of `baseTSConfigs` when TS working in Vue files
const baseConfigsNoTS = baseTSConfigs.filter(c => !c.includes('@typescript-eslint'))
// Node-specific base configs
const baseNodeConfigs = [
'ash-nazg/sauron-node',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:prettier/recommended',
]
// `eslint-plugin-vue` rules
const vueRules = {
// Disabling as Vue linter won't catch (and we are requiring `name` anyways)
'import/no-anonymous-default-export': 'off',
// Temporarily disable
'vue/no-boolean-default': 'off', // Enable?
'vue/no-mutating-props': 'off', // Enable?
'vue/require-default-prop': 'off', // Enable?
// 'vue/no-duplicate-attr-inheritance': ['error'], // Enforce?
// 'vue/no-static-inline-styles': ['error'], // Use later; require in <style>
'vue/no-unused-properties': [
'error',
{
// 'data', 'methods'
groups: ['props', 'computed', 'setup'],
},
],
// 'vue/no-bare-strings-in-template': ['error'], // Use later if i18nizing
// 'vue/html-comment-indent': ['error'], // Possibly too oppressive
// Disable
'vue/attributes-order': 'off', // Oppressive
'vue/max-attributes-per-line': 'off', // A bit oppressive
'vue/block-tag-newline': ['error'],
'vue/component-name-in-template-casing': ['error', 'kebab-case'],
'vue/html-comment-content-newline': ['error'],
'vue/html-comment-content-spacing': ['error'],
'vue/match-component-file-name': ['error', { shouldMatchCase: true }],
// 'vue/no-boolean-default': ['error'],
'vue/no-empty-component-block': ['error'],
'vue/no-multiple-objects-in-class': ['error'],
'vue/no-potential-component-option-typo': ['error', { presets: ['vue', 'vue-router'] }],
'vue/no-reserved-component-names': ['error'],
'vue/no-restricted-component-options': ['error', 'data', 'computed', 'methods', 'watch'],
'vue/no-template-target-blank': ['error', { allowReferrer: true }],
'vue/no-unregistered-components': [
'error',
{
// Component used in main.ts
ignorePatterns: ['router-view'],
},
],
'vue/no-unsupported-features': ['error', { version: '^3.0.0' }],
'vue/no-useless-mustaches': ['error'],
'vue/no-useless-v-bind': ['error'],
'vue/padding-line-between-blocks': ['error'],
'vue/require-direct-export': ['error'],
'vue/require-name-property': ['error'],
'vue/v-for-delimiter-style': ['error'],
'vue/v-on-function-call': ['error'],
'vue/html-closing-bracket-newline': [
'error',
{
singleline: 'never',
multiline: 'never',
},
],
'vue/html-self-closing': [
'error',
{
html: {
void: 'always',
},
},
],
}
const baseRules = {
// Keep this here so can uncomment to check inline disabling
// "eslint-comments/no-use": "error",
// Simplifying
'import/extensions': 'off',
// Disabling for now
'max-len': 'off', // ['warn', { code: 80 }],
'jsdoc/require-jsdoc': 'off',
'require-unicode-regexp': 'off',
'prefer-named-capture-group': 'off',
// More consistent styling of WS before exports
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: ['const', 'let'], next: 'export' },
],
// Wasteful to use all named imports
'no-restricted-syntax': [
'error',
{
selector: 'ImportNamespaceSpecifier',
message:
'As it is wasteful to use all named imports, use only those ' +
'which are needed (or switch to a default import).',
},
],
}
module.exports = {
env: {
browser: true,
es6: true,
},
extends: baseConfigs,
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2020,
},
overrides: [
// Node.js config files (non-Vue, non-TS)
{
files: ['.*.js', '*.config.js'],
extends: baseNodeConfigs,
env: {
node: true,
},
globals: {
// Have to add these back due to config inheritance
__dirname: true,
module: true,
require: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'script',
},
rules: {
...baseRules,
// CommonJS:
strict: ['error', 'global'],
'import/no-commonjs': 'off',
},
},
// Rollup (ESM)
{
files: 'rollup.config.js',
env: {
node: true,
},
globals: {
__dirname: true, // Switch to `import.meta.url` when using bona fide ESM
},
extends: baseNodeConfigs,
rules: {
...baseRules,
},
},
// TS files
{
files: '*.ts',
extends: baseTSConfigs,
rules: {
...baseRules,
// Possible non-recommended items to enable?
// '@typescript-eslint/no-unsafe-assignment': ['error'],
// '@typescript-eslint/no-unsafe-member-access': ['error'],
// '@typescript-eslint/no-unsafe-return': ['error'],
'@typescript-eslint/naming-convention': ['error'],
},
},
// TS declaration files
{
files: '*.d.ts',
extends: baseTSConfigs,
rules: {
...baseRules,
// Let API be as needed
'@typescript-eslint/naming-convention': 'off',
// No imports/exports in plain declaration file
'import/unambiguous': 'off',
},
},
// Vue SFC files
{
files: '*.vue',
extends: baseConfigsNoTS,
// Need `vue` `parser` and `plugins` re-added since adding `vue3`
parser: require.resolve('vue-eslint-parser'),
plugins: ['vue', '@pathscale/vue3'],
rules: {
...baseRules,
...vueRules,
'@pathscale/vue3/v-directive': [
'error',
{
unsafe: [
// These just add a single operator
// 'SpreadElement',
// 'UnaryExpression',
// This seems unavoidable
// 'CallExpression',
// To avoid these, one can use a call expression
'AssignmentExpression',
'BinaryExpression',
'LogicalExpression',
'ConditionalExpression',
// This can have design features but preventing to avoid ugliness
'TemplateLiteral[expressions.length <= 1]',
],
},
],
},
},
{
files: ['**/*.spec.{j,t}s?(x)'],
env: {
jest: true,
},
},
],
rules: {
...baseRules,
},
}