UNPKG

12.4 kBJavaScriptView Raw
1/*!
2 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3 * Licensed under the MIT License.
4 */
5
6module.exports = {
7 env: {
8 browser: true,
9 es6: true,
10 node: true,
11 },
12 extends: [
13 "./eslint7",
14 "plugin:eslint-comments/recommended",
15 "plugin:import/errors",
16 "plugin:import/warnings",
17 "plugin:import/typescript",
18 ],
19 globals: {
20 Atomics: "readonly",
21 SharedArrayBuffer: "readonly",
22 },
23 parser: "@typescript-eslint/parser",
24 parserOptions: {
25 ecmaFeatures: {
26 jsx: true,
27 },
28 ecmaVersion: 2018,
29 sourceType: "module",
30 project: "./tsconfig.json",
31 },
32 plugins: [
33 // Plugin documentation: https://www.npmjs.com/package/@rushstack/eslint-plugin
34 "@rushstack/eslint-plugin",
35 // Plugin documentation: https://www.npmjs.com/package/@rushstack/eslint-plugin-security
36 "@rushstack/eslint-plugin-security",
37 // Plugin documentation: https://www.npmjs.com/package/@typescript-eslint/eslint-plugin
38 "@typescript-eslint/eslint-plugin",
39 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-jsdoc
40 "eslint-plugin-jsdoc",
41 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-promise
42 "eslint-plugin-promise",
43 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-tsdoc
44 "eslint-plugin-tsdoc",
45 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-unused-imports
46 "unused-imports",
47 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-react
48 "react",
49 // Plugin documentation: https://www.npmjs.com/package/eslint-plugin-unicorn
50 "unicorn",
51 ],
52 reportUnusedDisableDirectives: true,
53 rules: {
54 // The @rushstack rules are documented in the package README:
55 // https://www.npmjs.com/package/@rushstack/eslint-plugin
56 "@rushstack/no-new-null": "warn",
57
58 // RATIONALE: Harmless. Our guideline is to only use leading underscores on private members
59 // when required to avoid a conflict between private fields and a public property.
60 // Docs: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
61 "@typescript-eslint/naming-convention": [
62 "error",
63 {
64 selector: "accessor",
65 modifiers: ["private"],
66 format: ["camelCase"],
67 leadingUnderscore: "allow",
68 },
69 ],
70
71 // Encourages minimal disabling of eslint rules, while still permitting whole-file exclusions.
72 "eslint-comments/disable-enable-pair": [
73 "error",
74 {
75 allowWholeFile: true,
76 },
77 ],
78
79 // ENABLED INTENTIONALLY
80 "@typescript-eslint/ban-types": "error",
81 "@typescript-eslint/dot-notation": "error",
82 "@typescript-eslint/no-non-null-assertion": "error",
83 "@typescript-eslint/no-unnecessary-type-assertion": "error",
84 "eqeqeq": ["error", "smart"],
85 "max-len": [
86 "error",
87 {
88 ignoreRegExpLiterals: false,
89 ignoreStrings: false,
90 code: 120,
91 },
92 ],
93 "no-multi-spaces": [
94 "error",
95 {
96 ignoreEOLComments: true,
97 },
98 ],
99
100 // Note: this can be replaced altogether by `@typescript-eslint/no-unused-vars`,
101 // but that rule covers many more scenarios than this one does, and there are many violations,
102 // currently in the repository, so it has not been enabled yet.
103 "unused-imports/no-unused-imports": "error",
104
105 "valid-typeof": "error",
106
107 // Catches a common coding mistake where "resolve" and "reject" are confused.
108 "promise/param-names": "warn",
109
110 "unicorn/better-regex": "error",
111 "unicorn/filename-case": [
112 "error",
113 {
114 cases: {
115 camelCase: true,
116 pascalCase: true,
117 },
118 },
119 ],
120 "unicorn/no-new-buffer": "error",
121 "unicorn/no-unsafe-regex": "error",
122 "unicorn/prefer-switch": "error",
123 "unicorn/prefer-ternary": "error",
124 "unicorn/prefer-type-error": "error",
125
126 // DISABLED INTENTIONALLY
127 // Disabled because we don't require that all variable declarations be explicitly typed.
128 "@rushstack/typedef-var": "off",
129 "@typescript-eslint/explicit-function-return-type": "off",
130 "@typescript-eslint/explicit-member-accessibility": "off",
131 "@typescript-eslint/indent": "off", // Off because it conflicts with typescript-formatter
132 "@typescript-eslint/member-ordering": "off",
133 "@typescript-eslint/no-explicit-any": "off",
134 "@typescript-eslint/no-parameter-properties": "off",
135 "@typescript-eslint/no-unused-vars": "off",
136 "@typescript-eslint/no-use-before-define": "off",
137 "@typescript-eslint/typedef": "off",
138 "func-call-spacing": "off", // Off because it conflicts with typescript-formatter
139 "no-empty": "off",
140 "no-void": "off",
141 "require-atomic-updates": "off",
142 "dot-notation": "off", // Superseded by @typescript-eslint/dot-notation
143 "no-unused-expressions": "off", // Superseded by @typescript-eslint/no-unused-expressions
144
145 // FORMATTING RULES
146 "@typescript-eslint/brace-style": [
147 "error",
148 "1tbs",
149 {
150 allowSingleLine: true,
151 },
152 ],
153 "@typescript-eslint/comma-spacing": "error",
154 "@typescript-eslint/func-call-spacing": "error",
155 "@typescript-eslint/keyword-spacing": "error",
156 "@typescript-eslint/member-delimiter-style": [
157 "error",
158 {
159 multiline: {
160 delimiter: "semi",
161 requireLast: true,
162 },
163 singleline: {
164 delimiter: "semi",
165 requireLast: true,
166 },
167 multilineDetection: "brackets",
168 },
169 ],
170 "@typescript-eslint/object-curly-spacing": ["error", "always"],
171 "@typescript-eslint/semi": ["error", "always"],
172 "@typescript-eslint/space-before-function-paren": [
173 "error",
174 {
175 anonymous: "never",
176 asyncArrow: "always",
177 named: "never",
178 },
179 ],
180 "@typescript-eslint/space-infix-ops": "error",
181 "@typescript-eslint/type-annotation-spacing": "error",
182 "array-bracket-spacing": "error",
183 "arrow-spacing": "error",
184 "block-spacing": "error",
185 "dot-location": ["error", "property"],
186 "jsx-quotes": "error",
187 "key-spacing": "error",
188 "space-unary-ops": "error",
189 "switch-colon-spacing": "error",
190
191 // This rule ensures that our Intellisense looks good by verifying the TSDoc syntax.
192 "tsdoc/syntax": "error",
193
194 // #region eslint-plugin-jsdoc rules
195
196 /**
197 * Ensures that conflicting access tags don't exist in the same comment.
198 * See <https://github.com/gajus/eslint-plugin-jsdoc#check-access>.
199 */
200 "jsdoc/check-access": "error",
201
202 /**
203 * Ensures consistent line formatting in JSDoc/TSDoc comments
204 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-check-alignment>
205 */
206 "jsdoc/check-line-alignment": "error",
207
208 /**
209 * The syntax this validates does not accommodate the syntax used by API-Extractor
210 * See <https://api-extractor.com/pages/tsdoc/tag_example/>
211 */
212 "jsdoc/check-examples": "off",
213
214 /**
215 * Ensures correct indentation within JSDoc/TSDoc comment body
216 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-check-indentation>
217 */
218 "jsdoc/check-indentation": "error",
219
220 /**
221 * Covered by `tsdoc/syntax`
222 */
223 "jsdoc/check-tag-names": "off",
224
225 /**
226 * Ensures that JSDoc/TSDoc "modifier" tags are empty.
227 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-empty-tags>
228 */
229 "jsdoc/empty-tags": "error",
230
231 /**
232 * Ensures multi-line formatting meets JSDoc/TSDoc requirements.
233 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-no-bad-blocks>
234 */
235 "jsdoc/no-bad-blocks": "error",
236
237 /**
238 * Requires that each line in a JSDoc/TSDoc comment starts with a `*`.
239 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-asterisk-prefix>
240 */
241 "jsdoc/require-asterisk-prefix": "error",
242
243 /**
244 * Ensure function/method parameter comments include a `-` between name and description.
245 * Useful to ensure API-Extractor compatability.
246 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-hyphen-before-param-description>.
247 */
248 "jsdoc/require-hyphen-before-param-description": "error",
249
250 /**
251 * Require `@param` tags be non-empty.
252 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-param-description>
253 */
254 "jsdoc/require-param-description": "error",
255
256 /**
257 * Requires `@returns` tags to be non-empty.
258 * See <https://github.com/gajus/eslint-plugin-jsdoc#user-content-eslint-plugin-jsdoc-rules-require-returns-description>
259 */
260 "jsdoc/require-returns-description": "error",
261
262 // #endregion
263
264 "@typescript-eslint/prefer-includes": "error",
265 "@typescript-eslint/prefer-nullish-coalescing": "error",
266 "@typescript-eslint/prefer-optional-chain": "error",
267 },
268 overrides: [
269 {
270 // Rules only for TypeScript files
271 files: ["*.ts", "*.tsx"],
272 rules: {
273 "dot-notation": "off", // Superseded by @typescript-eslint/dot-notation
274 "no-unused-expressions": "off", // Superseded by @typescript-eslint/no-unused-expressions
275 },
276 settings: {
277 jsdoc: {
278 mode: "typescript",
279 },
280 },
281 },
282 {
283 // Rules only for test files
284 files: ["*.spec.ts", "src/test/**"],
285 rules: {
286 "@typescript-eslint/no-invalid-this": "off",
287 "@typescript-eslint/unbound-method": "off", // This rule has false positives in many of our test projects.
288 },
289 },
290 {
291 // Rules only for type validation files
292 files: ["**/types/*validate*Previous.ts"],
293 rules: {
294 "@typescript-eslint/comma-spacing": "off",
295 "@typescript-eslint/consistent-type-imports": "off",
296 "max-lines": "off",
297 },
298 },
299 ],
300 settings: {
301 "import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
302 "import/parsers": {
303 "@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
304 },
305 "import/resolver": {
306 node: {
307 extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
308 },
309 },
310 "jsdoc": {
311 // The following are intended to keep js/jsx JSDoc comments in line with TSDoc syntax used in ts/tsx code.
312 tagNamePreference: {
313 arg: {
314 message: "Please use @param instead of @arg.",
315 replacement: "param",
316 },
317 argument: {
318 message: "Please use @param instead of @argument.",
319 replacement: "param",
320 },
321 return: {
322 message: "Please use @returns instead of @return.",
323 replacement: "returns",
324 },
325 },
326 },
327 },
328};