forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal-deprecated.js
517 lines (457 loc) · 16.1 KB
/
minimal-deprecated.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
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Shared list of permitted imports for configuring and override the `import/no-internal-modules` rule.
*/
const permittedImports = [
// Within Fluid Framework allow import of '/internal' from other FF packages.
"@fluid-example/*/internal",
"@fluid-experimental/*/internal",
"@fluid-internal/*/internal",
"@fluid-private/*/internal",
"@fluid-tools/*/internal",
"@fluidframework/*/internal",
// Experimental package APIs and exports are unknown, so allow any imports from them.
"@fluid-experimental/**",
// Allow imports from sibling and ancestral sibling directories,
// but not from cousin directories. Parent is allowed but only
// because there isn't a known way to deny it.
"*/index.js",
];
/**
* "Minimal" eslint configuration.
*
* This configuration is primarily intended for use in packages during prototyping / initial setup.
* Ideally, all of packages in the fluid-framework repository should derive from either the "Recommended" or
* "Strict" configuration.
*
* Production packages **should not** use this configuration.
*
* @deprecated This config is too permissive and should not be used. It will be removed in a future release.
* Use the "Recommended" or "Strict" configuration instead.
*
* @privateRemarks TODO: Once this config is ready for deletion, its rules can be moved into `recommended.js`.
*/
module.exports = {
env: {
browser: true,
es6: true,
es2024: false,
node: true,
},
extends: [
"./base",
"plugin:eslint-comments/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"prettier",
],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: "module",
project: "./tsconfig.json",
},
plugins: [
// Plugin documentation: https://www.npmjs.com/package/@rushstack/eslint-plugin
"@rushstack/eslint-plugin",
// Plugin documentation: https://www.npmjs.com/package/@rushstack/eslint-plugin-security
"@rushstack/eslint-plugin-security",
// Plugin documentation: https://www.npmjs.com/package/@typescript-eslint/eslint-plugin
"@typescript-eslint/eslint-plugin",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-jsdoc
"eslint-plugin-jsdoc",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-promise
"eslint-plugin-promise",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-tsdoc
"eslint-plugin-tsdoc",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-unused-imports
"unused-imports",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-unicorn
"unicorn",
// Custom ESLint rules
"@fluid-internal/eslint-plugin-fluid",
],
reportUnusedDisableDirectives: true,
ignorePatterns: [
// Don't lint generated packageVersion files.
"**/packageVersion.ts",
],
rules: {
/**
* Restricts including release tags inside the member class / interface.
*
* Refer to the rule by the unprefixed plugin name in the consumed package.
* {@link https://eslint.org/docs/latest/extend/plugins#rules-in-plugins}
*/
"@fluid-internal/fluid/no-member-release-tags": "error",
/**
* Rule to enforce safe property access on index signature types.
*
* Reports issues when non-array index properties are accessed without handling
* the possibility that they are absent.
* Enabling `noUncheckedIndexedAccess` will disable these checks.
*/
"@fluid-internal/fluid/no-unchecked-record-access": "error",
/**
* The @rushstack rules are documented in the package README:
* {@link https://www.npmjs.com/package/@rushstack/eslint-plugin}
*/
"@rushstack/no-new-null": "warn",
/**
* RATIONALE: Harmless.
*
* Our guideline is to only use leading underscores on private members when required to avoid a conflict
* between private fields and a public property.
*
* Docs: {@link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md}
*/
"@typescript-eslint/naming-convention": [
"error",
{
selector: "accessor",
modifiers: ["private"],
format: ["camelCase"],
leadingUnderscore: "allow",
},
],
/**
* Encourages minimal disabling of eslint rules, while still permitting whole-file exclusions.
*/
"eslint-comments/disable-enable-pair": [
"error",
{
allowWholeFile: true,
},
],
// ENABLED INTENTIONALLY
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"eqeqeq": ["error", "smart"],
"import/no-deprecated": "error",
"max-len": [
"error",
{
code: 120,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
"no-multi-spaces": [
"error",
{
ignoreEOLComments: true,
},
],
/**
* Note: this can be replaced altogether by `@typescript-eslint/no-unused-vars`,
* but that rule covers many more scenarios than this one does, and there are many violations
* currently in the repository, so it has not been enabled yet.
*/
"unused-imports/no-unused-imports": "error",
"valid-typeof": "error",
/**
* Catches a common coding mistake where "resolve" and "reject" are confused.
*/
"promise/param-names": "warn",
"unicorn/better-regex": "error",
"unicorn/filename-case": [
"error",
{
cases: {
camelCase: true,
pascalCase: true,
},
},
],
"unicorn/no-new-buffer": "error",
"unicorn/prefer-switch": "error",
"unicorn/prefer-ternary": "error",
"unicorn/prefer-type-error": "error",
// #region DISABLED INTENTIONALLY
/**
* Disabled because we don't require that all variable declarations be explicitly typed.
*/
"@rushstack/typedef-var": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
/**
* Disabled because we will lean on the formatter (i.e. prettier) to enforce indentation policy.
*/
"@typescript-eslint/indent": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/typedef": "off",
/**
* Disabled because we want to encourage documenting different events separately.
*/
"@typescript-eslint/unified-signatures": "off",
// Requires a lot of changes
"@typescript-eslint/no-duplicate-type-constituents": "off",
// Lots of false positives
"@typescript-eslint/non-nullable-type-assertion-style": "off",
// Requires breaking changes; enabled in the strict config
"@typescript-eslint/consistent-indexed-object-style": "off",
// Requires a lot of changes; enabled in the strict config
"@typescript-eslint/no-unsafe-enum-comparison": "off",
// Requires a lot of changes; enabled in the strict config
"@typescript-eslint/no-redundant-type-constituents": "off",
// Requires a lot of changes; enabled in the strict config
"@typescript-eslint/consistent-generic-constructors": "off",
// Off for minimal and recommended; enabled in the strict config
"@typescript-eslint/consistent-type-exports": "off",
"@typescript-eslint/consistent-type-imports": "off",
"func-call-spacing": "off", // Off because it conflicts with typescript-formatter
"no-empty": "off",
"no-void": "off",
"require-atomic-updates": "off",
/**
* Superseded by `@typescript-eslint/dot-notation`.
*/
"dot-notation": "off",
/**
* Superseded by `@typescript-eslint/no-unused-expressions`.
*/
"no-unused-expressions": "off",
// #endregion
// #region FORMATTING RULES
// We use formatting tools like Biome or prettier to format code, so most formatting-related rules are superfluous
// and are disabled. Running fewer rules also improves lint performance.
// The rules below are also deprecated in more recent versions of eslint/plugins
"@typescript-eslint/brace-style": "off",
"@typescript-eslint/comma-spacing": "off",
"@typescript-eslint/func-call-spacing": "off",
"@typescript-eslint/keyword-spacing": "off",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/semi": "off",
"@typescript-eslint/space-before-function-paren": "off",
"@typescript-eslint/space-infix-ops": "off",
"@typescript-eslint/type-annotation-spacing": "off",
// The rules below are deprecated in our current version of eslint/plugins
"@typescript-eslint/object-curly-spacing": "off",
"array-bracket-spacing": "off",
"arrow-spacing": "off",
"block-spacing": "off",
"dot-location": "off",
"jsx-quotes": "off",
"key-spacing": "off",
"space-unary-ops": "off",
"switch-colon-spacing": "off",
// #endregion
// #region DOCUMENTATION RULES
/**
* This rule ensures that our Intellisense looks good by verifying the TSDoc syntax.
*/
"tsdoc/syntax": "error",
// #region eslint-plugin-jsdoc rules
/**
* Ensures that conflicting access tags don't exist in the same comment.
* See <https://github.com/gajus/eslint-plugin-jsdoc#check-access>.
*/
"jsdoc/check-access": "error",
/**
* Ensures consistent line formatting in JSDoc/TSDoc comments
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-check-alignment>
*
* TODO: This is temporarily set to "warn" because there are a lot of false positives with code blocks in
* particular.
*/
"jsdoc/check-line-alignment": "warn",
/**
* The syntax this validates does not accommodate the syntax used by API-Extractor
* See <https://api-extractor.com/pages/tsdoc/tag_example/>
*/
"jsdoc/check-examples": "off",
/**
* Ensures correct indentation within JSDoc/TSDoc comment body
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-check-indentation>
*/
"jsdoc/check-indentation": "error",
/**
* Covered by `tsdoc/syntax`
*/
"jsdoc/check-tag-names": "off",
/**
* Ensures that JSDoc/TSDoc "modifier" tags are empty.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-empty-tags>
*/
"jsdoc/empty-tags": "error",
/**
* Ensures multi-line formatting meets JSDoc/TSDoc requirements.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-no-bad-blocks>
*/
"jsdoc/no-bad-blocks": "error",
/**
* Requires that each line in a JSDoc/TSDoc comment starts with a `*`.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-asterisk-prefix>
*/
"jsdoc/require-asterisk-prefix": "error",
/**
* Ensure function/method parameter comments include a `-` between name and description.
* Useful to ensure API-Extractor compatability.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-hyphen-before-param-description>.
*/
"jsdoc/require-hyphen-before-param-description": "error",
/**
* Require `@param` tags be non-empty.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-param-description>
*/
"jsdoc/require-param-description": "error",
/**
* Requires `@returns` tags to be non-empty.
* See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-returns-description>
*/
"jsdoc/require-returns-description": "error",
// #endregion
// #endregion
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
/**
* By default, libraries should not take dependencies on node libraries.
* This rule can be disabled at the project level for libraries that are intended to be used only in node.
*/
"import/no-nodejs-modules": ["error"],
/**
* Allow Fluid Framework to import from its own internal packages.
* https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md
*/
"import/no-internal-modules": [
"error",
{
allow: permittedImports,
},
],
},
overrides: [
{
// Rules only for TypeScript files
files: ["*.ts", "*.tsx"],
rules: {
"dot-notation": "off", // Superseded by @typescript-eslint/dot-notation
"no-unused-expressions": "off", // Superseded by @typescript-eslint/no-unused-expressions
},
settings: {
jsdoc: {
mode: "typescript",
},
},
},
{
// Rules only for React files
files: ["*.jsx", "*.tsx"],
plugins: [
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-react
"react",
// Plugin documentation: https://www.npmjs.com/package/eslint-plugin-react-hooks
"react-hooks",
],
extends: ["plugin:react/recommended", "plugin:react-hooks/recommended"],
settings: {
react: {
version: "detect",
},
},
},
{
// Rules only for test files
files: [
"*.spec.ts",
"*.test.ts",
"**/test/**",
// TODO: consider unifying code across the repo to use "test" and not "tests", then we can remove this.
"**/tests/**",
],
rules: {
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/unbound-method": "off", // This rule has false positives in many of our test projects.
"import/no-nodejs-modules": "off", // Node libraries are OK for test files.
"import/no-deprecated": "off", // Deprecated APIs are OK to use in test files.
// Disabled for test files
"@typescript-eslint/consistent-type-exports": "off",
"@typescript-eslint/consistent-type-imports": "off",
// For test files only, additionally allow import of '/test*' and '/internal/test*' exports.
"import/no-internal-modules": [
"error",
{
allow: ["@fluid*/*/test*", "@fluid*/*/internal/test*"].concat(
permittedImports,
),
},
],
// Test code may leverage dev dependencies
"import/no-extraneous-dependencies": ["error", { devDependencies: true }],
},
},
],
settings: {
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
/**
* Note: the key order of import/resolver is relevant in the completely resolved eslint config (see ./printed-configs).
* Resolvers are tried in key order, and the first one to successfully resolve the import wins. See:
* https://github.com/import-js/eslint-plugin-import/blob/c0ac54b8a721c2b1c9048838acc4d6282f4fe7a7/utils/resolve.js#L196
*
* It's important that the typescript resolver is first, as the node resolver legitimately resolves some imports to modules
* with stripped type information, which can cause silent negatives in lint rules. For example, import/no-deprecated fails
* to lint against import and usage of deprecated types when the import is resolvable and resolved using the node resolver.
*/
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
conditionNames: [
// This supports the test-only conditional export pattern used in merge-tree and id-compressor.
"allow-ff-test-exports",
// Default condition names below, see https://www.npmjs.com/package/eslint-import-resolver-typescript#conditionnames
"types",
"import",
// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",
"require",
"node",
"node-addons",
"browser",
"default",
],
},
},
"jsdoc": {
// The following are intended to keep js/jsx JSDoc comments in line with TSDoc syntax used in ts/tsx code.
tagNamePreference: {
arg: {
message: "Please use @param instead of @arg.",
replacement: "param",
},
argument: {
message: "Please use @param instead of @argument.",
replacement: "param",
},
return: {
message: "Please use @returns instead of @return.",
replacement: "returns",
},
},
},
},
};