forked from tylerbutler/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.js
423 lines (384 loc) · 12 KB
/
minimal.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
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
/**
* "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.
*/
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"./eslint7",
"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",
],
reportUnusedDisableDirectives: true,
ignorePatterns: [
// Don't lint generated packageVersion files.
"**/packageVersion.ts",
],
rules: {
/**
* 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"],
"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/no-unsafe-regex": "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-parameter-properties": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/typedef": "off",
/**
* Disabled because we will lean on the formatter (i.e. prettier) to enforce indentation policy.
* @remarks This rule also directly conflicts with prettier's formatting of nested ternary expressions.
*/
"unicorn/no-nested-ternary": "off",
/**
* Disabled because we want to encourage documenting different events separately.
*/
"@typescript-eslint/unified-signatures": "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
"@typescript-eslint/brace-style": [
"error",
"1tbs",
{
allowSingleLine: true,
},
],
"@typescript-eslint/comma-spacing": "error",
"@typescript-eslint/func-call-spacing": "error",
"@typescript-eslint/keyword-spacing": "error",
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "semi",
requireLast: true,
},
singleline: {
delimiter: "semi",
requireLast: true,
},
multilineDetection: "brackets",
},
],
"@typescript-eslint/object-curly-spacing": ["error", "always"],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/space-before-function-paren": [
"error",
{
anonymous: "never",
asyncArrow: "always",
named: "never",
},
],
"@typescript-eslint/space-infix-ops": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"array-bracket-spacing": "error",
"arrow-spacing": "error",
"block-spacing": "error",
"dot-location": ["error", "property"],
"jsx-quotes": "error",
"key-spacing": "error",
"space-unary-ops": "error",
"switch-colon-spacing": "error",
// #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>
*/
"jsdoc/check-line-alignment": "error",
/**
* 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.
*
* @remarks
*
* Note: "events" has been allow-listed here due to the sheer number of uses across the codebase.
* We may wish to address this in the future.
*/
"import/no-nodejs-modules": ["error", { allow: ["events"] }],
},
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", "src/test/**"],
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.
},
},
{
// Rules only for type validation files
files: ["**/types/*validate*Previous*.ts"],
rules: {
"@typescript-eslint/comma-spacing": "off",
"@typescript-eslint/consistent-type-imports": "off",
"max-lines": "off",
},
},
],
settings: {
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
node: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
},
},
"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",
},
},
},
},
};