-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy patheslint.config.mjs
More file actions
452 lines (441 loc) · 16 KB
/
Copy patheslint.config.mjs
File metadata and controls
452 lines (441 loc) · 16 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// SPDX-License-Identifier: Apache-2.0
import {basename} from 'node:path';
import globals from 'globals';
import eslintJs from '@eslint/js';
import nodePlugin from 'eslint-plugin-n';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginPrettier from 'eslint-plugin-prettier';
import tsEslint from 'typescript-eslint';
import headers from 'eslint-plugin-headers';
import tsdoc from 'eslint-plugin-tsdoc';
import unusedImports from 'eslint-plugin-unused-imports';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
// Local rules enforcing Solo conventions that no off-the-shelf plugin covers.
// See docs/contributing/typescript-code-style.md §3.4.5 and §10.3.1.
const soloLocalPlugin = {
rules: {
// Behavior (resolvers, orchestrators, computations) must be grouped on a class as static
// methods rather than exported as free functions. Pure data (constants, types, simple
// factories) may still be exported — this rule only targets functions.
'no-exported-function': {
meta: {
type: 'problem',
docs: {
description: 'Disallow exported functions — group behavior on a class with static methods (§10.3.1).',
},
schema: [],
messages: {
noExportedFunction:
'No exported functions — group behavior on a class with static methods. ' +
'See docs/contributing/typescript-code-style.md §10.3.1. ' +
'Pure data (constants, types) may be exported; helpers used by one class become private static members.',
},
},
create(context) {
return {
'ExportNamedDeclaration > FunctionDeclaration'(node) {
context.report({node, messageId: 'noExportedFunction'});
},
'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator'(node) {
const initializerType = node.init?.type;
if (initializerType === 'ArrowFunctionExpression' || initializerType === 'FunctionExpression') {
context.report({node, messageId: 'noExportedFunction'});
}
},
};
},
},
// Every direct node:child_process invocation must state its `shell` option explicitly, so the
// call site documents that no shell interprets its arguments; exec/execSync always run a shell
// and are banned outright. PR #4804 swept the implicit-shell call sites once already and they
// drifted back (#5869) — this rule keeps them out.
'require-explicit-shell': {
meta: {
type: 'problem',
docs: {
description: 'Require an explicit `shell` option on child_process calls and ban exec/execSync.',
},
schema: [],
messages: {
missingShell:
'Pass an explicit `shell` option (normally `shell: false`) to child_process.{{name}} ' +
'so the call site documents that no shell interprets its arguments.',
shellOnly: 'child_process.{{name}} always runs a shell — use execFile/spawn with an argument array instead.',
},
},
create(context) {
const spawnLikeNames = new Set(['spawn', 'spawnSync', 'execFile', 'execFileSync']);
const shellOnlyNames = new Set(['exec', 'execSync']);
const namedImportLocals = new Map(); // local identifier name -> imported child_process member name
const moduleObjectLocals = new Set(); // locals bound to the whole module (namespace/default import)
function hasExplicitShellOption(callArguments) {
return callArguments.some(
argument =>
argument.type === 'ObjectExpression' &&
argument.properties.some(
property =>
property.type === 'Property' &&
!property.computed &&
(property.key.name === 'shell' || property.key.value === 'shell'),
),
);
}
function childProcessMemberName(callee) {
if (callee.type === 'Identifier') {
return namedImportLocals.get(callee.name);
}
if (
callee.type === 'MemberExpression' &&
!callee.computed &&
callee.object.type === 'Identifier' &&
moduleObjectLocals.has(callee.object.name)
) {
return callee.property.name;
}
return undefined;
}
return {
ImportDeclaration(node) {
if (node.source.value !== 'node:child_process' && node.source.value !== 'child_process') {
return;
}
for (const specifier of node.specifiers) {
if (specifier.type === 'ImportSpecifier') {
namedImportLocals.set(specifier.local.name, specifier.imported.name);
} else {
moduleObjectLocals.add(specifier.local.name);
}
}
},
CallExpression(node) {
const name = childProcessMemberName(node.callee);
if (name === undefined) {
return;
}
if (shellOnlyNames.has(name)) {
context.report({node, messageId: 'shellOnly', data: {name}});
return;
}
if (spawnLikeNames.has(name) && !hasExplicitShellOption(node.arguments)) {
context.report({node, messageId: 'missingShell', data: {name}});
}
},
};
},
},
// Each exported interface must be in its own file named in kebab-case matching the
// interface name — §3.5. No off-the-shelf rule covers name-matching; unicorn/filename-case
// enforces kebab-case style but not that the filename matches the interface name.
'exported-interface-in-own-file': {
meta: {
type: 'problem',
docs: {
description:
'Each exported interface must be in its own file named in kebab-case matching the interface name (§3.5).',
},
schema: [],
messages: {
filenameMismatch:
'Exported interface "{{interfaceName}}" must be in its own file named ' +
'"{{expectedFilename}}.ts" — move it or rename the file (§3.5).',
},
},
create(context) {
function toKebabCase(name) {
return name
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
.replace(/([a-z\d])([A-Z])/g, '$1-$2')
.toLowerCase();
}
return {
'ExportNamedDeclaration > TSInterfaceDeclaration'(node) {
const filename = context.filename;
if (!filename || filename.endsWith('.d.ts')) return;
const interfaceName = node.id.name;
const expectedFilename = toKebabCase(interfaceName);
const actualFilename = basename(filename, '.ts');
if (actualFilename !== expectedFilename) {
context.report({
node: node.id,
messageId: 'filenameMismatch',
data: {interfaceName, expectedFilename},
});
}
},
};
},
},
},
};
export default [
eslintJs.configs.recommended,
nodePlugin.configs['flat/recommended'],
eslintConfigPrettier,
...tsEslint.configs.recommended.map(config => ({
...config,
files: ['**/*.ts', '**/*.tsx'],
})),
eslintPluginUnicorn.configs.recommended,
{
ignores: [
'.git/**/*', // Git files
'.github/**/*', // GitHub files
'!.github/**/*.ts', // ...except TypeScript files
'.idea/**/*', // IDE files
'.claude/**/*', // Claude AI files
'coverage/**/*', // Coverage files
'docs/**/*', // Documentation files
'examples/**/*', // Example files
'dist/**/*', // Distribution files
'scripts/metrics-plotter/**/*', // External tool files
'node_modules/**/*', // Node modules
'coverage/**/*', // Coverage files
'**/*.*js', // JavaScript files
],
},
{
// Rules for all files not excluded
languageOptions: {
globals: {
...globals.mocha,
...globals.node,
},
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: {
n: nodePlugin,
prettier: eslintPluginPrettier,
headers: headers,
tsdoc: tsdoc,
'unused-imports': unusedImports,
'@typescript-eslint': tsEslint.plugin,
},
rules: {
'headers/header-format': [
'error',
{
source: 'string',
content: 'SPDX-License-Identifier: Apache-2.0',
style: 'line',
trailingNewlines: 2,
},
],
'prettier/prettier': 'error',
'block-scoped-var': 'error',
eqeqeq: 'error',
'no-var': 'error',
'prefer-const': 'error',
'eol-last': 'error',
'prefer-arrow-callback': 'error',
'no-trailing-spaces': 'error',
quotes: ['warn', 'single', {avoidEscape: true}],
'no-restricted-properties': [
'error',
{
object: 'describe',
property: 'only',
},
{
object: 'it',
property: 'only',
},
],
'n/no-missing-import': 'off',
'n/no-empty-function': 'off',
'n/no-unsupported-features/es-syntax': 'off',
'n/no-missing-require': 'off',
'n/hashbang': [
'error',
{
additionalExecutables: ['solo.ts', '.github/workflows/script/jdwp-tester.ts'],
},
],
'n/no-unpublished-import': [
'error',
{
allowModules: [
'globals',
'@eslint/js',
'eslint-plugin-n',
'eslint-config-prettier',
'eslint-plugin-prettier',
'typescript-eslint',
'eslint-plugin-headers',
'eslint-plugin-tsdoc',
'eslint-plugin-unused-imports',
],
convertPath: [
{
include: ['src/**'],
replace: ['^src/(.+)$', 'dist/$1'],
},
],
},
],
'no-dupe-class-members': 'off',
'require-atomic-updates': 'off',
'n/no-unsupported-features/node-builtins': [
'error',
{
ignores: ['fs.cpSync', 'CryptoKey', 'fetch'],
},
],
'no-prototype-builtins': 'off',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-warning-comments': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: false,
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: false,
},
],
'@typescript-eslint/typedef': [
'warn',
{
variableDeclaration: true,
parameter: true,
propertyDeclaration: true,
memberVariableDeclaration: true,
},
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/consistent-type-imports': [
// optional: assists in reducing circular dependencies
'error',
{
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/no-explicit-any': 'warn', // TODO remove (406 errors)
'@typescript-eslint/no-this-alias': [
'error',
{
allowedNames: ['self'], // TODO remove (59 errors)
},
],
'@typescript-eslint/no-unused-vars': 'warn', // TODO remove (6 errors)
'n/no-process-exit': 'warn', // TODO remove (1 errors)
// Enforce `import {type X} from 'path';` over `import type {X} from 'path';`,
// but allow `import type * as <name> from 'path';`
'no-restricted-syntax': [
'error',
{
selector: "ImportDeclaration[importKind='type'] ImportSpecifier",
message: "Use `import {type X} from 'path';` instead of `import type {X} from 'path';`.",
},
],
'@typescript-eslint/explicit-member-accessibility': 'warn', // TODO remove (47 error)
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'no-invalid-this': ['off', {}],
'@typescript-eslint/no-unused-expressions': 'off',
curly: ['error', 'all'],
'@typescript-eslint/no-extraneous-class': [
'error',
{
allowWithDecorator: true,
allowStaticOnly: true,
allowConstructorOnly: true,
},
],
'unicorn/filename-case': [
'error',
{
case: 'kebabCase',
// Optional: Ensure this rule only applies to TypeScript files
ignore: ['.*\\.d\\.ts$'], // Ignore TypeScript declaration files if needed
},
],
'unicorn/no-null': 'warn', // TODO error (104 errors)
'unicorn/consistent-function-scoping': 'warn', // TODO error (2 errors)
'unicorn/error-message': 'warn', // TODO error (1 error)
'unicorn/import-style': 'warn', // TODO error (8 errors)
'unicorn/better-dom-traversing': 'off', // TODO seems to be misidentifying some of our custom classes as Arrays
},
},
{
// include certain rules for source ts files (everything except test files)
ignores: ['test/**/*.ts'],
rules: {
'no-invalid-this': ['error', {}],
'@typescript-eslint/no-unused-expressions': 'error',
},
},
{
// No exported functions in source code — see §10.3.1.
// One exported interface per file, filename matches interface name in kebab-case — see §3.5.
// Explicit `shell` option on every child_process call — see #5869.
files: ['src/**/*.ts'],
plugins: {solo: soloLocalPlugin},
rules: {
'solo/no-exported-function': 'error',
'solo/exported-interface-in-own-file': 'error',
'solo/require-explicit-shell': 'error',
},
},
{
// Enforce getEnvironmentVariable() over process.env[...] bracket notation in src/.
// Bracket-notation reads bypass the utility and the env.md documentation requirement.
// See CLAUDE.md "Environment Variable Access".
// constants.ts is excluded because it defines getEnvironmentVariable() and legitimately
// accesses process.env[name] internally.
files: ['src/**/*.ts'],
ignores: ['src/core/constants.ts'],
rules: {
'no-restricted-syntax': [
'error',
// Re-state the global import-type check here because this block overrides
// no-restricted-syntax for src/ files; @typescript-eslint/consistent-type-imports
// already enforces the same thing at error level, so this is belt-and-suspenders.
{
selector: "ImportDeclaration[importKind='type'] ImportSpecifier",
message: "Use `import {type X} from 'path';` instead of `import type {X} from 'path';`.",
},
{
selector:
'MemberExpression[computed=true][object.type="MemberExpression"][object.object.name="process"][object.property.name="env"]',
message:
'Use getEnvironmentVariable() from src/core/constants.ts instead of process.env[...]. ' +
'Bracket-notation access bypasses the project utility and the env.md documentation requirement (see CLAUDE.md).',
},
],
},
},
{
// @kubernetes/client-node types must not leak outside src/integration/kube.
// Use Solo domain types (Pod, ContainerStatus, etc.) in all other layers.
files: ['**/*.ts'],
ignores: ['src/integration/kube/**'],
rules: {
'no-restricted-imports': [
'error',
{
name: '@kubernetes/client-node',
message:
'@kubernetes/client-node types must stay within src/integration/kube — use the Solo domain types (Pod, ContainerStatus, etc.) instead.',
},
],
},
},
];