@eslint-react/shared 1.5.12 → 1.5.13-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +52 -222
- package/dist/index.d.ts +52 -222
- package/dist/index.js +117 -191
- package/dist/index.mjs +117 -191
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -187,9 +187,6 @@ var getDocsUrl = (pluginName) => (ruleName) => {
|
|
|
187
187
|
return `${WEBSITE_URL}/rules/${pluginName}-${ruleName}`;
|
|
188
188
|
};
|
|
189
189
|
var createRuleForPlugin = (pluginName) => ESLintUtils.RuleCreator(getDocsUrl(pluginName));
|
|
190
|
-
function defaultArgs(arg1, arg2) {
|
|
191
|
-
return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2];
|
|
192
|
-
}
|
|
193
190
|
var store2;
|
|
194
191
|
function getGlobalMessage(lang) {
|
|
195
192
|
return store2?.get(lang);
|
|
@@ -202,116 +199,77 @@ var store4;
|
|
|
202
199
|
function getSpecificMessage(reference, lang) {
|
|
203
200
|
return store4?.get(reference)?.get(lang);
|
|
204
201
|
}
|
|
205
|
-
function
|
|
206
|
-
const message = context.message ?? getSpecificMessage(reference, issue.lang) ?? (schema ? getSchemaMessage(issue.lang) : null) ?? config?.message ?? getGlobalMessage(issue.lang) ?? issue.message;
|
|
207
|
-
return typeof message === "function" ? message(issue) : message;
|
|
208
|
-
}
|
|
209
|
-
function schemaResult(typed, output, issues) {
|
|
210
|
-
return { typed, output, issues };
|
|
211
|
-
}
|
|
212
|
-
function stringify(input) {
|
|
202
|
+
function _stringify(input) {
|
|
213
203
|
let type = typeof input;
|
|
214
204
|
if (type === "object") {
|
|
215
205
|
type = input ? Object.getPrototypeOf(input).constructor.name : "null";
|
|
216
206
|
}
|
|
217
207
|
return type === "string" ? `"${input}"` : type === "number" || type === "bigint" || type === "boolean" ? `${input}` : type;
|
|
218
208
|
}
|
|
219
|
-
function
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
context: issue.context.type,
|
|
224
|
-
expected: issue.context.expects,
|
|
225
|
-
received,
|
|
226
|
-
message: `Invalid ${issue.label}: ${issue.context.expects ? `Expected ${issue.context.expects} but r` : "R"}eceived ${received}`,
|
|
227
|
-
input: issue.input,
|
|
228
|
-
requirement: issue.context.requirement,
|
|
229
|
-
path: issue.path,
|
|
230
|
-
lang: config?.lang,
|
|
231
|
-
abortEarly: config?.abortEarly,
|
|
232
|
-
abortPipeEarly: config?.abortPipeEarly,
|
|
233
|
-
skipPipe: config?.skipPipe
|
|
234
|
-
};
|
|
235
|
-
schemaIssue2.message = i18n(
|
|
236
|
-
false,
|
|
237
|
-
issue.context,
|
|
238
|
-
issue.reference,
|
|
239
|
-
config,
|
|
240
|
-
schemaIssue2
|
|
241
|
-
);
|
|
242
|
-
return schemaIssue2;
|
|
243
|
-
}
|
|
244
|
-
function pipeResult(context, input, config, issues) {
|
|
245
|
-
if (context.pipe && !config?.skipPipe) {
|
|
246
|
-
for (const action of context.pipe) {
|
|
247
|
-
const result = action._parse(input);
|
|
248
|
-
if (result.issues) {
|
|
249
|
-
for (const actionIssue2 of result.issues) {
|
|
250
|
-
const schemaIssue2 = pipeIssue(context, config, actionIssue2);
|
|
251
|
-
issues ? issues.push(schemaIssue2) : issues = [schemaIssue2];
|
|
252
|
-
}
|
|
253
|
-
if (config?.abortEarly || config?.abortPipeEarly) {
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
input = result.output;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return schemaResult(true, input, issues);
|
|
262
|
-
}
|
|
263
|
-
function restAndDefaultArgs(arg1, arg2, arg3) {
|
|
264
|
-
if (!arg1 || typeof arg1 === "object" && !Array.isArray(arg1)) {
|
|
265
|
-
const [error2, pipe2] = defaultArgs(arg2, arg3);
|
|
266
|
-
return [arg1, error2, pipe2];
|
|
267
|
-
}
|
|
268
|
-
const [error, pipe] = defaultArgs(
|
|
269
|
-
arg1,
|
|
270
|
-
arg2
|
|
271
|
-
);
|
|
272
|
-
return [void 0, error, pipe];
|
|
273
|
-
}
|
|
274
|
-
function schemaIssue(context, reference, input, config, other) {
|
|
275
|
-
const received = stringify(input);
|
|
276
|
-
const expected = other?.expected ?? context.expects;
|
|
209
|
+
function _addIssue(context, label, dataset, config, other) {
|
|
210
|
+
const input = dataset.value;
|
|
211
|
+
const expected = context.expects;
|
|
212
|
+
const received = _stringify(input);
|
|
277
213
|
const issue = {
|
|
278
|
-
|
|
279
|
-
|
|
214
|
+
kind: context.kind,
|
|
215
|
+
type: context.type,
|
|
216
|
+
input,
|
|
280
217
|
expected,
|
|
281
218
|
received,
|
|
282
|
-
message: `Invalid
|
|
283
|
-
|
|
219
|
+
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
220
|
+
// @ts-expect-error
|
|
221
|
+
requirement: context.requirement,
|
|
284
222
|
path: other?.path,
|
|
285
223
|
issues: other?.issues,
|
|
286
|
-
lang: config
|
|
287
|
-
abortEarly: config
|
|
288
|
-
abortPipeEarly: config
|
|
289
|
-
skipPipe: config
|
|
224
|
+
lang: config.lang,
|
|
225
|
+
abortEarly: config.abortEarly,
|
|
226
|
+
abortPipeEarly: config.abortPipeEarly,
|
|
227
|
+
skipPipe: config.skipPipe
|
|
290
228
|
};
|
|
291
|
-
|
|
292
|
-
|
|
229
|
+
const isSchema = context.kind === "schema";
|
|
230
|
+
const message = (
|
|
231
|
+
// @ts-expect-error
|
|
232
|
+
context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config.message ?? getGlobalMessage(issue.lang)
|
|
233
|
+
);
|
|
234
|
+
if (message) {
|
|
235
|
+
issue.message = typeof message === "function" ? message(issue) : message;
|
|
236
|
+
}
|
|
237
|
+
if (isSchema) {
|
|
238
|
+
dataset.typed = false;
|
|
239
|
+
}
|
|
240
|
+
if (dataset.issues) {
|
|
241
|
+
dataset.issues.push(issue);
|
|
242
|
+
} else {
|
|
243
|
+
dataset.issues = [issue];
|
|
244
|
+
}
|
|
293
245
|
}
|
|
294
|
-
function getDefault(schema) {
|
|
295
|
-
return typeof schema.default === "function" ?
|
|
246
|
+
function getDefault(schema, dataset, config) {
|
|
247
|
+
return typeof schema.default === "function" ? (
|
|
248
|
+
// @ts-expect-error
|
|
249
|
+
schema.default(dataset, config)
|
|
250
|
+
) : (
|
|
251
|
+
// @ts-expect-error
|
|
252
|
+
schema.default
|
|
253
|
+
);
|
|
296
254
|
}
|
|
297
|
-
function array(item,
|
|
298
|
-
const [message, pipe] = defaultArgs(arg2, arg3);
|
|
255
|
+
function array(item, message) {
|
|
299
256
|
return {
|
|
257
|
+
kind: "schema",
|
|
300
258
|
type: "array",
|
|
259
|
+
reference: array,
|
|
301
260
|
expects: "Array",
|
|
302
261
|
async: false,
|
|
303
262
|
item,
|
|
304
263
|
message,
|
|
305
|
-
|
|
306
|
-
|
|
264
|
+
_run(dataset, config) {
|
|
265
|
+
const input = dataset.value;
|
|
307
266
|
if (Array.isArray(input)) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const output = [];
|
|
267
|
+
dataset.typed = true;
|
|
268
|
+
dataset.value = [];
|
|
311
269
|
for (let key = 0; key < input.length; key++) {
|
|
312
270
|
const value2 = input[key];
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
271
|
+
const itemDataset = this.item._run({ typed: false, value: value2 }, config);
|
|
272
|
+
if (itemDataset.issues) {
|
|
315
273
|
const pathItem = {
|
|
316
274
|
type: "array",
|
|
317
275
|
origin: "value",
|
|
@@ -319,57 +277,55 @@ function array(item, arg2, arg3) {
|
|
|
319
277
|
key,
|
|
320
278
|
value: value2
|
|
321
279
|
};
|
|
322
|
-
for (const issue of
|
|
280
|
+
for (const issue of itemDataset.issues) {
|
|
323
281
|
if (issue.path) {
|
|
324
282
|
issue.path.unshift(pathItem);
|
|
325
283
|
} else {
|
|
326
284
|
issue.path = [pathItem];
|
|
327
285
|
}
|
|
328
|
-
issues?.push(issue);
|
|
286
|
+
dataset.issues?.push(issue);
|
|
329
287
|
}
|
|
330
|
-
if (!issues) {
|
|
331
|
-
issues =
|
|
288
|
+
if (!dataset.issues) {
|
|
289
|
+
dataset.issues = itemDataset.issues;
|
|
332
290
|
}
|
|
333
|
-
if (config
|
|
334
|
-
typed = false;
|
|
291
|
+
if (config.abortEarly) {
|
|
292
|
+
dataset.typed = false;
|
|
335
293
|
break;
|
|
336
294
|
}
|
|
337
295
|
}
|
|
338
|
-
if (!
|
|
339
|
-
typed = false;
|
|
296
|
+
if (!itemDataset.typed) {
|
|
297
|
+
dataset.typed = false;
|
|
340
298
|
}
|
|
341
|
-
|
|
299
|
+
dataset.value.push(itemDataset.value);
|
|
342
300
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
return schemaResult(false, output, issues);
|
|
301
|
+
} else {
|
|
302
|
+
_addIssue(this, "type", dataset, config);
|
|
347
303
|
}
|
|
348
|
-
return
|
|
304
|
+
return dataset;
|
|
349
305
|
}
|
|
350
306
|
};
|
|
351
307
|
}
|
|
352
|
-
function object(entries,
|
|
353
|
-
const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4);
|
|
354
|
-
let cachedEntries;
|
|
308
|
+
function object(entries, message) {
|
|
355
309
|
return {
|
|
310
|
+
kind: "schema",
|
|
356
311
|
type: "object",
|
|
312
|
+
reference: object,
|
|
357
313
|
expects: "Object",
|
|
358
314
|
async: false,
|
|
359
315
|
entries,
|
|
360
|
-
rest,
|
|
361
316
|
message,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (input && typeof input === "object") {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const output = {};
|
|
369
|
-
for (const [key, schema] of cachedEntries) {
|
|
317
|
+
_run(dataset, config) {
|
|
318
|
+
const input = dataset.value;
|
|
319
|
+
if (input && typeof input === "object" && input.constructor === Object) {
|
|
320
|
+
dataset.typed = true;
|
|
321
|
+
dataset.value = {};
|
|
322
|
+
for (const key in this.entries) {
|
|
370
323
|
const value2 = input[key];
|
|
371
|
-
const
|
|
372
|
-
|
|
324
|
+
const valueDataset = this.entries[key]._run(
|
|
325
|
+
{ typed: false, value: value2 },
|
|
326
|
+
config
|
|
327
|
+
);
|
|
328
|
+
if (valueDataset.issues) {
|
|
373
329
|
const pathItem = {
|
|
374
330
|
type: "object",
|
|
375
331
|
origin: "value",
|
|
@@ -377,111 +333,81 @@ function object(entries, arg2, arg3, arg4) {
|
|
|
377
333
|
key,
|
|
378
334
|
value: value2
|
|
379
335
|
};
|
|
380
|
-
for (const issue of
|
|
336
|
+
for (const issue of valueDataset.issues) {
|
|
381
337
|
if (issue.path) {
|
|
382
338
|
issue.path.unshift(pathItem);
|
|
383
339
|
} else {
|
|
384
340
|
issue.path = [pathItem];
|
|
385
341
|
}
|
|
386
|
-
issues?.push(issue);
|
|
342
|
+
dataset.issues?.push(issue);
|
|
387
343
|
}
|
|
388
|
-
if (!issues) {
|
|
389
|
-
issues =
|
|
344
|
+
if (!dataset.issues) {
|
|
345
|
+
dataset.issues = valueDataset.issues;
|
|
390
346
|
}
|
|
391
|
-
if (config
|
|
392
|
-
typed = false;
|
|
347
|
+
if (config.abortEarly) {
|
|
348
|
+
dataset.typed = false;
|
|
393
349
|
break;
|
|
394
350
|
}
|
|
395
351
|
}
|
|
396
|
-
if (!
|
|
397
|
-
typed = false;
|
|
352
|
+
if (!valueDataset.typed) {
|
|
353
|
+
dataset.typed = false;
|
|
398
354
|
}
|
|
399
|
-
if (
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
if (this.rest && !(config?.abortEarly && issues)) {
|
|
404
|
-
for (const key in input) {
|
|
405
|
-
if (!(key in this.entries)) {
|
|
406
|
-
const value2 = input[key];
|
|
407
|
-
const result = this.rest._parse(value2, config);
|
|
408
|
-
if (result.issues) {
|
|
409
|
-
const pathItem = {
|
|
410
|
-
type: "object",
|
|
411
|
-
origin: "value",
|
|
412
|
-
input,
|
|
413
|
-
key,
|
|
414
|
-
value: value2
|
|
415
|
-
};
|
|
416
|
-
for (const issue of result.issues) {
|
|
417
|
-
if (issue.path) {
|
|
418
|
-
issue.path.unshift(pathItem);
|
|
419
|
-
} else {
|
|
420
|
-
issue.path = [pathItem];
|
|
421
|
-
}
|
|
422
|
-
issues?.push(issue);
|
|
423
|
-
}
|
|
424
|
-
if (!issues) {
|
|
425
|
-
issues = result.issues;
|
|
426
|
-
}
|
|
427
|
-
if (config?.abortEarly) {
|
|
428
|
-
typed = false;
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (!result.typed) {
|
|
433
|
-
typed = false;
|
|
434
|
-
}
|
|
435
|
-
output[key] = result.output;
|
|
436
|
-
}
|
|
355
|
+
if (valueDataset.value !== void 0 || key in input) {
|
|
356
|
+
dataset.value[key] = valueDataset.value;
|
|
437
357
|
}
|
|
438
358
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
this,
|
|
442
|
-
output,
|
|
443
|
-
config,
|
|
444
|
-
issues
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
return schemaResult(false, output, issues);
|
|
359
|
+
} else {
|
|
360
|
+
_addIssue(this, "type", dataset, config);
|
|
448
361
|
}
|
|
449
|
-
return
|
|
362
|
+
return dataset;
|
|
450
363
|
}
|
|
451
364
|
};
|
|
452
365
|
}
|
|
453
|
-
function optional(wrapped,
|
|
454
|
-
|
|
366
|
+
function optional(wrapped, ...args) {
|
|
367
|
+
const schema = {
|
|
368
|
+
kind: "schema",
|
|
455
369
|
type: "optional",
|
|
370
|
+
reference: optional,
|
|
456
371
|
expects: `${wrapped.expects} | undefined`,
|
|
457
372
|
async: false,
|
|
458
373
|
wrapped,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
374
|
+
_run(dataset, config) {
|
|
375
|
+
if (dataset.value === void 0) {
|
|
376
|
+
if ("default" in this) {
|
|
377
|
+
dataset.value = getDefault(
|
|
378
|
+
this,
|
|
379
|
+
dataset,
|
|
380
|
+
config
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
if (dataset.value === void 0) {
|
|
384
|
+
dataset.typed = true;
|
|
385
|
+
return dataset;
|
|
465
386
|
}
|
|
466
|
-
input = override;
|
|
467
387
|
}
|
|
468
|
-
return this.wrapped.
|
|
388
|
+
return this.wrapped._run(dataset, config);
|
|
469
389
|
}
|
|
470
390
|
};
|
|
391
|
+
if (0 in args) {
|
|
392
|
+
schema.default = args[0];
|
|
393
|
+
}
|
|
394
|
+
return schema;
|
|
471
395
|
}
|
|
472
|
-
function string(
|
|
473
|
-
const [message, pipe] = defaultArgs(arg1, arg2);
|
|
396
|
+
function string(message) {
|
|
474
397
|
return {
|
|
398
|
+
kind: "schema",
|
|
475
399
|
type: "string",
|
|
400
|
+
reference: string,
|
|
476
401
|
expects: "string",
|
|
477
402
|
async: false,
|
|
478
403
|
message,
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
404
|
+
_run(dataset, config) {
|
|
405
|
+
if (typeof dataset.value === "string") {
|
|
406
|
+
dataset.typed = true;
|
|
407
|
+
} else {
|
|
408
|
+
_addIssue(this, "type", dataset, config);
|
|
483
409
|
}
|
|
484
|
-
return
|
|
410
|
+
return dataset;
|
|
485
411
|
}
|
|
486
412
|
};
|
|
487
413
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13-next.1",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"./package.json"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@typescript-eslint/utils": "^7.
|
|
39
|
-
"deepmerge-ts": "
|
|
38
|
+
"@typescript-eslint/utils": "^7.10.0",
|
|
39
|
+
"deepmerge-ts": "7.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"type-fest": "4.18.2",
|
|
43
|
-
"valibot": "0.
|
|
43
|
+
"valibot": "0.31.0-rc.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsup",
|