-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypescript.js
More file actions
141 lines (128 loc) · 4.34 KB
/
typescript.js
File metadata and controls
141 lines (128 loc) · 4.34 KB
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
module.exports = {
extends: [
'airbnb-base',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier',
require.resolve('./rules'),
],
plugins: ['deprecation'],
// parser @typescript-eslint/parser already set by extends from plugin:@typescript-eslint/recommended
// however, it needs parserOptions `project: './tsconfig.json'` to work
parserOptions: { sourceType: 'module', project: './tsconfig.json' },
rules: {
// additional ts rules
// deprecation
'deprecation/deprecation': 'warn',
// switch to typescript version rules
// camelcase
camelcase: 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase', 'PascalCase', 'UPPER_CASE', 'snake_case'],
leadingUnderscore: 'allowSingleOrDouble',
},
{
selector: 'variable',
modifiers: ['destructured'],
format: null,
},
{
selector: [
'classProperty',
'objectLiteralProperty',
'typeProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
'enumMember',
],
modifiers: ['requiresQuotes'],
format: null,
},
// SomeEnum.ENUM_VALUE
{
selector: 'enum',
format: ['PascalCase'],
},
{
selector: 'enumMember',
format: ['UPPER_CASE'],
},
// variableLike
{
selector: 'variableLike',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
// - const variable allows UPPER_CASE
{
selector: 'variable',
modifiers: ['const'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
},
// Type, Interface
{
selector: 'typeLike',
format: ['PascalCase'],
},
// object literal
{
selector: 'objectLiteralProperty',
format: ['camelCase', 'PascalCase', 'snake_case', 'UPPER_CASE'],
},
{
selector: 'objectLiteralProperty',
format: null,
// __html used in React is a sepcial case
filter: {
regex: '__html',
match: true,
},
},
],
// array type
'@typescript-eslint/array-type': ['error'],
// no-unused-vars
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
// no-unused-expressions
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': ['error'],
// no-useless-constructor
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': ['error'],
// no-shadow
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
// TypeScript compilation already ensures that named imports exist in the referenced module
'import/named': 'off',
},
settings: {
// Append 'ts' extensions to Airbnb 'import/resolver' setting
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.native.js'],
},
// for deprecation plugin
typescript: {
alwaysTryTypes: true,
},
},
// Append 'ts' extensions to Airbnb 'import/extensions' setting
'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.native.js'],
// use typescript parser for ts, tsx import
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
};
try {
// check if typescript installed
require.resolve('typescript');
} catch (e) {
// disable typescript related config if current project doesn't use typescript
module.exports = {};
}