-
Notifications
You must be signed in to change notification settings - Fork 14
/
eslint.config.mjs
178 lines (161 loc) · 5.38 KB
/
eslint.config.mjs
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// @ts-check
import tseslint from "typescript-eslint";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import reactPlugin from "eslint-plugin-react";
import vitest from "@vitest/eslint-plugin";
import { fixupPluginRules } from "@eslint/compat";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import eslintConfigPrettier from "eslint-config-prettier";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [
{
ignores: [
"**/node_modules",
"**/dist",
"tmpDist*",
"**/tmpPackage*",
"**/custom-vitest-environment.ts",
// TODO use a separate config for files that doesn't use TypeScript
"**/*.js",
"vitest.config.js",
"scripts",
".prettierrc.js",
"eslint.config.mjs",
"jest.config.mjs",
],
},
...compat.plugins("require-extensions"),
...compat.extends("plugin:require-extensions/recommended"),
js.configs.recommended,
{
files: ["**/*.js", "**/*.jsx", "**/*ts", "**/*.tsx"],
plugins: {
"@typescript-eslint": tseslint.plugin,
react: reactPlugin,
"react-hooks": fixupPluginRules(reactHooksPlugin),
vitest,
},
languageOptions: {
globals: {
...globals.amd,
...globals.browser,
...globals.node,
},
parser: tseslint.parser,
ecmaVersion: 2022,
sourceType: "module",
parserOptions: {
project: ["./tsconfig.json"],
tsconfigRootDir: ".",
},
},
rules: {
...reactHooksPlugin.configs.recommended.rules,
"no-debugger": "error",
// any is terrible but we use it a lot (even in our public code).
"@typescript-eslint/no-explicit-any": "off",
// asserting that values aren't null is risky but useful.
"@typescript-eslint/no-non-null-assertion": "off",
// Warn against interpolating objects
"@typescript-eslint/restrict-template-expressions": "error",
"no-redeclare": "off", // breaks for overloads
"@typescript-eslint/no-redeclare": "error",
"no-undef": "off",
// allow (_arg: number) => {}
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"no-restricted-syntax": [
"error",
{
// From https://github.com/typescript-eslint/typescript-eslint/issues/1391#issuecomment-1124154589
// Prefer `private` ts keyword to `#private` private methods
selector:
":matches(PropertyDefinition, MethodDefinition) > PrivateIdentifier.key",
message: "Use `private` instead",
},
],
// Makes it harder to accidentally fire off a promise without waiting for it.
"@typescript-eslint/no-floating-promises": "error",
// Since `const x = <number>foo;` syntax is ambiguous with JSX syntax some tools don't support it.
// In particular we need this for depcheck https://github.com/depcheck/depcheck/issues/585
"@typescript-eslint/consistent-type-assertions": [
"error",
{
assertionStyle: "as",
},
],
eqeqeq: ["error", "always"],
// vitest (manually enabled until we can upgrade eslint)
"vitest/no-focused-tests": [
"error",
{
fixable: false,
},
],
// Use `logMessage` and friends (CLI specific) or `logger.log` instead.
"no-console": "error",
},
},
{
name: "CLI-specific",
files: ["src/cli/**/*.ts", "src/bundler/**/*.ts"],
ignores: ["**/*.test.ts"],
rules: {
"no-restricted-imports": [
"warn",
{
patterns: [
{
group: ["fs", "node:fs"],
message:
"Use a `Filesystem` implementation like `nodeFs` instead of Node's 'fs' package directly.",
},
{
group: ["fs/promises", "node:fs/promises"],
message:
"Use a `Filesystem` implementation like `nodeFs` instead of Node's 'fs/promises' package directly. Additionally, use synchronous filesystem IO within our CLI.",
},
],
},
],
"no-restricted-syntax": [
"error",
{
selector:
":matches(PropertyDefinition, MethodDefinition) > PrivateIdentifier.key",
message: "Use `private` instead",
},
{
selector: "ThrowStatement",
message:
"Don't use `throw` if this is a developer-facing error message and this code could be called by `npx convex dev`. Instead use `ctx.crash`.",
},
// TODO: fix to allow process.exit(0) but not process.exit(1)
// {
// message: "Use flushAndExit from convex/src/cli/utils.ts instead of process.exit so that Sentry gets flushed.",
// selector: "CallExpression[callee.object.name='process'][callee.property.name='exit'][callee.value=1]"
// }
],
"no-throw-literal": ["error"],
},
},
eslintConfigPrettier,
];