-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.mts
160 lines (141 loc) · 5.2 KB
/
eslint.mts
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
import eslint from "@eslint/js";
import type { TSESLint } from "@typescript-eslint/utils";
import eslintConfigPrettier from "eslint-config-prettier";
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
import importPlugin from "eslint-plugin-import";
import reactPlugin from "eslint-plugin-react";
// @ts-ignore
import hooksPlugin from "eslint-plugin-react-hooks";
import unusedImports from "eslint-plugin-unused-imports";
import type { ConfigWithExtends } from "typescript-eslint";
import tseslint from "typescript-eslint";
/* eslint-enable @typescript-eslint/ban-ts-comment */
export type FlatConfigs = {
[t: string]: TSESLint.FlatConfig.Config;
};
export const configs = {
ignores: {
ignores: ["*.d.ts", "*.d.mts", "**/*.d.ts", "**/*.d.mts"],
},
reactHooksRecommended: {
plugins: {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
"react-hooks": hooksPlugin,
},
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
rules: {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access */
...hooksPlugin.configs.recommended.rules,
},
},
unusedImportsRecommended: {
plugins: {
"unused-imports": unusedImports,
},
rules: {
// Typescript overrides from recommended
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
},
},
thelabRecommended: {
settings: {
"react": {
version: "detect",
},
"import/resolver": "typescript",
},
rules: {
// Prettier does this.
"sort-imports": 0,
// TypeScript handles this for us.
"import/namespace": 0,
"import/named": 0,
"import/no-unresolved": 0,
// immer's default export is produce, not matching the filename.
// TODO: I think immer can be specifically imported now.
"import/no-named-as-default": 0,
"import/no-named-as-default-member": 0,
"import/newline-after-import": ["error"],
"import/first": ["error"],
"import/order": 0,
// React overrides
"react/prop-types": "off",
"react/display-name": "off",
// We use empty arrays to run once, etc.
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
// For when we do RPC calls and forget to call await on the promise
// to check against a null return.
"@typescript-eslint/no-unnecessary-condition": "error",
// We use empty callbacks that are no-ops sometimes.
"@typescript-eslint/no-empty-function": [
"error",
{
allow: ["arrowFunctions"],
},
],
// See: https://github.com/typescript-eslint/typescript-eslint/issues/4619#issuecomment-1057096238
// We want async callbacks to React event handlers
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
},
},
],
// https://www.reddit.com/r/typescript/comments/uiil9k/am_i_crazy_for_expecting_typescript_to_catch_this/
"@typescript-eslint/no-use-before-define": ["error"],
},
},
} as const satisfies FlatConfigs;
export const recommended: TSESLint.FlatConfig.Config[] = [
configs.ignores,
eslint.configs.recommended,
...(reactPlugin.configs.flat
? [reactPlugin.configs.flat.recommended as TSESLint.FlatConfig.Config]
: []),
configs.reactHooksRecommended,
...tseslint.configs.recommendedTypeChecked,
eslintConfigPrettier,
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
importPlugin.flatConfigs.typescript as TSESLint.FlatConfig.Config,
importPlugin.flatConfigs.errors as TSESLint.FlatConfig.Config,
importPlugin.flatConfigs.warnings as TSESLint.FlatConfig.Config,
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
configs.unusedImportsRecommended,
configs.thelabRecommended,
];
export const getTSConfig = ({
parserOptions,
configs = [],
}: {
parserOptions: Partial<TSESLint.FlatConfig.ParserOptions> & {
tsconfigRootDir: string;
};
configs: ConfigWithExtends[];
}): ReturnType<typeof tseslint.config> => {
return tseslint.config(
...recommended,
{
languageOptions: {
parserOptions: {
project: ["./tsconfig.json"],
projectService: true,
...parserOptions,
},
},
},
...configs,
);
};