Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
255 lines (240 loc) · 5.91 KB
/
Copy patheslint.config.js
File metadata and controls
255 lines (240 loc) · 5.91 KB
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';
const { defineConfig, globalIgnores } = require( 'eslint/config' );
const globals = require( 'globals' );
const wikimedia = require( 'eslint-config-wikimedia/flat' );
// Code which runs in the browser, as part of MediaWiki
const resourcesConfig = {
extends: [ wikimedia( 'client', 'jquery', 'mediawiki' ) ],
languageOptions: {
globals: {
require: 'readonly',
module: 'readonly'
}
},
rules: {
'max-len': 'off',
'es-x/no-promise-prototype-finally': 'off',
'no-jquery/no-done-fail': 'off',
'no-jquery/no-global-selector': 'off',
'jsdoc/no-undefined-types': [ 'warn', {
definedTypes: [
'Hooks',
'JQuery',
'MwApi'
]
} ]
}
};
// Directories with their own config, which other configs don't apply to.
// These were directories with `"root": true` in .eslintrc.json.
const rootDirs = {
resourcesSrc: [ 'resources/src/**', 'mw-config/**', 'tests/phpunit/data/**' ],
startup: [ 'resources/src/startup/**' ],
vue: [ 'resources/src/vue/**' ],
mediawikiTitle: [ 'maintenance/mediawiki.Title/**' ],
apiTesting: [ 'tests/api-testing/**' ],
jest: [ 'tests/jest/**' ],
qunit: [ 'tests/qunit/**' ],
selenium: [ 'tests/selenium/**' ]
};
const allRootDirs = Object.values( rootDirs ).flat();
module.exports = defineConfig( [
globalIgnores( [
// Upstream code
'resources/lib/',
'maintenance/external-schemas/',
'resources/src/mediawiki.libs.jpegmeta/',
// Skip functions
'resources/src/skip-*',
// Build tooling
'docs/coverage/',
'docs/html/',
'docs/js/',
'docs/latex/',
'vendor/',
'tests/coverage/',
// Test data
'tests/phpunit/data/registration/duplicate_keys.json',
'tests/phpunit/data/resourceloader/codex/',
'tests/phpunit/data/resourceloader/codex-devmode/',
'tests/phpunit/data/SelserContext/*.json',
'tests/phpunit/data/PageEditStashContents/*.json',
'tests/phpunit/unit/includes/Settings/Source/fixtures/bad.json',
'tests/phpunit/**/*malformed*.json',
'maintenance/benchmarks/data/',
// Nested projects
'extensions/',
'skins/',
// Language files written automatically by TranslateWiki
'**/i18n/**/*.json',
'!**/i18n/**/en.json',
'!**/i18n/**/qqq.json',
// Ignore directories where MW may write internal files (T291674)
// Ref $wgCacheDirectory (installer)
// Ref $wgUploadDirectory (run-time default)
'cache/',
'images/',
// TODO: This file should be linted
'docker-compose.yml',
// Automatically generated file
'docs/config-schema.yaml'
] ),
// Build tools, maintenance scripts, etc.
{
ignores: allRootDirs,
extends: [ wikimedia( 'server' ) ],
rules: {
'max-len': 'warn'
}
},
{
files: [ 'docs/extension.schema.v2.json' ],
rules: {
'no-dupe-keys': 'off'
}
},
{
files: [ 'tests/phpunit/unit/includes/Tidy/**' ],
rules: {
indent: 'off',
'eol-last': 'off'
}
},
{
files: rootDirs.mediawikiTitle,
extends: [ wikimedia( 'server' ) ]
},
// Browser code
{
files: rootDirs.resourcesSrc,
ignores: [ ...rootDirs.startup, ...rootDirs.vue ],
...resourcesConfig
},
{
files: [ 'tests/phpunit/data/**' ],
rules: {
'array-bracket-spacing': 'off',
'comma-spacing': 'off',
'eol-last': 'off',
indent: 'off',
'key-spacing': 'off',
'no-multi-spaces': 'off',
'no-multiple-empty-lines': 'off',
'object-curly-spacing': 'off',
strict: 'off'
}
},
{
files: [ 'tests/phpunit/data/languageConverter/**' ],
rules: {
indent: 'off',
'eol-last': 'off'
}
},
{
files: rootDirs.startup,
extends: [ wikimedia( 'client' ) ],
rules: {
'max-len': 'off',
'no-var': 'off',
'prefer-arrow-callback': 'off'
}
},
{
// Only for .js files, so that JSON files are still parsed as JSON
files: [ 'resources/src/startup/**/*.js' ],
languageOptions: {
ecmaVersion: 3,
globals: {
// eslintrc defined ES5 globals for all ECMAScript versions
JSON: 'readonly'
}
},
rules: {
// ES3 doesn't have directives, so since ESLint 9 "use strict" is
// reported, unless ignored
'no-unused-expressions': [ 'error', { ignoreDirectives: true } ]
}
},
{
files: rootDirs.vue,
extends: [ wikimedia( 'client', 'mediawiki' ) ],
rules: {
'compat/compat': [
'error',
'last 2 chrome versions, last 2 firefox versions, last 2 opera versions, last 2 edge versions, safari >= 14, iOS >= 14'
],
'max-len': 'off'
}
},
// Tests
{
files: rootDirs.apiTesting,
extends: [ wikimedia( 'server', 'mocha' ) ],
rules: {
camelcase: 'off',
// Triggers for Chai assertions like `expect( foo ).to.blahBlah;`
'no-unused-expressions': 'off',
'mocha/no-setup-in-describe': 'off',
'security/detect-non-literal-regexp': 'off'
}
},
{
files: rootDirs.jest,
extends: [ wikimedia( 'client/common', 'language/es2020', 'jquery', 'mediawiki' ) ],
languageOptions: {
sourceType: 'module',
globals: {
...globals.browser,
...globals.jest,
global: 'writable'
}
},
rules: {
'compat/compat': [ 'error', 'last 2 chrome versions, last 2 firefox versions' ],
'max-len': 'off'
}
},
{
files: rootDirs.qunit,
extends: [ wikimedia( 'client/common', 'language/es2021', 'jquery', 'mediawiki', 'qunit' ) ],
languageOptions: {
globals: {
sinon: 'readonly'
}
},
rules: {
'compat/compat': [ 'error', 'last 2 chrome versions, last 2 firefox versions' ],
'max-len': 'off',
'mediawiki/no-storage': 'off',
'no-shadow': [ 'error', { allow: [ 'hooks' ] } ],
'no-jquery/no-done-fail': 'off',
'no-jquery/no-global-selector': 'off',
'no-jquery/no-parse-html-literal': 'off',
'qunit/resolve-async': 'off'
}
},
{
files: [ 'tests/qunit/data/**' ],
rules: {
indent: 'off'
}
},
{
// Applied on top of the tests/qunit config
files: [ 'tests/qunit/**/coverage-runner.js' ],
extends: [ wikimedia( 'server' ) ]
},
{
files: rootDirs.selenium,
extends: [ wikimedia( 'selenium' ) ],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
mw: 'readonly',
document: 'readonly'
}
}
}
] );