forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheslint.config.mjs
220 lines (200 loc) · 5.35 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import noOnlyTests from 'eslint-plugin-no-only-tests';
import filenamesSimple from 'eslint-plugin-filenames-simple';
import globals from 'globals';
import babelParser from '@babel/eslint-parser';
import importPlugin from 'eslint-plugin-import';
import jsxAllyPlugin from 'eslint-plugin-jsx-a11y';
import prettierConfig from 'eslint-config-prettier';
import reactPlugin from 'eslint-plugin-react';
import testingLibraryPlugin from 'eslint-plugin-testing-library';
import jestDomPlugin from 'eslint-plugin-jest-dom';
import tsParser from '@typescript-eslint/parser';
import tseslint from 'typescript-eslint';
import jsdoc from 'eslint-plugin-jsdoc';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
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 tseslint.config(
{
ignores: [
'client/static/**/*',
'client/.cache/**/*',
'client/public/**/*',
'api-server/**/*',
'shared/**/*.js',
'docs/**/*.md',
'**/playwright*.config.ts',
'playwright/**/*'
]
},
js.configs.recommended,
reactPlugin.configs['flat'].recommended,
jsxAllyPlugin.flatConfigs.recommended,
...fixupConfigRules(
compat.extends(
'plugin:react-hooks/recommended' // Note: at time of testing, upgrading to v5 creates false positives
)
),
importPlugin.flatConfigs.recommended,
// TODO: consider adding eslint-plugin-n ():
// ...nodePlugin.configs["flat/mixed-esm-and-cjs"],
prettierConfig,
{
plugins: {
'no-only-tests': noOnlyTests,
'filenames-simple': fixupPluginRules(filenamesSimple)
},
languageOptions: {
globals: {
...globals.browser,
...globals.mocha,
...globals.node,
...globals.jest,
Promise: true,
window: true,
$: true,
ga: true,
jQuery: true,
router: true
},
parser: babelParser,
parserOptions: {
babelOptions: {
presets: ['@babel/preset-react']
}
}
},
settings: {
react: {
version: '16.4.2'
},
'import/resolver': {
typescript: true,
node: true
}
},
// TODO: audit these rules and remove as many as possible, ideally we want
// to rely on recommended configs.
rules: {
'import/no-unresolved': [
2,
{
commonjs: true
}
],
'import/named': 'error',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/order': 'error',
'import/no-cycle': [
2,
{
maxDepth: 2
}
],
'react/prop-types': 'off',
'no-only-tests/no-only-tests': 'error',
'no-unused-vars': 'off',
'no-unused-expressions': 'error', // This is so the js rules are more in line with the ts rules
'filenames-simple/naming-convention': ['warn']
}
},
{
files: ['**/*.ts?(x)'],
extends: [
tseslint.configs.recommended,
// TODO: turn on type-aware rules
// tseslint.configs.recommendedTypeChecked,
importPlugin.flatConfigs['typescript']
],
languageOptions: {
parser: tsParser,
parserOptions: {
projectService: true
}
},
rules: {
'import/no-unresolved': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
]
}
},
{
files: [
'client/**/*.ts?(x)',
'api/**/*.ts',
'shared/**/*.ts',
'tools/client-plugins/**/*.ts',
'tools/scripts/**/*.ts',
'tools/challenge-helper-scripts/**/*.ts',
'tools/challenge-auditor/**/*.ts',
'e2e/**/*.ts'
],
extends: [tseslint.configs.recommendedTypeChecked]
},
{
files: ['client/**/*.test.[jt]s?(x)'],
extends: [
testingLibraryPlugin.configs['flat/react'],
jestDomPlugin.configs['flat/recommended']
],
rules: {
'import/named': 2
}
},
{
files: ['e2e/*.ts'],
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off'
}
},
{
files: ['.lintstagedrc.js', '**/.babelrc.js', '**/404.tsx'],
rules: {
'filenames-simple/naming-convention': 'off'
}
},
{
extends: [
jsdoc.configs['flat/recommended-typescript-error'],
tseslint.configs.recommendedTypeChecked
],
files: ['**/api/src/**/*.ts'],
rules: {
'jsdoc/require-jsdoc': [
'error',
{
require: {
ArrowFunctionExpression: true,
ClassDeclaration: true,
ClassExpression: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true
},
publicOnly: true
}
],
'jsdoc/require-description-complete-sentence': 'error',
'jsdoc/tag-lines': 'off'
}
}
);