/
index.ts
161 lines (152 loc) · 6.23 KB
/
index.ts
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import configStandard from './eslint-config-standard'
import { Linter } from 'eslint'
const equivalents = [
'comma-spacing',
'dot-notation',
'brace-style',
'func-call-spacing',
'indent',
'keyword-spacing',
'lines-between-class-members',
'no-array-constructor',
'no-dupe-class-members',
'no-extra-parens',
'no-loss-of-precision',
'no-redeclare',
'no-throw-literal',
'no-unused-vars',
'no-unused-expressions',
'no-useless-constructor',
'object-curly-spacing',
'quotes',
'semi',
'space-before-blocks',
'space-before-function-paren',
'space-infix-ops'
] as const
const ruleFromStandard = (name: string): Linter.RuleEntry => {
if (configStandard.rules === undefined) throw new Error()
const rule = configStandard.rules[name]
if (rule === undefined) throw new Error()
if (typeof rule !== 'object') return rule
return JSON.parse(JSON.stringify(rule))
}
function fromEntries<T> (iterable: Array<[string, T]>): Record<string, T> {
return [...iterable].reduce<Record<string, T>>((obj, [key, val]) => {
obj[key] = val
return obj
}, {})
}
const config: Linter.Config = {
extends: 'eslint-config-standard',
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
rules: {
'comma-dangle': 'off',
// TypeScript has this functionality by default:
'no-undef': 'off',
// Rules replaced by @typescript-eslint versions:
...fromEntries(equivalents.map((name) => [name, 'off'])),
camelcase: 'off',
'no-use-before-define': 'off',
// @typescript-eslint versions of Standard.js rules:
...fromEntries(equivalents.map((name) => [`@typescript-eslint/${name}`, ruleFromStandard(name)])),
'@typescript-eslint/no-use-before-define': ['error', {
functions: false,
classes: false,
enums: false,
variables: false,
typedefs: false // Only the TypeScript rule has this option.
}],
// Rules exclusive to Standard TypeScript:
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/comma-dangle': ['error', {
arrays: 'never',
objects: 'never',
imports: 'never',
exports: 'never',
functions: 'never',
enums: 'ignore',
generics: 'ignore',
tuples: 'ignore'
}],
'@typescript-eslint/consistent-indexed-object-style': ['error', 'record'],
'@typescript-eslint/consistent-type-assertions': [
'error',
{
assertionStyle: 'as',
objectLiteralTypeAssertions: 'never'
}
],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/explicit-function-return-type': ['error', {
allowExpressions: true,
allowHigherOrderFunctions: true,
allowTypedFunctionExpressions: true,
allowDirectConstAssertionInArrowFunctions: true
}],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: { delimiter: 'none' },
singleline: { delimiter: 'comma', requireLast: false }
}
],
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/naming-convention': ['error', {
selector: 'variableLike',
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
format: ['camelCase', 'PascalCase', 'UPPER_CASE']
}],
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }],
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-this-alias': ['error', { allowDestructuring: true }],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignoreConditionalTests: false, ignoreMixedLogicalExpressions: false }],
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': ['error', { ignoreStringArrays: true }],
'@typescript-eslint/restrict-plus-operands': ['error', { checkCompoundAssignments: true }],
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': ['error', {
allowString: false,
allowNumber: false,
allowNullableObject: false,
allowNullableBoolean: false,
allowNullableString: false,
allowNullableNumber: false,
allowAny: false
}],
'@typescript-eslint/triple-slash-reference': ['error', { lib: 'never', path: 'never', types: 'never' }],
'@typescript-eslint/type-annotation-spacing': 'error',
'no-void': ['error', { allowAsStatement: true }]
}
}
]
}
export = config