@eslint-react/shared 1.12.1 → 1.12.2-beta.5

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.js CHANGED
@@ -377,6 +377,25 @@ function boolean(message) {
377
377
  }
378
378
  };
379
379
  }
380
+ function instance(class_, message) {
381
+ return {
382
+ kind: "schema",
383
+ type: "instance",
384
+ reference: instance,
385
+ expects: class_.name,
386
+ async: false,
387
+ class: class_,
388
+ message,
389
+ _run(dataset, config2) {
390
+ if (dataset.value instanceof this.class) {
391
+ dataset.typed = true;
392
+ } else {
393
+ _addIssue(this, "type", dataset, config2);
394
+ }
395
+ return dataset;
396
+ }
397
+ };
398
+ }
380
399
  function object(entries, message) {
381
400
  return {
382
401
  kind: "schema",
@@ -550,6 +569,13 @@ var CustomComponentSchema = object({
550
569
  */
551
570
  attributes: optional(array(CustomAttributeSchema), [])
552
571
  });
572
+ var CustomComponentNormalizedSchema = object({
573
+ name: string(),
574
+ as: optional(string()),
575
+ attributes: optional(array(CustomAttributeSchema), []),
576
+ re: instance(RegExp),
577
+ selector: optional(string())
578
+ });
553
579
  var ESLintReactSettingsSchema = object({
554
580
  /**
555
581
  * The source where React is imported from.
@@ -1281,52 +1307,48 @@ function createMemoizedFunction(fn, options) {
1281
1307
  var INITIAL_ESLINT_REACT_SETTINGS = {
1282
1308
  skipImportCheck: false
1283
1309
  };
1284
- var DEFAULT_ESLINT_REACT_SETTINGS = {
1285
- additionalHooks: {
1286
- useLayoutEffect: ["useIsomorphicLayoutEffect"]
1287
- },
1288
- polymorphicPropName: "as",
1289
- skipImportCheck: false,
1290
- version: "detect"
1291
- };
1292
- var defineSettings = tools.F.identity;
1310
+ function unsafeReadSettings(data) {
1311
+ return tools.Data.struct(data?.["react-x"] ?? {});
1312
+ }
1293
1313
  var decodeSettings = createMemoizedFunction((data) => {
1294
1314
  return tools.Data.struct({
1295
1315
  ...INITIAL_ESLINT_REACT_SETTINGS,
1296
1316
  ...parse(ESLintSettingsSchema, data)["react-x"] ?? {}
1297
1317
  });
1298
1318
  }, { isEqual: (a, b) => a === b });
1299
- function unsafeCastSettings(data) {
1300
- return tools.Data.struct(data?.["react-x"] ?? {});
1301
- }
1302
- var expandSettings = createMemoizedFunction(
1303
- (settings) => {
1304
- const additionalComponents = settings.additionalComponents ?? [];
1305
- return tools.Data.struct({
1306
- ...settings,
1307
- additionalComponents: additionalComponents.map((component) => ({
1308
- ...component,
1309
- attributes: component.attributes.map((attr) => ({
1310
- ...attr,
1311
- as: attr.as ?? attr.name
1312
- })),
1313
- re: pm__default.default.makeRe(component.name, { fastpaths: true })
1319
+ var normalizeSettings = createMemoizedFunction((settings) => {
1320
+ const additionalComponents = settings.additionalComponents ?? [];
1321
+ return tools.Data.struct({
1322
+ ...settings,
1323
+ additionalComponents: additionalComponents.map((component) => ({
1324
+ ...component,
1325
+ attributes: component.attributes.map((attr) => ({
1326
+ ...attr,
1327
+ as: attr.as ?? attr.name
1314
1328
  })),
1315
- components: additionalComponents.reduce((acc, component) => {
1316
- const { name, as, attributes, selector } = component;
1317
- if (!name || !as || selector || attributes.length > 0) return acc;
1318
- if (!/^[\w-]+$/u.test(name)) return acc;
1319
- return acc.set(name, as);
1320
- }, /* @__PURE__ */ new Map())
1321
- });
1322
- },
1323
- { isEqual: shallowEqual }
1324
- );
1329
+ re: pm__default.default.makeRe(component.name, { fastpaths: true })
1330
+ })),
1331
+ components: additionalComponents.reduce((acc, component) => {
1332
+ const { name, as, attributes, selector } = component;
1333
+ if (!name || !as || selector || attributes.length > 0) return acc;
1334
+ if (!/^[\w-]+$/u.test(name)) return acc;
1335
+ return acc.set(name, as);
1336
+ }, /* @__PURE__ */ new Map())
1337
+ });
1338
+ }, { isEqual: shallowEqual });
1339
+ function findAttrInCustomAttributes(name, attributes) {
1340
+ return tools.F.pipe(
1341
+ tools.O.fromNullable(attributes.findLast((a) => a.as === name)),
1342
+ tools.O.map((a) => [a.name, a.defaultValue]),
1343
+ tools.O.getOrElse(() => [name])
1344
+ );
1345
+ }
1346
+ var defineSettings = tools.F.identity;
1325
1347
 
1326
1348
  exports.CustomAttributeSchema = CustomAttributeSchema;
1349
+ exports.CustomComponentNormalizedSchema = CustomComponentNormalizedSchema;
1327
1350
  exports.CustomComponentSchema = CustomComponentSchema;
1328
1351
  exports.CustomHookSchema = CustomHookSchema;
1329
- exports.DEFAULT_ESLINT_REACT_SETTINGS = DEFAULT_ESLINT_REACT_SETTINGS;
1330
1352
  exports.ESLintReactSettingsSchema = ESLintReactSettingsSchema;
1331
1353
  exports.ESLintSettingsSchema = ESLintSettingsSchema;
1332
1354
  exports.GITHUB_URL = GITHUB_URL;
@@ -1345,5 +1367,6 @@ exports.WEBSITE_URL = WEBSITE_URL;
1345
1367
  exports.createRuleForPlugin = createRuleForPlugin;
1346
1368
  exports.decodeSettings = decodeSettings;
1347
1369
  exports.defineSettings = defineSettings;
1348
- exports.expandSettings = expandSettings;
1349
- exports.unsafeCastSettings = unsafeCastSettings;
1370
+ exports.findAttrInCustomAttributes = findAttrInCustomAttributes;
1371
+ exports.normalizeSettings = normalizeSettings;
1372
+ exports.unsafeReadSettings = unsafeReadSettings;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- import { F, Data } from '@eslint-react/tools';
2
+ import { F, Data, O } from '@eslint-react/tools';
3
3
  import pm from 'picomatch';
4
4
 
5
5
  // src/constants.ts
@@ -371,6 +371,25 @@ function boolean(message) {
371
371
  }
372
372
  };
373
373
  }
374
+ function instance(class_, message) {
375
+ return {
376
+ kind: "schema",
377
+ type: "instance",
378
+ reference: instance,
379
+ expects: class_.name,
380
+ async: false,
381
+ class: class_,
382
+ message,
383
+ _run(dataset, config2) {
384
+ if (dataset.value instanceof this.class) {
385
+ dataset.typed = true;
386
+ } else {
387
+ _addIssue(this, "type", dataset, config2);
388
+ }
389
+ return dataset;
390
+ }
391
+ };
392
+ }
374
393
  function object(entries, message) {
375
394
  return {
376
395
  kind: "schema",
@@ -544,6 +563,13 @@ var CustomComponentSchema = object({
544
563
  */
545
564
  attributes: optional(array(CustomAttributeSchema), [])
546
565
  });
566
+ var CustomComponentNormalizedSchema = object({
567
+ name: string(),
568
+ as: optional(string()),
569
+ attributes: optional(array(CustomAttributeSchema), []),
570
+ re: instance(RegExp),
571
+ selector: optional(string())
572
+ });
547
573
  var ESLintReactSettingsSchema = object({
548
574
  /**
549
575
  * The source where React is imported from.
@@ -1275,46 +1301,42 @@ function createMemoizedFunction(fn, options) {
1275
1301
  var INITIAL_ESLINT_REACT_SETTINGS = {
1276
1302
  skipImportCheck: false
1277
1303
  };
1278
- var DEFAULT_ESLINT_REACT_SETTINGS = {
1279
- additionalHooks: {
1280
- useLayoutEffect: ["useIsomorphicLayoutEffect"]
1281
- },
1282
- polymorphicPropName: "as",
1283
- skipImportCheck: false,
1284
- version: "detect"
1285
- };
1286
- var defineSettings = F.identity;
1304
+ function unsafeReadSettings(data) {
1305
+ return Data.struct(data?.["react-x"] ?? {});
1306
+ }
1287
1307
  var decodeSettings = createMemoizedFunction((data) => {
1288
1308
  return Data.struct({
1289
1309
  ...INITIAL_ESLINT_REACT_SETTINGS,
1290
1310
  ...parse(ESLintSettingsSchema, data)["react-x"] ?? {}
1291
1311
  });
1292
1312
  }, { isEqual: (a, b) => a === b });
1293
- function unsafeCastSettings(data) {
1294
- return Data.struct(data?.["react-x"] ?? {});
1295
- }
1296
- var expandSettings = createMemoizedFunction(
1297
- (settings) => {
1298
- const additionalComponents = settings.additionalComponents ?? [];
1299
- return Data.struct({
1300
- ...settings,
1301
- additionalComponents: additionalComponents.map((component) => ({
1302
- ...component,
1303
- attributes: component.attributes.map((attr) => ({
1304
- ...attr,
1305
- as: attr.as ?? attr.name
1306
- })),
1307
- re: pm.makeRe(component.name, { fastpaths: true })
1313
+ var normalizeSettings = createMemoizedFunction((settings) => {
1314
+ const additionalComponents = settings.additionalComponents ?? [];
1315
+ return Data.struct({
1316
+ ...settings,
1317
+ additionalComponents: additionalComponents.map((component) => ({
1318
+ ...component,
1319
+ attributes: component.attributes.map((attr) => ({
1320
+ ...attr,
1321
+ as: attr.as ?? attr.name
1308
1322
  })),
1309
- components: additionalComponents.reduce((acc, component) => {
1310
- const { name, as, attributes, selector } = component;
1311
- if (!name || !as || selector || attributes.length > 0) return acc;
1312
- if (!/^[\w-]+$/u.test(name)) return acc;
1313
- return acc.set(name, as);
1314
- }, /* @__PURE__ */ new Map())
1315
- });
1316
- },
1317
- { isEqual: shallowEqual }
1318
- );
1323
+ re: pm.makeRe(component.name, { fastpaths: true })
1324
+ })),
1325
+ components: additionalComponents.reduce((acc, component) => {
1326
+ const { name, as, attributes, selector } = component;
1327
+ if (!name || !as || selector || attributes.length > 0) return acc;
1328
+ if (!/^[\w-]+$/u.test(name)) return acc;
1329
+ return acc.set(name, as);
1330
+ }, /* @__PURE__ */ new Map())
1331
+ });
1332
+ }, { isEqual: shallowEqual });
1333
+ function findAttrInCustomAttributes(name, attributes) {
1334
+ return F.pipe(
1335
+ O.fromNullable(attributes.findLast((a) => a.as === name)),
1336
+ O.map((a) => [a.name, a.defaultValue]),
1337
+ O.getOrElse(() => [name])
1338
+ );
1339
+ }
1340
+ var defineSettings = F.identity;
1319
1341
 
1320
- export { CustomAttributeSchema, CustomComponentSchema, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, INITIAL_ESLINT_REACT_SETTINGS, NPM_SCOPE, REACT_BUILD_IN_HOOKS, RE_CAMEL_CASE, RE_CONSTANT_CASE, RE_JAVASCRIPT_PROTOCOL, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_SNAKE_CASE, WEBSITE_URL, createRuleForPlugin, decodeSettings, defineSettings, expandSettings, unsafeCastSettings };
1342
+ export { CustomAttributeSchema, CustomComponentNormalizedSchema, CustomComponentSchema, CustomHookSchema, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, INITIAL_ESLINT_REACT_SETTINGS, NPM_SCOPE, REACT_BUILD_IN_HOOKS, RE_CAMEL_CASE, RE_CONSTANT_CASE, RE_JAVASCRIPT_PROTOCOL, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_SNAKE_CASE, WEBSITE_URL, createRuleForPlugin, decodeSettings, defineSettings, findAttrInCustomAttributes, normalizeSettings, unsafeReadSettings };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "1.12.1",
3
+ "version": "1.12.2-beta.5",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -35,9 +35,9 @@
35
35
  "./package.json"
36
36
  ],
37
37
  "dependencies": {
38
- "@typescript-eslint/utils": "^8.2.0",
38
+ "@typescript-eslint/utils": "^8.3.0",
39
39
  "picomatch": "^4.0.2",
40
- "@eslint-react/tools": "1.12.1"
40
+ "@eslint-react/tools": "1.12.2-beta.5"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/picomatch": "^3.0.1",
@@ -45,7 +45,7 @@
45
45
  "micro-memoize": "^4.1.2",
46
46
  "tsup": "^8.2.4",
47
47
  "type-fest": "^4.25.0",
48
- "valibot": "^0.38.0"
48
+ "valibot": "^0.39.0"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsup --dts-resolve",