-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy patheslint.config.js
More file actions
238 lines (222 loc) · 7.14 KB
/
eslint.config.js
File metadata and controls
238 lines (222 loc) · 7.14 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { defineConfig, globalIgnores } from "eslint/config";
import globals from "globals";
import checkFile from "eslint-plugin-check-file";
import header from "eslint-plugin-header";
import importPlugin from "eslint-plugin-import";
import vitestPlugin from "@vitest/eslint-plugin";
import js from "@eslint/js";
import jsdoc from "eslint-plugin-jsdoc";
import storybook from "eslint-plugin-storybook";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
// Workaround for a compatibility issue between eslint-plugin-header and ESLint v9:
// See https://github.com/Stuk/eslint-plugin-header/issues/59
// TODO: This line can be removed and the default header config can be used
// again after the aforementioned issue has been fixed.
header.rules.header.meta.schema = false;
const estlintConfig = defineConfig([
js.configs.recommended,
...nextVitals,
...nextTs,
...storybook.configs["flat/recommended"],
{
rules: {
// For some reason `eqeqeq` is not in the recommended set, but we try to
// avoid implicit type casting, cause that's where bugs lurk:
eqeqeq: ["error", "always", { null: "ignore" }],
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["**/hooks/*"],
importNames: ["useGlean", "useGa"],
message:
"Please refrain from using this hook standalone. The preferred way to record telemetry is through `useTelemetry`.",
},
],
paths: [
{
name: "react-aria",
importNames: ["VisuallyHidden"],
message:
"Please use the <VisuallyHidden> component from `/src/app/components/server/VisuallyHidden.tsx` instead of the one from react-aria, since the latter's (inline) styles will be stripped by our Content Security Policy.",
},
{
name: "next-auth",
importNames: ["getServerSession"],
message:
"Please use the `getServerSession` wrapper function from `/src/app/functions/server/getServerSession.ts` instead of the one from next-auth, since the latter's doesn't enforce passing the auth configuration object, resulting in broken sessions.",
},
{
name: "next-auth/next",
importNames: ["getServerSession"],
message:
"Please use the `getServerSession` wrapper function from `/src/app/functions/server/getServerSession.ts` instead of the one from next-auth, since the latter's doesn't enforce passing the auth configuration object, resulting in broken sessions.",
},
{
name: "server-only",
message:
"Please import `/src/app/functions/server/notInClientComponent` instead of `server-only`, since the latter will also error in non-Next.js environments like cron jobs.",
},
],
},
],
},
},
// Storybook configurations
...storybook.configs["flat/recommended"],
// JSDoc plugin configuration
{
plugins: {
jsdoc,
},
rules: {
"jsdoc/tag-lines": ["error", "any", { startLines: 1 }],
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-property-description": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"jsdoc/require-returns-description": "off",
},
},
// Header plugin configuration
{
plugins: {
header,
},
rules: {
"header/header": [
"warn",
"block",
[
" This Source Code Form is subject to the terms of the Mozilla Public",
" * License, v. 2.0. If a copy of the MPL was not distributed with this",
" * file, You can obtain one at http://mozilla.org/MPL/2.0/. ",
],
2,
],
},
},
// Check-file plugin configuration
{
plugins: {
"check-file": checkFile,
},
rules: {
"check-file/filename-naming-convention": [
"error",
{ "**/*.{js,css} !src/db/migrations": "CAMEL_CASE" },
{ ignoreMiddleExtensions: true },
],
},
},
// Import plugin configuration
{
plugins: {
import: importPlugin,
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: true,
node: true,
},
},
},
// TypeScript ESLint configuration
{
rules: {
// Unused vars that start with an underscore are allowed to be unused:
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": "allow-with-description",
},
],
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-require-imports": "off",
},
},
// next-env.d.ts is autogenerated by Next.js, so doesn't need our licence header
{
files: ["next-env.d.ts"],
rules: { "header/header": "off" },
},
// Vitest configuration for test files
{
files: [
"**/*.{test,spec}.{ts,tsx}",
"**/*.integration.{ts,tsx}",
"vitest.setup.ts",
],
plugins: { vitest: vitestPlugin },
rules: vitestPlugin.configs.recommended.rules,
},
// Next is not running ESLint on root files by default. The only way to
// include those would be to explicitly add them one by one. Instead, we
// run ESLint directly in addition to next lint on just the root files.
// For more info see:
// https://nextjs.org/docs/app/api-reference/config/eslint#linting-custom-directories-and-files
{
files: ["*.{js,cjs,ts}"],
languageOptions: {
parserOptions: { project: null },
},
},
// Playwright configuration
// Playwright's `use` function is misinterpreted as a React hook.
// For more info see issue: https://github.com/facebook/react/issues/31237
{
files: ["functional-tests/**/*.ts"],
languageOptions: {
globals: {
navigator: "readonly",
},
},
rules: {
"react-hooks/rules-of-hooks": "off",
},
},
// Files that run in a Node environment.
{
files: ["lighthouserc.cjs"],
languageOptions: {
globals: {
...globals.node,
},
},
},
// Override default ignores of eslint-config-next.
globalIgnores([
"node_modules/**",
"storybook-static",
"dist",
"coverage",
"!.storybook",
"playwright-report/**",
// Default ignores of eslint-config-next:
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
]),
]);
export default estlintConfig;