-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.mjs
118 lines (115 loc) · 4.07 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
// @ts-check
// apparently it's not standard to publish types for eslint plugins
import pluginJs from "@eslint/js";
// @ts-expect-error no types for this plugin
import configPrettier from "eslint-config-prettier";
// @ts-expect-error no types for this plugin
import pluginBetterMutation from "eslint-plugin-better-mutation";
import pluginJest from "eslint-plugin-jest";
import pluginJestDom from "eslint-plugin-jest-dom";
// @ts-expect-error no types for this plugin
import pluginJsxA11y from "eslint-plugin-jsx-a11y";
// @ts-expect-error no types for this plugin
import pluginReactHooks from "eslint-plugin-react-hooks";
// @ts-expect-error no types for this plugin
import pluginReactJsx from "eslint-plugin-react/configs/jsx-runtime.js";
// @ts-expect-error no types for this plugin
import pluginReactRecommended from "eslint-plugin-react/configs/recommended.js";
import pluginStorybook from "eslint-plugin-storybook";
import pluginTestingLibrary from "eslint-plugin-testing-library";
import globals from "globals";
import tseslint from "typescript-eslint";
export default tseslint.config(
pluginJs.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
// jsx-runtime only disables rules, so need both recommended and jsx.
{
...pluginReactRecommended,
settings: { react: { version: "detect" } },
},
...pluginStorybook.configs["flat/recommended"],
pluginReactJsx,
configPrettier,
{
ignores: ["*", "!js/", "!*.ts", "!*.mjs"],
},
{
name: "orbit",
linterOptions: {
reportUnusedDisableDirectives: "error",
},
languageOptions: {
globals: globals.browser,
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"better-mutation": pluginBetterMutation,
"jsx-a11y": pluginJsxA11y,
"react-hooks": pluginReactHooks,
},
rules: {
...pluginBetterMutation.configs.recommended.rules,
...pluginJsxA11y.configs.recommended.rules,
...pluginReactHooks.configs.recommended.rules,
// allow modifying module.exports
"better-mutation/no-mutation": ["error", { commonjs: true }],
// enforce "type" instead of enforcing "interface"
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
// unused arguments are fine if they have a leading _
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
reportUsedIgnorePattern: true,
varsIgnorePattern: "^_",
},
],
// `${number}` is fine
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
},
],
},
},
{
files: ["js/test/**", "js/**/*.test.*"],
plugins: {
jest: pluginJest,
"jest-dom": pluginJestDom,
"testing-library": pluginTestingLibrary,
},
rules: {
...pluginJest.configs["flat/style"].rules,
...pluginJest.configs["flat/recommended"].rules,
...pluginJestDom.configs["flat/recommended"].rules,
...pluginTestingLibrary.configs["flat/react"].rules,
// empty functions are fine
"@typescript-eslint/no-empty-function": "off",
// expect.any is untyped and triggers this all the time.
"@typescript-eslint/no-unsafe-assignment": "off",
// sometimes the easiest way to mock a complex test setup is to mutate something
"better-mutation/no-mutation": "off",
/* we do `view = render(); view.getBy()` which also doesn't require destructuring
and has less global mutable state than `screen`. */
"testing-library/prefer-screen-queries": "off",
},
},
{
// In this file, some plugins have missing types that cause type-aware lint errors.
files: ["eslint.config.mjs"],
rules: {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
},
},
);