Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
458 lines (407 loc) · 13.3 KB
/
Copy patheslint.config.mjs
File metadata and controls
458 lines (407 loc) · 13.3 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
import { readdirSync } from 'node:fs';
import globals from 'globals';
import vitest from '@vitest/eslint-plugin';
import { defineConfig } from 'eslint/config';
import ckeditor5Rules from 'eslint-plugin-ckeditor5-rules';
import ckeditor5Config from 'eslint-config-ckeditor5';
import { CKEDITOR5_PACKAGES_PATH } from './scripts/constants.mjs';
const projectPackages = readdirSync( CKEDITOR5_PACKAGES_PATH, { withFileTypes: true } )
.filter( dirent => dirent.isDirectory() )
.map( dirent => dirent.name );
const allowedPackageNames = [
'inspector',
'mermaid',
...projectPackages
.map( projectPackage => projectPackage.replace( /ckeditor5-?/, '' ) )
.filter( Boolean )
];
const disallowedPackageImportsPattern = `@ckeditor/ckeditor5-(?!${ allowedPackageNames.join( '|' ) })`;
const disallowedPackageImportsMessage = 'External `@ckeditor/ckeditor5-*` imports are forbidden.';
const disallowedRelativePathImportsPattern = [ './**/src/**', '../**/src/**' ];
const disallowedRelativePathImportsMessage = 'Imports to the `src` directory from within the `src` directory are forbidden.';
export default defineConfig( [
{
ignores: [
'.*/',
'!.changelog/',
'build/**',
'coverage/**',
'coverage-vitest/**',
'dist/**',
'packages/*/build/**',
'packages/*/coverage/**',
'packages/*/dist/**',
'packages/*/lang/translations/*.ts',
'packages/*/src/lib/**',
'release/**',
'**/*.d.ts',
'packages/ckeditor5-emoji/src/utils/isemojisupported.ts',
// This file includes JSX which eslint can't parse without additional configuration.
'docs/_snippets/framework/tutorials/using-react-in-widget.js',
// Editor builds in memory leak detection test.
'scripts/memory/assets/'
]
},
{
extends: ckeditor5Config,
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
linterOptions: {
reportUnusedDisableDirectives: 'warn',
reportUnusedInlineConfigs: 'warn'
},
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
rules: {
'ckeditor5-rules/prevent-license-key-leak': 'error',
'ckeditor5-rules/license-header': [ 'error', {
headerLines: [
'/**',
' * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.',
' * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options',
' */'
]
} ],
'ckeditor5-rules/require-file-extensions-in-imports': [ 'error', {
extensions: [ '.ts', '.js', '.json' ]
} ],
'ckeditor5-rules/require-as-const-returns-in-methods': [ 'error', {
methodNames: [ 'pluginName' ]
} ]
}
},
{
files: [
'packages/**/*.css',
'docs/**/*.css'
],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
rules: {
'ckeditor5-rules/license-header': [ 'error', {
headerLines: [
'/*',
' * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.',
' * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options',
' */'
]
} ]
}
},
{
// `ck-content-variable-name` is activated by the eslint-config-ckeditor5 only for `**/theme/**/*.css`.
files: [ '**/theme/**/*.css' ],
rules: {
'ckeditor5-rules/require-host-with-root-selector': 'error',
'ckeditor5-rules/ck-content-variable-name': [ 'error', {
ignoredVariableSubstrings: [ '-suggestion-', '-comment-', '-color-base-' ]
} ]
}
},
{
files: [ '**/*.css' ],
rules: {
// See tracking issue: https://github.com/ckeditor/ckeditor5-commercial/issues/11155.
// TODO (RTL): off pending a migration of physical properties/values to logical. Step 1
// (required first): fix the ~10 logical-*value* cases in source - text-align/float/resize
// `right`/`left`/`vertical` - which have no allow option, so they block enabling. Then, as a
// gradual follow-up, replace `off` with the allow-list below (it permits the physical
// properties/units already in use, silencing the bulk so only new ones are flagged) and
// shrink that list over time as each property is migrated to logical.
// 'css/prefer-logical-properties': [ 'error', {
// allowProperties: [
// // sizing
// 'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height',
// // margin / padding
// 'margin-top', 'margin-bottom', 'margin-left', 'margin-right',
// 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
// // inset
// 'top', 'bottom', 'left', 'right',
// // border (side / width / color)
// 'border-top', 'border-bottom', 'border-left', 'border-right', 'border-top-width',
// 'border-top-color', 'border-bottom-color', 'border-left-color',
// // border radius
// 'border-top-left-radius', 'border-top-right-radius',
// 'border-bottom-left-radius', 'border-bottom-right-radius',
// // overflow / misc
// 'overflow-x', 'overflow-y', 'scroll-margin-top', 'overscroll-behavior-y'
// ],
// allowUnits: [ 'vh', 'vw' ]
// } ],
'css/prefer-logical-properties': 'off',
// See tracking issue: https://github.com/ckeditor/ckeditor5-commercial/issues/10452
// The features marked with TODO are used but are not yet baseline "widely available", so they are
// temporarily white-listed locally. The rest are acceptable (supported in practice or handled by the build).
// All TODOs should be fixed in source and have the exceptions removed afterwards.
'css/use-baseline': [ 'error', {
available: 'widely',
allowSelectors: [
// https://developer.mozilla.org/en-US/docs/Web/CSS/Nesting_selector
// handled by LightningCSS at build (never ships nested)
'nesting',
// https://developer.mozilla.org/en-US/docs/Web/CSS/:has
// Baseline 2023, all modern browsers
'has'
],
allowProperties: [
// https://developer.mozilla.org/en-US/docs/Web/CSS/user-select
// Not Baseline because Safari has never shipped an unprefixed version - every usage in
// this codebase already pairs it with `-webkit-user-select`, so this is a syntax
// limitation, not a cross-browser behavior gap.
'user-select',
// https://developer.mozilla.org/en-US/docs/Web/CSS/resize
// Not Baseline solely because Firefox for Android and Safari on iOS recognize it but apply
// no effect (mobile browsers show no resize handle regardless of this property) - a no-op
// gap on the browsers where it doesn't apply, not a real cross-browser risk.
'resize',
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap
// Baseline "newly available" - already supported across major browsers since March
// 2024 and on track to reach "widely available" around September 2026.
'text-wrap',
// TODO: fix https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior
'transition-behavior',
// https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior
// https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior-y
// Not Baseline solely because of a partial-implementation caveat noting no effect on
// non-scrollable containers - uniform across browsers and irrelevant to every usage here,
// which is always on a genuinely scrollable element. Core behavior (preventing scroll
// chaining) has been supported by Chrome, Firefox, Safari, and Edge since 2017-2022.
'overscroll-behavior',
'overscroll-behavior-y'
],
allowAtRules: [
// TODO: fix https://developer.mozilla.org/en-US/docs/Web/CSS/@starting-style
'starting-style'
]
} ]
}
},
{
// Less strict checks for non-production code.
files: [ '**/manual/**/*.css' ],
rules: {
'css/no-important': 'off',
'css/prefer-logical-properties': 'off',
'css/use-baseline': 'off'
}
},
{
files: [ 'packages/*/src/**/*.ts' ],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
languageOptions: {
parserOptions: {
// Type information for the `require-trusted-types-for-sinks` rule, which reports a sink only on a DOM object.
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
rules: {
'ckeditor5-rules/require-trusted-types-for-sinks': 'error',
'ckeditor5-rules/no-shadow-unsafe-dom-apis': 'error',
'ckeditor5-rules/validate-module-tag': 'error',
'ckeditor5-rules/no-default-export': 'error',
'ckeditor5-rules/allow-svg-imports-only-in-icons-package': 'error',
'ckeditor5-rules/allow-css-imports-only-in-main-package-entry-point': 'error',
'ckeditor5-rules/no-literal-dollar-root': [ 'error', {
allowedPackages: [ 'ckeditor5-engine', 'ckeditor5-core' ],
allowedCalls: [ 'is' ]
} ],
'ckeditor5-rules/require-explicit-data-context': 'error',
'ckeditor5-rules/ckeditor-plugin-flags': [ 'error', {
requiredFlags: [ {
name: 'isOfficialPlugin',
returnValue: true
} ]
} ],
'@typescript-eslint/no-restricted-imports': [ 'error',
{
patterns: [
{
group: disallowedRelativePathImportsPattern,
message: disallowedRelativePathImportsMessage
},
{
regex: disallowedPackageImportsPattern,
message: disallowedPackageImportsMessage
},
{
regex: '^es-toolkit$',
message: 'Import from `es-toolkit/compat` instead.'
}
]
}
]
}
},
{
files: [
// A development helper, which is never a part of a production build.
'packages/ckeditor5-engine/src/dev-utils/view.ts',
// The home of the Trusted Types helpers, which writes to a sink on purpose to check whether the browser rejects it.
'packages/ckeditor5-utils/src/dom/trustedtypes.ts'
],
rules: {
'ckeditor5-rules/require-trusted-types-for-sinks': 'off'
}
},
{
files: [
'packages/*/@(src|tests|manual)/**/*.js',
'**/docs/**/_snippets/**/*.js'
],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
rules: {
'no-restricted-imports': [ 'error', {
patterns: [
{
regex: disallowedPackageImportsPattern,
message: disallowedPackageImportsMessage
},
{
regex: '^es-toolkit$',
message: 'Import from `es-toolkit/compat` instead.'
}
]
} ]
}
},
{
files: [
'packages/*/tests/**/*.ts',
'packages/*/manual/**/*.ts'
],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
rules: {
'@typescript-eslint/no-restricted-imports': [ 'error', {
patterns: [
{
regex: disallowedPackageImportsPattern,
message: disallowedPackageImportsMessage
},
{
regex: '^es-toolkit$',
message: 'Import from `es-toolkit/compat` instead.'
}
]
} ]
}
},
{
files: [ '**/*.@(js|cjs|mjs)' ],
languageOptions: {
globals: {
...globals.node
}
}
},
{
files: [
'**/tests/**/*.@(js|cjs|mjs|ts)',
'**/manual/**/*.@(js|cjs|mjs|ts)'
],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
languageOptions: {
globals: {
...globals.browser
}
},
rules: {
'ckeditor5-rules/allow-imports-only-from-main-package-entry-point': [ 'error', {
allowedImportPatterns: [
'**/tests/**/_utils*/**',
'**/manual/**/_utils*/**'
]
} ],
'ckeditor5-rules/no-cross-package-imports': 'off'
}
},
{
files: [
'**/tests/**/*.@(js|cjs|mjs|ts)',
'**/scripts-tests/**/*.@(js|cjs|mjs|ts)'
],
plugins: {
vitest
},
rules: {
...vitest.configs.recommended.rules,
// Many suites assert through shared helpers instead of inline `expect()` calls.
'vitest/expect-expect': [ 'error', {
assertFunctionNames: [ 'expect*', 'assert*', 'check*', 'test*', 'runTest' ]
} ],
// Skipped tests are allowed. Some cover known, tracked limitations.
'vitest/no-disabled-tests': 'off',
// Combining `toHaveBeenCalledOnce()` with `toHaveBeenCalledWith()` is fine.
'vitest/prefer-called-exactly-once-with': 'off',
// The Vitest `expect` is chai-based and accepts a custom assertion message
// as the second argument.
'vitest/valid-expect': [ 'error', { maxArgs: 2 } ],
// The shared Vitest configuration sets `restoreMocks: true` and `unstubGlobals: true`,
// so manual cleanup is redundant and a suite-level variant would break other tests.
'vitest/no-restricted-vi-methods': [ 'error', {
restoreAllMocks: 'The shared Vitest config restores mocks automatically (`restoreMocks: true`).',
unstubAllGlobals: 'The shared Vitest config unstubs globals automatically (`unstubGlobals: true`).'
} ],
'vitest/consistent-test-it': [ 'error', { fn: 'it' } ]
}
},
{
files: [ '**/manual/**/*.@(js|cjs|mjs|ts)' ],
languageOptions: {
globals: {
CKEditorInspector: true
}
}
},
{
files: [ '**/docs/**/*.@(js|cjs|mjs)' ],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
languageOptions: {
globals: {
...globals.browser
}
}
},
{
files: [ 'scripts/memory/page-test.js' ],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
languageOptions: {
globals: {
...globals.browser
}
}
},
{
extends: ckeditor5Config,
files: [ '.changelog/**/*.md' ],
plugins: {
'ckeditor5-rules': ckeditor5Rules
},
rules: {
'ckeditor5-rules/validate-changelog-entry': [ 'error', {
allowedScopes: projectPackages,
repositoryType: 'mono'
} ]
}
}
] );