-
Notifications
You must be signed in to change notification settings - Fork 21
/
.eslintrc.js
232 lines (223 loc) · 6.18 KB
/
.eslintrc.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
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
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-nodejs-modules */
const glob = require('glob');
const { readFileSync } = require('fs');
const { dirname, join } = require('path');
const noRestrictedSyntaxRules = {
'no-restricted-syntax': [
'error',
{
selector:
"TSNonNullExpression>CallExpression[callee.property.name='getAttribute']",
message:
"Please check for null or use `|| ''` instead of `!` when calling `getAttribute`",
},
{
selector:
'MemberExpression[object.name=/^e/][property.name=/^(key(?:Code)?|which|(meta|ctrl|alt)Key)$/]',
message: 'Please use `data-hotkey` instead of manual shortcut logic',
},
{
selector: "NewExpression[callee.name='URL'][arguments.length=1]",
message:
'Please pass in `window.location.origin` as the 2nd argument to `new URL()`',
},
{
selector: "CallExpression[callee.name='unsafeHTML']",
message:
'Use unsafeHTML sparingly. Please add an eslint-disable comment if you want to use this',
},
],
};
const baseConfig = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'compat',
'delegated-events',
'filenames',
'i18n-text',
'escompat',
'import',
'github',
],
extends: [
'plugin:github/internal',
'plugin:github/recommended',
'plugin:github/browser',
'plugin:escompat/typescript',
'plugin:import/typescript',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:primer-react/recommended',
'next',
],
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
ignorePatterns: ['*__generated__*'],
rules: {
'prettier/prettier': 1, // We use prettier for formatting instead of ESLint
'import/no-unresolved': 0, // Handled by TypeScript instead
'import/extensions': [
'error',
{
svg: 'always',
},
],
'compat/compat': ['error'],
'delegated-events/global-on': ['error'],
'delegated-events/no-high-freq': ['error'],
'escompat/no-dynamic-imports': 'off',
'escompat/no-nullish-coalescing': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': ['error'],
'no-unused-vars': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'valid-typeof': ['error', { requireStringLiterals: true }],
'github/no-inner-html': 'off',
'no-restricted-imports': ['error'],
'primer-react/no-deprecated-colors': ['error', { skipImportCheck: true }],
'primer-react/no-system-props': [
'error',
{ includeUtilityComponents: true },
],
'react/no-danger': ['error'],
'react/self-closing-comp': [
'error',
{
component: true,
html: true,
},
],
'react/jsx-no-constructed-context-values': ['error'],
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks: 'useHydratedEffect',
},
],
},
settings: {
polyfills: [
'Request',
'window.customElements',
'window.requestIdleCallback',
],
'import/resolver': {
node: {
extensions: ['.js', '.ts', '.tsx', '.json', '.md'],
moduleDirectory: ['app/src', 'app/node_modules'],
},
typescript: {},
},
react: {
version: 'detect',
},
},
overrides: [
{
files: ['*.ts?(x)'],
rules: {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
// recommended by typescript-eslint as the typechecker handles these out of the box
// https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#eslint-plugin-import
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
// muting an expensive rule that scans jsdoc comments looking for @deprecated notes
'import/no-deprecated': 'off',
'filenames/match-regex': 'off',
},
},
{
files: ['*.json'],
rules: {
'filenames/match-regex': 'off',
},
parserOptions: {
project: null,
},
},
{
files: ['*.d.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'no-var': 'off',
},
},
{
files: ['eslintrc.js', '.eslintrc.js'],
parserOptions: {
project: null,
},
env: {
node: true,
browser: false,
},
rules: {
'filenames/match-regex': ['off'],
'import/no-commonjs': ['off'],
},
},
],
};
const findDevPackages = () => {
const uiPackagesGlob = join(__dirname, 'packages/*/package.json');
const packages = glob.sync(uiPackagesGlob, {
ignore: 'node_modules/**',
absolute: true,
});
return packages.reduce((acc, package) => {
const pkg = JSON.parse(readFileSync(package));
if (pkg.dev) acc.push(`${dirname(package)}/**/*.{mjs,js,ts,tsx}`);
return acc;
}, []);
};
module.exports = {
...baseConfig,
root: true,
rules: {
...baseConfig.rules,
'eslint-comments/no-use': [
'error',
{ allow: ['eslint-disable', 'eslint-disable-next-line'] },
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/__tests__/**/*.{ts,tsx}',
'**/__browser-tests__/**/*.ts',
'**/test-utils/**/*.{ts,tsx}',
'**/*.stories.*',
'**/jest.config.js',
...findDevPackages(),
],
},
],
},
overrides: [
...baseConfig.overrides,
{
files: ['*.tsx'],
excludedFiles: ['**/__tests__/**'],
rules: {
'i18n-text/no-en': 'off',
// 'filenames/match-regex': [2, '^[A-Z][a-zA-Z]+(.[a-z0-9-]+)?$'],
'import/extensions': 'off',
},
},
{
files: ['*.ts'],
rules: noRestrictedSyntaxRules,
},
],
};