/
typescript.ts
154 lines (146 loc) · 5.74 KB
/
typescript.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
import type { ESLintConfig } from "eslint-define-config"
import { prettierStyleRules } from "../utils/prettier"
export const typescript = {
extends: [
/** Configures import plugin for TypeScript */
"plugin:import/typescript",
...prettierStyleRules,
],
settings: {
/**
* Fixes the import plugin not handling packages with types packages installed correctly
* https://github.com/benmosher/eslint-plugin-import/issues/1552
* Might not be necessary anymore, but doesn't hurt to keep
*/
"import/external-module-folders": ["node_modules", "node_modules/@types"],
},
overrides: [
{
files: ["*.ts", "*.tsx", "*.vue"],
extends: [
/**
* Adds typescript rules, typescript parser
* https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
*/
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic",
"plugin:@typescript-eslint/stylistic-type-checked",
],
parserOptions: {
extraFileExtensions: [".vue"],
project: true,
warnOnUnsupportedTypeScriptVersion: false,
},
settings: {
/** Use TypeScript resolver so we can use `baseUrl` and `paths` */
"import/resolver": {
// {} is required for some reason, cant find a link to it anymore :(
typescript: {},
},
/** Configure node plugin to include TS files */
node: { tryExtensions: [".js", ".ts", ".tsx"] },
},
rules: {
/** Allow returning a promise when the function expects `void` */
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false,
},
],
/** Don't warn about non-null assertions - assume they're used responsibly */
"@typescript-eslint/no-non-null-assertion": "off",
/** Don't error on operating on `any`s - it's way too strict */
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
/** Require type-only exports to explicitly say that they are type exports, to help compilers */
"@typescript-eslint/consistent-type-exports": "off",
/** Don't warn on implicit function returns */
"@typescript-eslint/explicit-module-boundary-types": "off",
/** Allow unions or intersections with types that ruin them (any, unknown, etc.), it be used for enhancing IDE behavior */
"@typescript-eslint/no-redundant-type-constituents": "off",
/** Enforce using shorter Map constructor syntax */
"@typescript-eslint/consistent-generic-constructors": "error",
/** Require explanations for @ts-ignore:s */
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-expect-error": false,
"ts-ignore": "allow-with-description",
"ts-check": true,
"ts-nocheck": true,
minimumDescriptionLength: 6,
},
],
/** Require using `type` over `interface` */
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
/** Enforce using `x as type` over `<type>x` */
"@typescript-eslint/consistent-type-assertions": [
"error",
{ assertionStyle: "as" },
],
/** Allow void before floating promises */
"no-void": ["error", { allowAsStatement: true }],
/** Automatically format Array types to most readable version depending on complexity */
"@typescript-eslint/array-type": [
"error",
{
default: "array-simple",
readonly: "array-simple",
},
],
/** Allow comparing Enums with primitive values */
"@typescript-eslint/no-unsafe-enum-comparison": "off",
/** Allow using `any` as a parameter */
"@typescript-eslint/no-unsafe-argument": "off",
/* Does not work with types */
"n/no-unpublished-import": "off",
/* Overrides that add TS functionality */
"@typescript-eslint/no-shadow": ["error", { ignoreOnInitialization: true }],
"@typescript-eslint/no-loss-of-precision": "error",
"@typescript-eslint/no-useless-constructor": "error",
/* Disable duplicate/overridden rules */
camelcase: "off",
"no-shadow": "off",
"no-loss-of-precision": "off",
"no-useless-constructor": "off",
/** TS uses ESM */
"n/no-unsupported-features/es-syntax": "off",
"import/named": "off",
"import/namespace": "off",
"import/default": "off",
"import/export": "off",
"import/no-duplicated": "off",
"import/no-unresolved": "off",
/* Disable checks that a well-configured TypeScript config does for you, but is not disabled by /recommended */
"no-unused-expressions": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"n/no-missing-import": "off",
"n/no-extraneous-import": "off",
"unicorn/no-array-callback-reference": "off",
},
},
{
files: ["*.vue"],
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
extraFileExtensions: [".vue"],
project: "**/tsconfig.json",
warnOnUnsupportedTypeScriptVersion: false,
},
},
{
files: ["*.d.ts"],
rules: {
/** Type definition files need different rules than normal files */
"import/no-duplicates": "off",
"import/order": "off",
},
},
],
} satisfies ESLintConfig