1 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
2 | // See LICENSE in the project root for license information.
|
3 |
|
4 | // For the first 5 years of Rush, our lint rules required explicit types for most declarations
|
5 | // such as function parameters, function return values, and exported variables. Although more verbose,
|
6 | // declaring types (instead of relying on type inference) encourages engineers to create interfaces
|
7 | // that inspire discussions about data structure design. It also makes source files easier
|
8 | // to understand for code reviewers who may be unfamiliar with a particular project. Once developers get
|
9 | // used to the extra work of declaring types, it turns out to be a surprisingly popular practice.
|
10 | //
|
11 | // However in 2020, to make adoption easier for existing projects, this rule was relaxed. Explicit
|
12 | // type declarations are now optional for local variables (although still required in other contexts).
|
13 | // See this GitHub issue for background:
|
14 | //
|
15 | // https://github.com/microsoft/rushstack/issues/2206
|
16 | //
|
17 | // If you are onboarding a large existing code base, this new default will make adoption easier.
|
18 | //
|
19 | // On the other hand, if your top priority is to make source files more friendly for other
|
20 | // people to read, enable the "@rushstack/eslint-config/mixins/friendly-locals" mixin.
|
21 | // It will restore the requirement that local variables should have explicit type declarations.
|
22 | //
|
23 | // IMPORTANT: Your .eslintrc.js "extends" field must load mixins AFTER the profile.
|
24 | module.exports = {
|
25 | overrides: [
|
26 | {
|
27 | files: ['*.ts', '*.tsx'],
|
28 | rules: {
|
29 | '@rushstack/typedef-var': 'off', // <--- disabled by the mixin
|
30 |
|
31 | '@typescript-eslint/typedef': [
|
32 | 'warn',
|
33 | {
|
34 | arrayDestructuring: false,
|
35 | arrowParameter: false,
|
36 | memberVariableDeclaration: true,
|
37 | objectDestructuring: false,
|
38 | parameter: true,
|
39 | propertyDeclaration: true,
|
40 |
|
41 | variableDeclaration: true, // <--- reenabled by the mixin
|
42 |
|
43 | variableDeclarationIgnoreFunction: true
|
44 | }
|
45 | ]
|
46 | }
|
47 | },
|
48 | // Note that the above block also applies to *.test.ts, so we need to
|
49 | // reapply those overrides.
|
50 | {
|
51 | files: [
|
52 | // Test files
|
53 | '*.test.ts',
|
54 | '*.test.tsx',
|
55 | '*.spec.ts',
|
56 | '*.spec.tsx',
|
57 |
|
58 | // Facebook convention
|
59 | '**/__mocks__/*.ts',
|
60 | '**/__mocks__/*.tsx',
|
61 | '**/__tests__/*.ts',
|
62 | '**/__tests__/*.tsx',
|
63 |
|
64 | // Microsoft convention
|
65 | '**/test/*.ts',
|
66 | '**/test/*.tsx'
|
67 | ],
|
68 | rules: {
|
69 | '@typescript-eslint/typedef': [
|
70 | 'warn',
|
71 | {
|
72 | arrayDestructuring: false,
|
73 | arrowParameter: false,
|
74 | memberVariableDeclaration: true,
|
75 | objectDestructuring: false,
|
76 | parameter: true,
|
77 | propertyDeclaration: true,
|
78 | variableDeclaration: false, // <--- special case for test files
|
79 | variableDeclarationIgnoreFunction: true
|
80 | }
|
81 | ]
|
82 | }
|
83 | }
|
84 | ]
|
85 | };
|