forked from WordPress/openverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
308 lines (306 loc) · 9.12 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// WebStorm fix for `~` alias not working:
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000771544-ESLint-does-not-work-with-webpack-import-resolver-in-2017-3
process.chdir(__dirname)
const i18nDestructureRules = ["t", "tc", "te", "td", "d", "n"].map(
(methodName) => ({
selector: `VariableDeclarator[id.type="ObjectPattern"]:has(Property[key.name="${methodName}"])[init.callee.name="useI18n"]`,
message: `Do not destructure ${methodName} from the i18n object as its methods internally depend on "this". Instead, use it directly (e.g., "i18n.${methodName}"). If you need an independent reference to the function then bind it or wrap it in a closure.`,
})
)
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parserOptions: {
parser: "@typescript-eslint/parser",
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:vue/recommended",
"plugin:prettier/recommended",
"plugin:vuejs-accessibility/recommended",
"plugin:@intlify/vue-i18n/recommended",
"plugin:import/recommended",
"plugin:eslint-comments/recommended",
"plugin:jsonc/recommended-with-jsonc",
"plugin:@openverse/recommended",
],
plugins: [
"@typescript-eslint",
"eslint-plugin-tsdoc",
"vue",
"vuejs-accessibility",
"unicorn",
"@openverse",
],
rules: {
semi: [2, "never"],
"no-console": "off",
"prettier/prettier": "off",
"vue/max-attributes-per-line": "off",
"vue/require-prop-types": "off",
"vue/require-default-prop": "off",
"vue/html-closing-bracket-newline": "off",
"vue/html-indent": "off",
"vue/singleline-html-element-content-newline": "off",
"vue/block-lang": [
"error",
{
// This confusing naming prevents the use of 'lang' directives
// entirely on Vue SFC style blocks.
style: { allowNoLang: true },
},
],
"vue/component-name-in-template-casing": [
"error",
"PascalCase",
{ registeredComponentsOnly: false, ignores: ["i18n"] },
],
"vue/html-self-closing": [
"error",
{
html: {
void: "always",
normal: "always",
component: "always",
},
svg: "always",
math: "always",
},
],
"vuejs-accessibility/aria-role": "error",
"vuejs-accessibility/label-has-for": [
"error",
{ required: { some: ["nesting", "id"] } },
],
/**
* Custom rule to disallow raw `<a></a>` tag usage.
* Learn more about vue-eslint-parser's AST syntax:
* https://github.com/vuejs/vue-eslint-parser/blob/master/docs/ast.md
*/
"vue/no-restricted-syntax": [
"error",
{
selector: 'VElement[name="a"]',
message: "Use the <VLink> component instead of a raw <a> tag.",
},
{
selector: 'VElement[name="nuxtlink"]',
message: "Use the <VLink> component instead of <NuxtLink>.",
},
{
selector: 'VElement[name="routerlink"]',
message: "Use the <VLink> component instead of <RouterLink>.",
},
],
"no-restricted-syntax": ["error", ...i18nDestructureRules],
"unicorn/filename-case": ["error", { case: "kebabCase" }],
"@typescript-eslint/no-var-requires": ["off"],
"import/no-unresolved": [
"error",
{
// https://github.com/nuxt-community/svg-module/issues/4
ignore: [".svg"],
},
],
"import/newline-after-import": ["error"],
"import/order": [
"error",
{
"newlines-between": "always-and-inside-groups",
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type",
],
pathGroups: [
{
// Treat vue and composition-api as "builtin"
pattern: "(vue|@nuxtjs/composition-api)",
group: "builtin",
position: "before",
},
{
// Move assets to the very end of the imports list
pattern: "~/assets/**",
group: "type",
position: "after",
},
{
// Treat components as their own group and move to the end of the internal imports list
pattern: "~/components/**",
group: "internal",
position: "after",
},
/**
* These next two must come after any more specific matchers
* as the plugin uses the patterns in order and does not sort
* multiple-matches by specificity, it just takes the _first_
* pattern that matches and applies that group to the import.
*/
{
// Document webpack alias
pattern: "~/**",
group: "internal",
position: "before",
},
{
// Document webpack alias
pattern: "~~/**",
group: "external",
position: "after",
},
],
},
],
"import/extensions": ["error", "always", { js: "never", ts: "never" }],
"@intlify/vue-i18n/no-raw-text": [
"error",
{
ignoreText: [
// Brand names that should not be translated
"Common Crawl",
"Creative Commons",
"Europeana",
"Flickr",
"Openverse",
"WordPress",
],
},
],
},
overrides: [
{
files: ["*.ts"],
rules: {
"tsdoc/syntax": "error",
},
},
{
env: { jest: true },
files: ["packages/**/*/test", "frontend/test/unit/**"],
plugins: ["jest"],
extends: ["plugin:jest/recommended"],
rules: {
"import/no-named-as-default-member": ["off"],
"@intlify/vue-i18n/no-raw-text": ["off"],
"no-restricted-imports": [
"error",
{
name: "pinia",
message:
"Please import pinia test utils from `~~/test/unit/test-utils/pinia`. The test-utils version ensures proper setup of universally necessary Nuxt context mocks.",
},
],
"no-restricted-syntax": [
"error",
{
selector:
"ImportDeclaration[source.value='@vue/test-utils']:has(ImportSpecifier[local.name='shallowMount'])",
message:
"Do not use @vue/test-utils' `shallowMount`. Use `~~/test/unit/test-utils/render` instead which includes helpful context setup or @testing-library/vue's `render` directly.",
},
],
},
},
{
files: ["frontend/test/{playwright,storybook}/**"],
plugins: ["playwright"],
extends: ["plugin:playwright/recommended"],
rules: {
// Enable once https://github.com/playwright-community/eslint-plugin-playwright/issues/154 is resolved
"playwright/expect-expect": ["off"],
},
},
{
files: [
"automations/js/src/**",
"frontend/test/**",
"frontend/src/**/**.json",
],
rules: {
"unicorn/filename-case": "off",
},
},
{
files: ["frontend/.storybook/**"],
rules: {
/**
* `.nuxt-storybook` doesn't exist in the CI when it
* lints files unless we ran the storybook build before linting,
* meaning that the imports used in the modules in this directory
* are mostly unavailable.
*
* To avoid turning these rules off we'd have to run the storybook
* build in CI before linting (or even instruct people to run
* storybook build locally before trying to lint) and that's just too
* heavy a lift when we can instead disable the rules for just this
* directory.
*/
"import/extensions": "off",
"import/export": "off",
"import/no-unresolved": "off",
},
},
{
files: ["frontend/src/components/**"],
rules: {
"unicorn/filename-case": [
"error",
// Allow things like `Component.stories.js` and `Component.types.js`
{
case: "pascalCase",
ignore: [".eslintrc.js", ".*\\..*\\.js", ".*\\.json"],
},
],
},
},
{
files: [
"frontend/src/locales/scripts/en.json5",
"frontend/test/locales/*.json",
],
rules: {
"jsonc/key-name-casing": [
"error",
{
camelCase: true,
"kebab-case": false,
snake_case: true, // for err_* keys
ignores: ["ncSampling+", "sampling+"],
},
],
},
},
{
files: ["frontend/src/locales/scripts/en.json5"],
rules: {
"jsonc/quote-props": "off",
"jsonc/quotes": "off",
},
},
],
settings: {
"vue-i18n": {
localeDir: "./frontend/src/locales/*.{json}",
messageSyntaxVersion: "^8.24.3",
},
"import/resolver": {
typescript: {
// This plugin automatically pulls paths from tsconfig
// so we don't need to redefine Nuxt and package aliases
extensions: [".js", ".ts", ".vue", ".png"],
},
},
},
}