@eslint-react/shared 1.23.2-next.1 → 1.23.2-next.3

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 CHANGED
@@ -2,7 +2,6 @@ import { ESLintUtils } from '@typescript-eslint/utils';
2
2
  import { E } from '@eslint-react/eff';
3
3
  import * as valibot from 'valibot';
4
4
  import { InferOutput } from 'valibot';
5
- import * as micro_memoize from 'micro-memoize';
6
5
 
7
6
  /**
8
7
  * The NPM scope for this project.
@@ -584,140 +583,6 @@ interface ESLintReactSettingsNormalized extends ESLintReactSettings {
584
583
  version: string;
585
584
  }
586
585
 
587
- /**
588
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
589
-
590
- @category Type
591
- */
592
- type Primitive =
593
- | null
594
- | undefined
595
- | string
596
- | number
597
- | boolean
598
- | symbol
599
- | bigint;
600
-
601
- declare global {
602
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
603
- interface SymbolConstructor {
604
- readonly observable: symbol;
605
- }
606
- }
607
-
608
- /**
609
- Matches any primitive, `void`, `Date`, or `RegExp` value.
610
- */
611
- type BuiltIns = Primitive | void | Date | RegExp;
612
-
613
- /**
614
- @see PartialDeep
615
- */
616
- type PartialDeepOptions = {
617
- /**
618
- Whether to affect the individual elements of arrays and tuples.
619
-
620
- @default false
621
- */
622
- readonly recurseIntoArrays?: boolean;
623
- };
624
-
625
- /**
626
- Create a type from another type with all keys and nested keys set to optional.
627
-
628
- Use-cases:
629
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
630
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
631
-
632
- @example
633
- ```
634
- import type {PartialDeep} from 'type-fest';
635
-
636
- const settings: Settings = {
637
- textEditor: {
638
- fontSize: 14;
639
- fontColor: '#000000';
640
- fontWeight: 400;
641
- }
642
- autocomplete: false;
643
- autosave: true;
644
- };
645
-
646
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
647
- return {...settings, ...savedSettings};
648
- }
649
-
650
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
651
- ```
652
-
653
- By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
654
-
655
- ```
656
- import type {PartialDeep} from 'type-fest';
657
-
658
- interface Settings {
659
- languages: string[];
660
- }
661
-
662
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
663
- languages: [undefined]
664
- };
665
- ```
666
-
667
- @category Object
668
- @category Array
669
- @category Set
670
- @category Map
671
- */
672
- type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
673
- ? T
674
- : T extends Map<infer KeyType, infer ValueType>
675
- ? PartialMapDeep<KeyType, ValueType, Options>
676
- : T extends Set<infer ItemType>
677
- ? PartialSetDeep<ItemType, Options>
678
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
679
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
680
- : T extends ReadonlySet<infer ItemType>
681
- ? PartialReadonlySetDeep<ItemType, Options>
682
- : T extends object
683
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
684
- ? Options['recurseIntoArrays'] extends true
685
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
686
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
687
- ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
688
- : Array<PartialDeep<ItemType | undefined, Options>>
689
- : PartialObjectDeep<T, Options> // Tuples behave properly
690
- : T // If they don't opt into array testing, just use the original type
691
- : PartialObjectDeep<T, Options>
692
- : unknown;
693
-
694
- /**
695
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
696
- */
697
- type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
698
-
699
- /**
700
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
701
- */
702
- type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
703
-
704
- /**
705
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
706
- */
707
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
708
-
709
- /**
710
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
711
- */
712
- type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
713
-
714
- /**
715
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
716
- */
717
- type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
718
- [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
719
- };
720
-
721
586
  /**
722
587
  * The default ESLint settings for "react-x".
723
588
  */
@@ -730,26 +595,14 @@ declare const DEFAULT_ESLINT_REACT_SETTINGS: {
730
595
  readonly version: "detect";
731
596
  };
732
597
  /**
733
- * Unsafely casts settings from a data object from `context.settings`.
734
- * @internal
735
- * @param data The data object.
736
- * @returns settings The settings.
737
- */
738
- declare function unsafeReadSettings(data: unknown): PartialDeep<ESLintReactSettings>;
739
- /**
740
- * Decodes settings from a data object from `context.settings`.
741
- * @internal
742
- * @param data The data object.
743
- * @returns settings The settings.
744
- */
745
- declare const decodeSettings: micro_memoize.Memoized<(data: unknown) => ESLintReactSettings>;
746
- /**
747
- * Normalizes the settings by converting all shorthand properties to their full form.
748
- * @param settings The settings.
749
- * @returns The normalized settings.
750
- * @internal
598
+ * Get the normalized ESLint settings for "react-x" from the given context.
599
+ * @param context The context.
600
+ * @param context.settings The ESLint settings.
601
+ * @returns The normalized ESLint settings.
751
602
  */
752
- declare const normalizeSettings: micro_memoize.Memoized<(settings: ESLintReactSettings) => ESLintReactSettingsNormalized>;
603
+ declare function getSettingsFromContext(context: {
604
+ settings: unknown;
605
+ }): ESLintReactSettingsNormalized;
753
606
  /**
754
607
  * A helper function to define settings for "react-x" with type checking in JavaScript files.
755
608
  * @param settings The settings.
@@ -762,4 +615,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
762
615
  }
763
616
  }
764
617
 
765
- export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentNormalized, CustomComponentNormalizedSchema, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, getReactVersion, normalizeSettings, unsafeReadSettings };
618
+ export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentNormalized, CustomComponentNormalizedSchema, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, defineSettings, getReactVersion, getSettingsFromContext };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { ESLintUtils } from '@typescript-eslint/utils';
2
2
  import { E } from '@eslint-react/eff';
3
3
  import * as valibot from 'valibot';
4
4
  import { InferOutput } from 'valibot';
5
- import * as micro_memoize from 'micro-memoize';
6
5
 
7
6
  /**
8
7
  * The NPM scope for this project.
@@ -584,140 +583,6 @@ interface ESLintReactSettingsNormalized extends ESLintReactSettings {
584
583
  version: string;
585
584
  }
586
585
 
587
- /**
588
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
589
-
590
- @category Type
591
- */
592
- type Primitive =
593
- | null
594
- | undefined
595
- | string
596
- | number
597
- | boolean
598
- | symbol
599
- | bigint;
600
-
601
- declare global {
602
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
603
- interface SymbolConstructor {
604
- readonly observable: symbol;
605
- }
606
- }
607
-
608
- /**
609
- Matches any primitive, `void`, `Date`, or `RegExp` value.
610
- */
611
- type BuiltIns = Primitive | void | Date | RegExp;
612
-
613
- /**
614
- @see PartialDeep
615
- */
616
- type PartialDeepOptions = {
617
- /**
618
- Whether to affect the individual elements of arrays and tuples.
619
-
620
- @default false
621
- */
622
- readonly recurseIntoArrays?: boolean;
623
- };
624
-
625
- /**
626
- Create a type from another type with all keys and nested keys set to optional.
627
-
628
- Use-cases:
629
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
630
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
631
-
632
- @example
633
- ```
634
- import type {PartialDeep} from 'type-fest';
635
-
636
- const settings: Settings = {
637
- textEditor: {
638
- fontSize: 14;
639
- fontColor: '#000000';
640
- fontWeight: 400;
641
- }
642
- autocomplete: false;
643
- autosave: true;
644
- };
645
-
646
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
647
- return {...settings, ...savedSettings};
648
- }
649
-
650
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
651
- ```
652
-
653
- By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
654
-
655
- ```
656
- import type {PartialDeep} from 'type-fest';
657
-
658
- interface Settings {
659
- languages: string[];
660
- }
661
-
662
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
663
- languages: [undefined]
664
- };
665
- ```
666
-
667
- @category Object
668
- @category Array
669
- @category Set
670
- @category Map
671
- */
672
- type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
673
- ? T
674
- : T extends Map<infer KeyType, infer ValueType>
675
- ? PartialMapDeep<KeyType, ValueType, Options>
676
- : T extends Set<infer ItemType>
677
- ? PartialSetDeep<ItemType, Options>
678
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
679
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
680
- : T extends ReadonlySet<infer ItemType>
681
- ? PartialReadonlySetDeep<ItemType, Options>
682
- : T extends object
683
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
684
- ? Options['recurseIntoArrays'] extends true
685
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
686
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
687
- ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
688
- : Array<PartialDeep<ItemType | undefined, Options>>
689
- : PartialObjectDeep<T, Options> // Tuples behave properly
690
- : T // If they don't opt into array testing, just use the original type
691
- : PartialObjectDeep<T, Options>
692
- : unknown;
693
-
694
- /**
695
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
696
- */
697
- type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
698
-
699
- /**
700
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
701
- */
702
- type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
703
-
704
- /**
705
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
706
- */
707
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
708
-
709
- /**
710
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
711
- */
712
- type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
713
-
714
- /**
715
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
716
- */
717
- type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
718
- [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
719
- };
720
-
721
586
  /**
722
587
  * The default ESLint settings for "react-x".
723
588
  */
@@ -730,26 +595,14 @@ declare const DEFAULT_ESLINT_REACT_SETTINGS: {
730
595
  readonly version: "detect";
731
596
  };
732
597
  /**
733
- * Unsafely casts settings from a data object from `context.settings`.
734
- * @internal
735
- * @param data The data object.
736
- * @returns settings The settings.
737
- */
738
- declare function unsafeReadSettings(data: unknown): PartialDeep<ESLintReactSettings>;
739
- /**
740
- * Decodes settings from a data object from `context.settings`.
741
- * @internal
742
- * @param data The data object.
743
- * @returns settings The settings.
744
- */
745
- declare const decodeSettings: micro_memoize.Memoized<(data: unknown) => ESLintReactSettings>;
746
- /**
747
- * Normalizes the settings by converting all shorthand properties to their full form.
748
- * @param settings The settings.
749
- * @returns The normalized settings.
750
- * @internal
598
+ * Get the normalized ESLint settings for "react-x" from the given context.
599
+ * @param context The context.
600
+ * @param context.settings The ESLint settings.
601
+ * @returns The normalized ESLint settings.
751
602
  */
752
- declare const normalizeSettings: micro_memoize.Memoized<(settings: ESLintReactSettings) => ESLintReactSettingsNormalized>;
603
+ declare function getSettingsFromContext(context: {
604
+ settings: unknown;
605
+ }): ESLintReactSettingsNormalized;
753
606
  /**
754
607
  * A helper function to define settings for "react-x" with type checking in JavaScript files.
755
608
  * @param settings The settings.
@@ -762,4 +615,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
762
615
  }
763
616
  }
764
617
 
765
- export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentNormalized, CustomComponentNormalizedSchema, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, getReactVersion, normalizeSettings, unsafeReadSettings };
618
+ export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentNormalized, CustomComponentNormalizedSchema, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, defineSettings, getReactVersion, getSettingsFromContext };
package/dist/index.js CHANGED
@@ -5,15 +5,12 @@ var eff = require('@eslint-react/eff');
5
5
  var tsPattern = require('ts-pattern');
6
6
  var module$1 = require('module');
7
7
  var valibot = require('valibot');
8
- var fastEquals = require('fast-equals');
9
- var memoize = require('micro-memoize');
10
8
  var pm = require('picomatch');
11
9
 
12
10
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
12
 
15
13
  var module__default = /*#__PURE__*/_interopDefault(module$1);
16
- var memoize__default = /*#__PURE__*/_interopDefault(memoize);
17
14
  var pm__default = /*#__PURE__*/_interopDefault(pm);
18
15
 
19
16
  // src/constants.ts
@@ -385,6 +382,11 @@ var ESLintSettingsSchema = valibot.optional(
385
382
  }),
386
383
  {}
387
384
  );
385
+
386
+ // src/cache.ts
387
+ var normalizedSettingsCache = /* @__PURE__ */ new WeakMap();
388
+
389
+ // src/settings.ts
388
390
  var DEFAULT_ESLINT_REACT_SETTINGS = {
389
391
  additionalHooks: {
390
392
  useLayoutEffect: ["useIsomorphicLayoutEffect"]
@@ -393,19 +395,20 @@ var DEFAULT_ESLINT_REACT_SETTINGS = {
393
395
  strictImportCheck: false,
394
396
  version: "detect"
395
397
  };
396
- function unsafeReadSettings(data) {
397
- return data?.["react-x"] ?? {};
398
- }
399
- var decodeSettings = memoize__default.default((data) => {
400
- return {
398
+ function getSettingsFromContext(context) {
399
+ valibot.assert(ESLintSettingsSchema, context.settings);
400
+ const raw = context.settings?.["react-x"] ?? {};
401
+ const memoized = normalizedSettingsCache.get(raw);
402
+ if (memoized) {
403
+ return memoized;
404
+ }
405
+ const rawWithDefaults = {
401
406
  ...DEFAULT_ESLINT_REACT_SETTINGS,
402
- ...valibot.parse(ESLintSettingsSchema, data)["react-x"] ?? {}
407
+ ...raw
403
408
  };
404
- }, { isEqual: (a, b) => a === b });
405
- var normalizeSettings = memoize__default.default((settings) => {
406
- const additionalComponents = settings.additionalComponents ?? [];
407
- return {
408
- ...settings,
409
+ const additionalComponents = rawWithDefaults.additionalComponents ?? [];
410
+ const normalized = {
411
+ ...rawWithDefaults,
409
412
  additionalComponents: additionalComponents.map((component) => ({
410
413
  ...component,
411
414
  attributes: component.attributes?.map((attr) => ({
@@ -420,9 +423,11 @@ var normalizeSettings = memoize__default.default((settings) => {
420
423
  if (!/^[\w-]+$/u.test(name)) return acc;
421
424
  return acc.set(name, as);
422
425
  }, /* @__PURE__ */ new Map()),
423
- version: tsPattern.match(settings.version).with(tsPattern.P.union(tsPattern.P.nullish, "", "detect"), () => eff.E.getOrElse(getReactVersion(), eff.F.constant("19.0.0"))).otherwise(eff.F.identity)
426
+ version: tsPattern.match(rawWithDefaults.version).with(tsPattern.P.union(tsPattern.P.nullish, "", "detect"), () => eff.E.getOrElse(getReactVersion(), eff.F.constant("19.0.0"))).otherwise(eff.F.identity)
424
427
  };
425
- }, { isEqual: fastEquals.shallowEqual });
428
+ normalizedSettingsCache.set(raw, normalized);
429
+ return normalized;
430
+ }
426
431
  var defineSettings = eff.F.identity;
427
432
 
428
433
  exports.CustomAttributeSchema = CustomAttributeSchema;
@@ -445,8 +450,6 @@ exports.RE_PASCAL_CASE = RE_PASCAL_CASE;
445
450
  exports.RE_SNAKE_CASE = RE_SNAKE_CASE;
446
451
  exports.WEBSITE_URL = WEBSITE_URL;
447
452
  exports.createRuleForPlugin = createRuleForPlugin;
448
- exports.decodeSettings = decodeSettings;
449
453
  exports.defineSettings = defineSettings;
450
454
  exports.getReactVersion = getReactVersion;
451
- exports.normalizeSettings = normalizeSettings;
452
- exports.unsafeReadSettings = unsafeReadSettings;
455
+ exports.getSettingsFromContext = getSettingsFromContext;
package/dist/index.mjs CHANGED
@@ -1,10 +1,8 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- import { E, F } from '@eslint-react/eff';
3
- import { match, P, isMatching } from 'ts-pattern';
2
+ import { F, E } from '@eslint-react/eff';
3
+ import { isMatching, P, match } from 'ts-pattern';
4
4
  import module from 'node:module';
5
- import { object, string, optional, boolean, array, instance, parse } from 'valibot';
6
- import { shallowEqual } from 'fast-equals';
7
- import memoize from 'micro-memoize';
5
+ import { object, string, optional, boolean, array, instance, assert } from 'valibot';
8
6
  import pm from 'picomatch';
9
7
 
10
8
  // src/constants.ts
@@ -376,6 +374,11 @@ var ESLintSettingsSchema = optional(
376
374
  }),
377
375
  {}
378
376
  );
377
+
378
+ // src/cache.ts
379
+ var normalizedSettingsCache = /* @__PURE__ */ new WeakMap();
380
+
381
+ // src/settings.ts
379
382
  var DEFAULT_ESLINT_REACT_SETTINGS = {
380
383
  additionalHooks: {
381
384
  useLayoutEffect: ["useIsomorphicLayoutEffect"]
@@ -384,19 +387,20 @@ var DEFAULT_ESLINT_REACT_SETTINGS = {
384
387
  strictImportCheck: false,
385
388
  version: "detect"
386
389
  };
387
- function unsafeReadSettings(data) {
388
- return data?.["react-x"] ?? {};
389
- }
390
- var decodeSettings = memoize((data) => {
391
- return {
390
+ function getSettingsFromContext(context) {
391
+ assert(ESLintSettingsSchema, context.settings);
392
+ const raw = context.settings?.["react-x"] ?? {};
393
+ const memoized = normalizedSettingsCache.get(raw);
394
+ if (memoized) {
395
+ return memoized;
396
+ }
397
+ const rawWithDefaults = {
392
398
  ...DEFAULT_ESLINT_REACT_SETTINGS,
393
- ...parse(ESLintSettingsSchema, data)["react-x"] ?? {}
399
+ ...raw
394
400
  };
395
- }, { isEqual: (a, b) => a === b });
396
- var normalizeSettings = memoize((settings) => {
397
- const additionalComponents = settings.additionalComponents ?? [];
398
- return {
399
- ...settings,
401
+ const additionalComponents = rawWithDefaults.additionalComponents ?? [];
402
+ const normalized = {
403
+ ...rawWithDefaults,
400
404
  additionalComponents: additionalComponents.map((component) => ({
401
405
  ...component,
402
406
  attributes: component.attributes?.map((attr) => ({
@@ -411,9 +415,11 @@ var normalizeSettings = memoize((settings) => {
411
415
  if (!/^[\w-]+$/u.test(name)) return acc;
412
416
  return acc.set(name, as);
413
417
  }, /* @__PURE__ */ new Map()),
414
- version: match(settings.version).with(P.union(P.nullish, "", "detect"), () => E.getOrElse(getReactVersion(), F.constant("19.0.0"))).otherwise(F.identity)
418
+ version: match(rawWithDefaults.version).with(P.union(P.nullish, "", "detect"), () => E.getOrElse(getReactVersion(), F.constant("19.0.0"))).otherwise(F.identity)
415
419
  };
416
- }, { isEqual: shallowEqual });
420
+ normalizedSettingsCache.set(raw, normalized);
421
+ return normalized;
422
+ }
417
423
  var defineSettings = F.identity;
418
424
 
419
- export { CustomAttributeSchema, CustomComponentNormalizedSchema, CustomComponentSchema, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, getReactVersion, normalizeSettings, unsafeReadSettings };
425
+ export { CustomAttributeSchema, CustomComponentNormalizedSchema, CustomComponentSchema, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, 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, defineSettings, getReactVersion, getSettingsFromContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "1.23.2-next.1",
3
+ "version": "1.23.2-next.3",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/rEl1cx/eslint-react",
6
6
  "bugs": {
@@ -34,12 +34,10 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@typescript-eslint/utils": "^8.19.0",
37
- "fast-equals": "^5.0.1",
38
- "micro-memoize": "^4.1.2",
39
37
  "picomatch": "^4.0.2",
40
38
  "ts-pattern": "^5.6.0",
41
- "valibot": "^1.0.0-beta.9",
42
- "@eslint-react/eff": "1.23.2-next.1"
39
+ "valibot": "^1.0.0-beta.10",
40
+ "@eslint-react/eff": "1.23.2-next.3"
43
41
  },
44
42
  "devDependencies": {
45
43
  "@types/picomatch": "^3.0.1",