Skip to content

Commit 8de0f3d

Browse files
committed
chore: update to eslint v9
1 parent 4a0fe55 commit 8de0f3d

4 files changed

Lines changed: 674 additions & 603 deletions

File tree

.eslintrc.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// @ts-check
2+
import { fileURLToPath } from 'node:url';
3+
import { includeIgnoreFile } from '@eslint/compat';
4+
import { defineConfig } from 'eslint/config';
5+
import globals from 'globals';
6+
import js from '@eslint/js';
7+
import ts from 'typescript-eslint';
8+
import react from 'eslint-plugin-react';
9+
import json from '@eslint/json';
10+
// @ts-expect-error
11+
import cypress from 'eslint-plugin-cypress';
12+
import prettierConfig from 'eslint-config-prettier/flat';
13+
14+
// paths shouldn't start with ./
15+
16+
const gitignorePath = fileURLToPath(
17+
new URL(
18+
'.gitignore',
19+
// @ts-expect-error ts doesn't respect this file as a module, can ignore
20+
import.meta.url,
21+
),
22+
);
23+
24+
export default defineConfig(
25+
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'),
26+
{
27+
name: 'ignores',
28+
ignores: [
29+
// lock files we don't control
30+
'**/package-lock.json',
31+
// has it's own eslint
32+
'experimental/license-inventory',
33+
// vendored code we're not changing
34+
'src/ui/assets/js/**',
35+
'src/ui/assets/css/**',
36+
],
37+
},
38+
39+
{
40+
name: 'JSON',
41+
files: ['**/*.json'],
42+
plugins: { json },
43+
extends: [json.configs.recommended],
44+
language: 'json/json',
45+
},
46+
47+
{
48+
name: 'JSON - proxy.config.json override',
49+
files: ['**/proxy.config.json'],
50+
// allow empty keys in proxy.config.json for now
51+
rules: { 'json/no-empty-keys': 'off' },
52+
},
53+
54+
// attempt at accurately linting each "type" of code we have
55+
// much of this can be consolidated going forward, or split out in
56+
// the case of the frontend
57+
{
58+
name: 'JS',
59+
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
60+
plugins: { js },
61+
extends: [js.configs.recommended],
62+
languageOptions: {
63+
globals: {
64+
...globals.node,
65+
// allow commonjs during the migration
66+
...globals.commonjs,
67+
},
68+
},
69+
rules: { 'no-unused-vars': 'warn', 'no-undef': 'warn', 'guard-for-in': 'error' },
70+
},
71+
72+
{
73+
name: 'TS',
74+
files: ['**/*.{js,jsx,ts,tsx}'],
75+
plugins: { '@typescript-eslint': ts.plugin },
76+
extends: [ts.configs.recommended],
77+
languageOptions: { globals: { ...globals.node } },
78+
rules: {
79+
'no-async-promise-executor': 'warn', // to resolve and return to default
80+
'@typescript-eslint/no-explicit-any': 'off', // temporary until TS refactor is complete
81+
// '@typescript-eslint/no-unused-vars': 'off', // temporary until TS refactor is complete
82+
// "no-unused-vars": 'off',
83+
'@typescript-eslint/no-unused-vars': [
84+
// TODO: increase this to error
85+
'off',
86+
{
87+
// allow ignoring/skipping a var with a _ prefix
88+
// also allow for `...otherStuff` syntax, particularly common in react
89+
argsIgnorePattern: '^_',
90+
caughtErrorsIgnorePattern: '^_',
91+
destructuredArrayIgnorePattern: '^_',
92+
varsIgnorePattern: '^_',
93+
ignoreRestSiblings: true,
94+
},
95+
],
96+
'@typescript-eslint/no-require-imports': 'off', // prevents error on old "require" imports
97+
},
98+
},
99+
100+
{
101+
name: 'JS minus type checking',
102+
// disable type-aware linting on JS files
103+
files: ['**/*.js'],
104+
extends: [ts.configs.disableTypeChecked],
105+
},
106+
107+
// web/react content
108+
{
109+
name: 'web/react',
110+
files: [
111+
'src/ui/**/*.{js,jsx,mjs,cjs,ts,tsx}',
112+
// TODO: split website into separate linting
113+
'website/src/**/*.{js,jsx,mjs,cjs,ts,tsx}',
114+
],
115+
plugins: { react },
116+
extends: [react.configs.flat.recommended],
117+
languageOptions: { globals: { ...globals.browser, ...globals.commonjs } },
118+
settings: { react: { version: 'detect' } },
119+
rules: {
120+
'react/jsx-uses-react': 'error',
121+
'react/jsx-uses-vars': 'error',
122+
'react/prop-types': 'off',
123+
},
124+
},
125+
126+
// tests
127+
{
128+
name: 'tests',
129+
files: ['**/*.test.{js,mjs,cjs}'],
130+
languageOptions: {
131+
// allow global functions e.g. describe, it, expect, etc.
132+
// from mocha and chai in tests
133+
globals: { ...globals.mocha, ...globals.chai },
134+
},
135+
rules: {
136+
'@typescript-eslint/no-unused-vars': [
137+
// TODO: increase to 'error'
138+
'warn',
139+
{
140+
argsIgnorePattern: '^_',
141+
caughtErrorsIgnorePattern: '^_',
142+
destructuredArrayIgnorePattern: '^_',
143+
varsIgnorePattern: '^_',
144+
ignoreRestSiblings: true,
145+
// same as rule above but exclude unused error vars in try catch for
146+
// now due to many warnings in tests
147+
caughtErrors: 'none',
148+
},
149+
],
150+
// allow for chai `expect().to.xyz`
151+
'@typescript-eslint/no-unused-expressions': 'off',
152+
},
153+
},
154+
155+
// cypress e2e tests
156+
{
157+
name: 'cypress',
158+
files: ['cypress/**/*.{js,mjs,cjs,ts}'],
159+
extends: [cypress.configs.recommended],
160+
rules: {
161+
// TODO: fix and remove 'warn' override
162+
'cypress/unsafe-to-chain-command': 'warn',
163+
},
164+
},
165+
166+
// disables rules which prettier controls
167+
// https://prettier.io/docs/integrating-with-linters
168+
prettierConfig,
169+
);

0 commit comments

Comments
 (0)