-
Notifications
You must be signed in to change notification settings - Fork 0
/
typescript.js
103 lines (102 loc) · 3.72 KB
/
typescript.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
const {
rules,
overrides: [ testOverrides, ...overrides ],
} = require( '.' )
module.exports = {
parserOptions: {
project: './tsconfig.json',
},
overrides: [
{
files: [ '**/*.ts?(x)' ],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/stylistic-type-checked',
'airbnb-typescript',
],
rules: {
// No unused variables except when prepended with _ to indicate they're unused but required
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
},
],
// Although shadow variables can be confusing, disallowing them can lead to terrible naming
'@typescript-eslint/no-shadow': 'off',
// Trailing commas result in better diffs and allow generics to work in JSX files
'@typescript-eslint/comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'only-multiline',
enums: 'always-multiline',
generics: 'ignore',
tuples: 'always-multiline',
},
],
// Very broken for some types, so ignoring them makes certain TS-only constructs look nicer
'@typescript-eslint/indent': [
'error',
2,
{
ignoredNodes: [
'TSUnionType',
'TSIntersectionType',
'PropertyDefinition[decorators]',
'TSTypeParameterInstantiation',
],
},
],
// Let Typescript infer the return types
'@typescript-eslint/explicit-module-boundary-types': 'off',
// Sometimes you want to declare a function as async so that it returns a Promisified value
'@typescript-eslint/require-await': 'off',
// Use types throughout, not interfaces
'@typescript-eslint/consistent-type-definitions': [ 'error', 'type' ],
// Semi colons are visual garbage
'@typescript-eslint/semi': [ 'error', 'never' ],
// Typescript types should be delimeted by commas, not semi-colons
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'comma',
},
singleline: {
delimiter: 'comma',
},
},
],
// Can be visually verbose to have every class member separated with a newline
'@typescript-eslint/lines-between-class-members': 'off',
// Without this, TS path alias imports report missing file extension
'import/extensions': rules[ 'import/extensions' ],
},
},
{
...testOverrides,
rules: {
...testOverrides.rules,
// In testing, dynamic requires are often required
'@typescript-eslint/no-var-requires': 'off',
// Allows destructuring class methods - up to us to determine if it is an issue
'@typescript-eslint/unbound-method': 'off',
// Strict type safety can be more of a hindrance in tests sometimes
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// We don't care about floating promises in tests, and it causes a typing issue with act()
'@typescript-eslint/no-floating-promises': 'off',
// We know what we're doing in tests
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
...overrides,
],
}