UNPKG

7.43 kBJavaScriptView Raw
1/*!
2 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3 * Licensed under the MIT License.
4 */
5
6/**
7 * "Recommended" eslint configuration.
8 *
9 * This is the fluid-framework repository's default configuration.
10 * Recommended for use production packages whose APIs we do not expect the majority of our customers to use directly.
11 *
12 * For packages whose APIs are intended for wide use, the "Strict" configuration should be used instead.
13 */
14module.exports = {
15 env: {
16 browser: true,
17 es6: true,
18 es2024: false,
19 node: true,
20 },
21 extends: ["./minimal-deprecated.js", "plugin:unicorn/recommended"],
22 plugins: ["eslint-plugin-tsdoc"],
23 rules: {
24 // RECOMMENDED RULES
25 "@rushstack/no-new-null": "error",
26 "no-empty": "error",
27 "no-void": "error",
28 "require-atomic-updates": "error",
29
30 // This rule ensures that our Intellisense looks good by verifying the TSDoc syntax.
31 "tsdoc/syntax": "error",
32
33 // In some cases, type inference can be wrong, and this can cause a "flip-flop" of type changes in our
34 // API documentation. For example, type inference might decide a function returns a concrete type
35 // instead of an interface. This has no runtime impact, but would cause compilation problems.
36 "@typescript-eslint/explicit-function-return-type": [
37 "error",
38 {
39 allowExpressions: true,
40 allowTypedFunctionExpressions: true,
41 allowHigherOrderFunctions: true,
42 allowDirectConstAssertionInArrowFunctions: true,
43 allowConciseArrowFunctionExpressionsStartingWithVoid: false,
44 },
45 ],
46
47 "unicorn/empty-brace-spaces": "off",
48
49 // Rationale: Destructuring of `Array.entries()` in order to get the index variable results in a
50 // significant performance regression [node 14 x64].
51 "unicorn/no-for-loop": "off",
52
53 /**
54 * Disabled because we will lean on the formatter (i.e. prettier) to enforce indentation policy.
55 * @remarks This rule also directly conflicts with prettier's formatting of nested ternary expressions.
56 */
57 "unicorn/no-nested-ternary": "off",
58
59 /**
60 * Disabled due to false positives / disruptive behavior of auto-fix.
61 * See {@link https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2018}.
62 * We may consider re-enabling once the above issue has been resolved.
63 */
64 "unicorn/no-useless-spread": "off",
65
66 /**
67 * Disabled due to the sheer number of false positives it detects, and because it is sometimes valuable to
68 * explicitly denote `undefined`.
69 */
70 "unicorn/no-useless-undefined": "off",
71
72 /**
73 * By default, this rule conflicts with our internal error code formats.
74 * Only enforce `_` separator consistency if any such separators appear in the number literal.
75 */
76 "unicorn/numeric-separators-style": ["error", { onlyIfContainsSeparator: true }],
77
78 "unicorn/prevent-abbreviations": "off",
79
80 /**
81 * Disabled because we don't yet target a ES version that includes .at().
82 */
83 "unicorn/prefer-at": "off",
84
85 /**
86 * Disabled because we use EventEmitter everywhere today and changing it will be a bigger change outside of lint
87 * rules.
88 */
89 "unicorn/prefer-event-target": "off",
90
91 /**
92 * Disabled because we don't yet target a ES version that includes string.replaceAll.
93 */
94 "unicorn/prefer-string-replace-all": "off",
95
96 /**
97 * Disabled because we will lean on the formatter (i.e. prettier) to enforce indentation policy.
98 */
99 "unicorn/template-indent": "off",
100
101 /**
102 * Disabled because it is incompatible with prettier.
103 */
104 "unicorn/number-literal-case": "off",
105
106 /**
107 * The rule seems to crash on some of our code
108 */
109 "unicorn/expiring-todo-comments": "off",
110
111 /**
112 * Disallows the `any` type.
113 * Using the `any` type defeats the purpose of using TypeScript.
114 * When `any` is used, all compiler type checks around that value are ignored.
115 *
116 * @see https://typescript-eslint.io/rules/no-explicit-any
117 */
118 "@typescript-eslint/no-explicit-any": [
119 "error",
120 {
121 /**
122 * For certain cases, like rest parameters, any is required to allow arbitrary argument types.
123 * @see https://typescript-eslint.io/rules/no-explicit-any/#ignorerestargs
124 */
125 ignoreRestArgs: true,
126 },
127 ],
128
129 /**
130 * Requires explicit typing for anything exported from a module. Explicit types for function return
131 * values and arguments makes it clear to any calling code what is the module boundary's input and
132 * output.
133 */
134 "@typescript-eslint/explicit-module-boundary-types": "error",
135
136 /**
137 * Disallows calling a function with a value with type `any`.
138 * Despite your best intentions, the `any` type can sometimes leak into your codebase.
139 * Call a function with `any` typed argument are not checked at all by TypeScript, so it creates a
140 * potential safety hole, and source of bugs in your codebase.
141 */
142 "@typescript-eslint/no-unsafe-argument": "error",
143
144 /**
145 * Disallows assigning any to a variable, and assigning any[] to an array destructuring. Assigning an
146 * any typed value to a variable can be hard to pick up on, particularly if it leaks in from an external
147 * library.
148 */
149 "@typescript-eslint/no-unsafe-assignment": "error",
150
151 /**
152 * Disallows calling any variable that is typed as any. The arguments to, and return value of calling an
153 * any typed variable are not checked at all by TypeScript.
154 */
155 "@typescript-eslint/no-unsafe-call": "error",
156
157 /**
158 * Disallows member access on any variable that is typed as any. The arguments to, and return value of
159 * calling an any typed variable are not checked at all by TypeScript.
160 */
161 "@typescript-eslint/no-unsafe-member-access": "error",
162
163 /**
164 * Disallows returning a value with type any from a function.
165 *
166 * Despite your best intentions, the any type can sometimes leak into your codebase.
167 * Returned any typed values are not checked at all by TypeScript, so it creates a potential safety
168 * hole, and source of bugs in your codebase.
169 */
170 "@typescript-eslint/no-unsafe-return": "error",
171
172 // #region eslint-plugin-jsdoc rules
173
174 /**
175 * Ensures all JSDoc/TSDoc comments use the multi-line format for consistency.
176 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-multiline-blocks>
177 */
178 "jsdoc/multiline-blocks": ["error", { noSingleLineBlocks: true }],
179
180 /**
181 * Require the description (summary) component in JSDoc/TSDoc comments
182 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-description>
183 */
184 "jsdoc/require-description": ["error", { checkConstructors: false }],
185
186 // #endregion
187 },
188 overrides: [
189 {
190 // Rules only for React files
191 files: ["*.jsx", "*.tsx"],
192 rules: {
193 // Conflicts with best practices for various React hooks.
194 "unicorn/consistent-function-scoping": "off",
195 },
196 },
197 {
198 // Rules for test code
199 files: ["*.spec.ts", "*.test.ts", "**/test/**"],
200 rules: {
201 // Does not work well with describe/it block scoping
202 "unicorn/consistent-function-scoping": "off",
203 // We run most of our tests in a Node.js environment, so this rule is not important and makes
204 // file-system logic more cumbersome.
205 "unicorn/prefer-module": "off",
206 },
207 },
208 {
209 // Rules only for type validation files
210 files: ["**/types/*validate*Previous*.ts"],
211 rules: {
212 "@typescript-eslint/no-explicit-any": "off",
213 "@typescript-eslint/no-unsafe-argument": "off",
214 },
215 },
216 ],
217};