-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
178 lines (172 loc) · 6.27 KB
/
eslint.config.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
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
import jsPlugin from '@eslint/js';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import prettierConfig from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import jestPlugin from 'eslint-plugin-jest';
import jestDOMPlugin from 'eslint-plugin-jest-dom';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
import markdownPlugin from 'eslint-plugin-markdown';
import reactPlugin from 'eslint-plugin-react';
import reactCompilerPlugin from 'eslint-plugin-react-compiler';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import testingLibraryPlugin from 'eslint-plugin-testing-library';
import tsSortKeysPlugin from 'eslint-plugin-typescript-sort-keys';
import globals from 'globals';
export default [
jsPlugin.configs.recommended,
jsxA11yPlugin.flatConfigs.strict,
prettierConfig,
// Global ignores
{
ignores: [
'.pnp.cjs',
'superflare.env.d.ts',
'worker-configuration.d.ts',
'.wrangler/',
'.yarn/',
'build/',
'public/',
],
},
// React
{
files: ['**/*.{js,jsx,ts,tsx}'],
languageOptions: {
globals: { ...globals.browser },
},
plugins: {
react: reactPlugin,
'react-compiler': reactCompilerPlugin,
'react-hooks': reactHooksPlugin,
},
settings: {
formComponents: ['Form'],
linkComponents: [
{ name: 'Link', linkAttribute: 'to' },
{ name: 'NavLink', linkAttribute: 'to' },
],
react: { version: 'detect' },
},
rules: {
...reactPlugin.configs.recommended.rules,
...reactPlugin.configs['jsx-runtime'].rules,
...reactHooksPlugin.configs.recommended.rules,
'react-compiler/react-compiler': 'warn',
'react/jsx-no-leaked-render': ['warn', { validStrategies: ['ternary'] }],
'react/jsx-sort-props': 'warn',
'react/no-unknown-property': [
'error',
{
ignore: ['popoverTarget', 'popoverTargetAction', 'precedence'],
},
],
'react-hooks/exhaustive-deps': [
'warn',
{ enableDangerousAutofixThisMayCauseInfiniteLoops: true },
],
'no-shadow': 'error',
'sort-imports': ['warn', { ignoreCase: true, ignoreDeclarationSort: true }],
},
},
// Typescript
{
files: ['**/*.{ts,tsx}'],
plugins: {
'@typescript-eslint': tsPlugin,
import: importPlugin,
'typescript-sort-keys': tsSortKeysPlugin,
},
languageOptions: {
parser: tsParser,
parserOptions: { project: ['./tsconfig.json'] },
},
settings: {
'import/internal-regex': '^~/',
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
node: true,
typescript: { alwaysTryTypes: true },
},
},
rules: {
...tsPlugin.configs.recommended.rules,
...tsPlugin.configs.stylistic.rules,
...importPlugin.configs.recommended.rules,
...importPlugin.configs.typescript.rules,
...tsSortKeysPlugin.configs.recommended.rules,
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-deprecated': 'warn',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrors: 'none',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{ ignorePrimitives: { boolean: true, string: true } },
],
'@typescript-eslint/strict-boolean-expressions': [
'error',
{ allowNullableBoolean: true, allowNullableString: true },
],
// TODO figure out why ignorePackages doesn’t work ('react-dom/client' is erroring)
// 'import/extensions': ['error', 'always', { ignorePackages: true }],
'no-undef': 'off', // typescript handles undefined variable detection
'prefer-const': ['error', { destructuring: 'all' }],
'sort-keys': 'warn',
},
},
// Markdown
{
files: ['**/*.md'],
plugins: { markdown: markdownPlugin },
processor: 'markdown/markdown',
// The markdown plugin exposes three configuration blocks and is supposed
// to be included as ...markdownPlugin.configs.recommended, but doing so in
// this config makes it so that issues in markdown code blocks are missed.
rules: markdownPlugin.configs.recommended[2].rules,
},
// Jest/Vitest
{
files: ['**/*.test.{js,jsx,ts,tsx}'],
plugins: {
jest: jestPlugin,
'jest-dom': jestDOMPlugin,
'testing-library': testingLibraryPlugin,
},
settings: {
jest: {
// we're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but it means we have to explicitly
// set the jest version.
version: 28,
},
},
rules: {
...jestPlugin.configs.recommended.rules,
...jestDOMPlugin.configs.recommended.rules,
...testingLibraryPlugin.configs.react.rules,
'testing-library/no-manual-cleanup': 'off',
// the following rules require setup-test-env: import '@testing-library/jest-dom/vitest';
'jest-dom/prefer-empty': 'off',
'jest-dom/prefer-in-document': 'off',
'jest-dom/prefer-to-have-value': 'off',
},
},
// Node
{
files: ['worker.ts', 'mocks/**/*.js'],
languageOptions: {
globals: {
...globals.node,
},
},
},
];