-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy patheslint.config.mjs
More file actions
204 lines (189 loc) · 5.94 KB
/
eslint.config.mjs
File metadata and controls
204 lines (189 loc) · 5.94 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
/**
* Copyright 2026 GitProxy Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-check
import { fileURLToPath } from 'node:url';
import { includeIgnoreFile } from '@eslint/compat';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import js from '@eslint/js';
import ts from 'typescript-eslint';
import react from 'eslint-plugin-react';
import json from '@eslint/json';
import cypress from 'eslint-plugin-cypress';
import prettierConfig from 'eslint-config-prettier/flat';
import licenseHeader from 'eslint-plugin-license-header';
// paths shouldn't start with ./
const gitignorePath = fileURLToPath(
new URL(
'.gitignore',
// @ts-expect-error ts doesn't respect this file as a module, can ignore
import.meta.url,
),
);
const licenseHeaderPath = fileURLToPath(
new URL(
'licenseHeader.js',
import.meta.url,
),
);
export default defineConfig(
includeIgnoreFile(gitignorePath, 'Imported .gitignore patterns'),
{
name: 'ignores',
ignores: [
// generated files we don't control
'**/package-lock.json',
'src/config/generated/**',
// has it's own eslint
'experimental/license-inventory',
// vendored code we're not changing
'src/ui/assets/js/**',
'src/ui/assets/css/**',
],
},
{
name: 'JSON',
files: ['**/*.json'],
plugins: { json },
extends: [json.configs.recommended],
language: 'json/json',
},
{
name: 'JSON - proxy.config.json override',
files: ['**/proxy.config.json'],
// allow empty keys in proxy.config.json for now
rules: { 'json/no-empty-keys': 'off' },
},
// attempt at accurately linting each "type" of code we have
// much of this can be consolidated going forward, or split out in
// the case of the frontend
{
name: 'JS',
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
plugins: { js },
extends: [js.configs.recommended],
languageOptions: {
globals: {
...globals.node,
// allow commonjs during the migration
...globals.commonjs,
},
},
rules: { 'no-unused-vars': 'warn', 'no-undef': 'warn', 'guard-for-in': 'error' },
},
{
name: 'TS',
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: { '@typescript-eslint': ts.plugin },
extends: [ts.configs.recommended],
languageOptions: { globals: { ...globals.node } },
rules: {
'no-async-promise-executor': 'warn', // to resolve and return to default
'@typescript-eslint/no-explicit-any': 'off', // temporary until TS refactor is complete
// '@typescript-eslint/no-unused-vars': 'off', // temporary until TS refactor is complete
// "no-unused-vars": 'off',
'@typescript-eslint/no-unused-vars': [
// TODO: increase this to error
'off',
{
// allow ignoring/skipping a var with a _ prefix
// also allow for `...otherStuff` syntax, particularly common in react
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-require-imports': 'off', // prevents error on old "require" imports
},
},
{
name: 'JS minus type checking',
// disable type-aware linting on JS files
files: ['**/*.js'],
extends: [ts.configs.disableTypeChecked],
},
// web/react content
{
name: 'web/react',
files: [
'src/ui/**/*.{js,jsx,mjs,cjs,ts,tsx}',
// TODO: split website into separate linting
'website/src/**/*.{js,jsx,mjs,cjs,ts,tsx}',
],
plugins: { react },
extends: [react.configs.flat.recommended],
languageOptions: { globals: { ...globals.browser, ...globals.commonjs } },
settings: { react: { version: 'detect' } },
rules: {
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
'react/prop-types': 'off',
},
},
// tests
{
name: 'tests',
files: ['**/*.test.{js,mjs,cjs}'],
languageOptions: {
// allow global functions e.g. describe, it, expect, etc.
// from mocha and chai in tests
globals: { ...globals.mocha, ...globals.chai },
},
rules: {
'@typescript-eslint/no-unused-vars': [
// TODO: increase to 'error'
'warn',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
// same as rule above but exclude unused error vars in try catch for
// now due to many warnings in tests
caughtErrors: 'none',
},
],
// allow for chai `expect().to.xyz`
'@typescript-eslint/no-unused-expressions': 'off',
'new-cap': ['error', { capIsNewExceptionPattern: '^express\\..*' }],
},
},
// cypress e2e tests
{
name: 'cypress',
files: ['cypress/**/*.{js,mjs,cjs,ts}'],
extends: [cypress.configs.recommended],
rules: {
// TODO: fix and remove 'warn' override
'cypress/unsafe-to-chain-command': 'warn',
},
},
{
name: 'license-header',
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
plugins: { 'license-header': licenseHeader },
rules: {
'license-header/header': ['error', licenseHeaderPath],
},
ignores: ['**/licenseHeader.js'],
},
// disables rules which prettier controls
// https://prettier.io/docs/integrating-with-linters
prettierConfig,
);