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