-
Notifications
You must be signed in to change notification settings - Fork 0
/
typescript.js
76 lines (74 loc) · 2.76 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
// @ts-check
/** @type {import('eslint').Linter.Config} */
module.exports = {
overrides: [
// TypeScript files
{
files: ['**/*.{ts,tsx,mts,cts}'],
extends: [
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts
'plugin:@typescript-eslint/recommended-type-checked',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict-type-checked.ts
'plugin:@typescript-eslint/strict-type-checked',
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts
'plugin:@typescript-eslint/stylistic-type-checked',
],
plugins: ['@typescript-eslint'],
parserOptions: {
project: true,
},
rules: {
// Disallow all Type Assertions. The default allows `as` assertions
'@typescript-eslint/consistent-type-assertions': [
'warn',
{ assertionStyle: 'never' },
],
// Ensure that type imports are imported with the `type` keyword
'@typescript-eslint/consistent-type-imports': [
'warn',
{
prefer: 'type-imports',
fixStyle: 'inline-type-imports',
},
],
// Don't warn about unused vars if they start with an underscore
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'after-used',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
// Turning off due to false positives.
// e.g. https://codesandbox.io/p/devbox/4xq3ql?file=%2Findex.ts%3A20%2C8
// - https://typescript-eslint.io/rules/no-unnecessary-condition/#when-not-to-use-it
// - https://github.com/microsoft/TypeScript/issues/9998
'@typescript-eslint/no-unnecessary-condition': 'off',
},
},
// TypeScript files with JSX only
{
files: ['**/*.tsx'],
rules: {
// False positive when using `onClick={() => someFunc()}`
// Will result in an unnecessary function body, which bloats the code
'@typescript-eslint/no-confusing-void-expression': 'off',
// False positive when using `onClick={() => someAsyncFunc()}`
'@typescript-eslint/no-misused-promises': [
'warn',
{
checksVoidReturn: {
// https://typescript-eslint.io/rules/no-misused-promises/#attributes
attributes: false,
},
},
],
},
},
],
};