@eslint-react/shared 1.8.3-beta.1 → 1.8.3-beta.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
@@ -60,6 +60,7 @@ declare const REACT_BUILD_IN_HOOKS: readonly ["useActionState", "useCallback", "
60
60
 
61
61
  /**
62
62
  * Get the ESLint rule creator for a plugin.
63
+ * @internal
63
64
  * @param pluginName The name of the plugin.
64
65
  * @returns The ESLint rule creator.
65
66
  */
@@ -1583,12 +1584,46 @@ declare const CustomComponentSchema: ObjectSchema<{
1583
1584
  * @internal
1584
1585
  */
1585
1586
  declare const ESLintReactSettingsSchema: ObjectSchema<{
1587
+ /**
1588
+ * The source where React is imported from.
1589
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1590
+ * @default `"react"`
1591
+ * @example `"@pika/react"`
1592
+ */
1586
1593
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1594
+ /**
1595
+ * The identifier that’s used for JSX Element creation.
1596
+ * @default `"createElement"`
1597
+ */
1587
1598
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1599
+ /**
1600
+ * The identifier that’s used for JSX fragment elements.
1601
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1602
+ * @default `"Fragment"`
1603
+ */
1588
1604
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1605
+ /**
1606
+ * The name of the prop that is used for polymorphic components.
1607
+ * @description This is used to determine the type of the component.
1608
+ * @example `"as"`
1609
+ */
1589
1610
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1611
+ /**
1612
+ * @internal
1613
+ */
1590
1614
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1615
+ /**
1616
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1617
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1618
+ * @example `"18.3.1"`
1619
+ * @default `"detect"`
1620
+ */
1591
1621
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1622
+ /**
1623
+ * An array of user-defined components
1624
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1625
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1626
+ */
1592
1627
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1593
1628
  /**
1594
1629
  * The name of the user-defined component.
@@ -1640,6 +1675,11 @@ declare const ESLintReactSettingsSchema: ObjectSchema<{
1640
1675
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1641
1676
  }, undefined>, undefined>, readonly []>;
1642
1677
  }, undefined>, undefined>, never>;
1678
+ /**
1679
+ * A object of aliases for React built-in hooks.
1680
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1681
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1682
+ */
1643
1683
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1644
1684
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1645
1685
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1666,12 +1706,46 @@ declare const ESLintReactSettingsSchema: ObjectSchema<{
1666
1706
  */
1667
1707
  declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1668
1708
  readonly "react-x": OptionalSchema<ObjectSchema<{
1709
+ /**
1710
+ * The source where React is imported from.
1711
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1712
+ * @default `"react"`
1713
+ * @example `"@pika/react"`
1714
+ */
1669
1715
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1716
+ /**
1717
+ * The identifier that’s used for JSX Element creation.
1718
+ * @default `"createElement"`
1719
+ */
1670
1720
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1721
+ /**
1722
+ * The identifier that’s used for JSX fragment elements.
1723
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1724
+ * @default `"Fragment"`
1725
+ */
1671
1726
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1727
+ /**
1728
+ * The name of the prop that is used for polymorphic components.
1729
+ * @description This is used to determine the type of the component.
1730
+ * @example `"as"`
1731
+ */
1672
1732
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1733
+ /**
1734
+ * @internal
1735
+ */
1673
1736
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1737
+ /**
1738
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1739
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1740
+ * @example `"18.3.1"`
1741
+ * @default `"detect"`
1742
+ */
1674
1743
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1744
+ /**
1745
+ * An array of user-defined components
1746
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1747
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1748
+ */
1675
1749
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1676
1750
  /**
1677
1751
  * The name of the user-defined component.
@@ -1723,6 +1797,11 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1723
1797
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1724
1798
  }, undefined>, undefined>, readonly []>;
1725
1799
  }, undefined>, undefined>, never>;
1800
+ /**
1801
+ * A object of aliases for React built-in hooks.
1802
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1803
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1804
+ */
1726
1805
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1727
1806
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1728
1807
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1749,12 +1828,46 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1749
1828
  * @deprecated
1750
1829
  */
1751
1830
  readonly reactOptions: OptionalSchema<ObjectSchema<{
1831
+ /**
1832
+ * The source where React is imported from.
1833
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1834
+ * @default `"react"`
1835
+ * @example `"@pika/react"`
1836
+ */
1752
1837
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1838
+ /**
1839
+ * The identifier that’s used for JSX Element creation.
1840
+ * @default `"createElement"`
1841
+ */
1753
1842
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1843
+ /**
1844
+ * The identifier that’s used for JSX fragment elements.
1845
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1846
+ * @default `"Fragment"`
1847
+ */
1754
1848
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1849
+ /**
1850
+ * The name of the prop that is used for polymorphic components.
1851
+ * @description This is used to determine the type of the component.
1852
+ * @example `"as"`
1853
+ */
1755
1854
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1855
+ /**
1856
+ * @internal
1857
+ */
1756
1858
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1859
+ /**
1860
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1861
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1862
+ * @example `"18.3.1"`
1863
+ * @default `"detect"`
1864
+ */
1757
1865
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1866
+ /**
1867
+ * An array of user-defined components
1868
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1869
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1870
+ */
1758
1871
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1759
1872
  /**
1760
1873
  * The name of the user-defined component.
@@ -1806,6 +1919,11 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1806
1919
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1807
1920
  }, undefined>, undefined>, readonly []>;
1808
1921
  }, undefined>, undefined>, never>;
1922
+ /**
1923
+ * A object of aliases for React built-in hooks.
1924
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1925
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1926
+ */
1809
1927
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1810
1928
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1811
1929
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1957,11 +2075,55 @@ interface ESLintReactSettingsExpanded extends ESLintReactSettings {
1957
2075
  additionalComponents: CustomComponentExpanded[];
1958
2076
  components: Map<string, string>;
1959
2077
  }
2078
+ /**
2079
+ * Defines the "react-x" settings in a type-safe way.
2080
+ * @param settings The settings.
2081
+ * @returns The ESLint settings containing the "react-x" object.
2082
+ */
2083
+ declare function defineSettings(settings: ESLintReactSettings): {
2084
+ importSource?: string | undefined;
2085
+ jsxPragma?: string | undefined;
2086
+ jsxPragmaFrag?: string | undefined;
2087
+ polymorphicPropName?: string | undefined;
2088
+ strict?: boolean | undefined;
2089
+ version?: string | undefined;
2090
+ additionalComponents?: {
2091
+ name: string;
2092
+ attributes: {
2093
+ name: string;
2094
+ as?: string | undefined;
2095
+ controlled?: boolean | undefined;
2096
+ defaultValue?: string | undefined;
2097
+ }[];
2098
+ as?: string | undefined;
2099
+ selector?: string | undefined;
2100
+ }[] | undefined;
2101
+ additionalHooks?: {
2102
+ use?: string[] | undefined;
2103
+ useActionState?: string[] | undefined;
2104
+ useCallback?: string[] | undefined;
2105
+ useContext?: string[] | undefined;
2106
+ useDebugValue?: string[] | undefined;
2107
+ useDeferredValue?: string[] | undefined;
2108
+ useEffect?: string[] | undefined;
2109
+ useId?: string[] | undefined;
2110
+ useImperativeHandle?: string[] | undefined;
2111
+ useInsertionEffect?: string[] | undefined;
2112
+ useLayoutEffect?: string[] | undefined;
2113
+ useMemo?: string[] | undefined;
2114
+ useOptimistic?: string[] | undefined;
2115
+ useReducer?: string[] | undefined;
2116
+ useRef?: string[] | undefined;
2117
+ useState?: string[] | undefined;
2118
+ useSyncExternalStore?: string[] | undefined;
2119
+ useTransition?: string[] | undefined;
2120
+ } | undefined;
2121
+ };
1960
2122
  /**
1961
2123
  * Decodes settings from a data object from `context.settings`.
2124
+ * @internal
1962
2125
  * @param data The data object.
1963
2126
  * @returns settings The settings.
1964
- * @internal
1965
2127
  */
1966
2128
  declare function decodeSettings(data: unknown): ESLintReactSettings;
1967
2129
  /**
@@ -1976,4 +2138,4 @@ declare const expandSettings: Memoized<(settings: ESLintReactSettings) => ESLint
1976
2138
  */
1977
2139
  declare const DEFAULT_ESLINT_REACT_SETTINGS: ESLintReactSettings;
1978
2140
 
1979
- export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentExpanded, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsExpanded, 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, expandSettings };
2141
+ export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentExpanded, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsExpanded, 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, expandSettings };
package/dist/index.d.ts CHANGED
@@ -60,6 +60,7 @@ declare const REACT_BUILD_IN_HOOKS: readonly ["useActionState", "useCallback", "
60
60
 
61
61
  /**
62
62
  * Get the ESLint rule creator for a plugin.
63
+ * @internal
63
64
  * @param pluginName The name of the plugin.
64
65
  * @returns The ESLint rule creator.
65
66
  */
@@ -1583,12 +1584,46 @@ declare const CustomComponentSchema: ObjectSchema<{
1583
1584
  * @internal
1584
1585
  */
1585
1586
  declare const ESLintReactSettingsSchema: ObjectSchema<{
1587
+ /**
1588
+ * The source where React is imported from.
1589
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1590
+ * @default `"react"`
1591
+ * @example `"@pika/react"`
1592
+ */
1586
1593
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1594
+ /**
1595
+ * The identifier that’s used for JSX Element creation.
1596
+ * @default `"createElement"`
1597
+ */
1587
1598
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1599
+ /**
1600
+ * The identifier that’s used for JSX fragment elements.
1601
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1602
+ * @default `"Fragment"`
1603
+ */
1588
1604
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1605
+ /**
1606
+ * The name of the prop that is used for polymorphic components.
1607
+ * @description This is used to determine the type of the component.
1608
+ * @example `"as"`
1609
+ */
1589
1610
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1611
+ /**
1612
+ * @internal
1613
+ */
1590
1614
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1615
+ /**
1616
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1617
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1618
+ * @example `"18.3.1"`
1619
+ * @default `"detect"`
1620
+ */
1591
1621
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1622
+ /**
1623
+ * An array of user-defined components
1624
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1625
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1626
+ */
1592
1627
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1593
1628
  /**
1594
1629
  * The name of the user-defined component.
@@ -1640,6 +1675,11 @@ declare const ESLintReactSettingsSchema: ObjectSchema<{
1640
1675
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1641
1676
  }, undefined>, undefined>, readonly []>;
1642
1677
  }, undefined>, undefined>, never>;
1678
+ /**
1679
+ * A object of aliases for React built-in hooks.
1680
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1681
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1682
+ */
1643
1683
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1644
1684
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1645
1685
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1666,12 +1706,46 @@ declare const ESLintReactSettingsSchema: ObjectSchema<{
1666
1706
  */
1667
1707
  declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1668
1708
  readonly "react-x": OptionalSchema<ObjectSchema<{
1709
+ /**
1710
+ * The source where React is imported from.
1711
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1712
+ * @default `"react"`
1713
+ * @example `"@pika/react"`
1714
+ */
1669
1715
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1716
+ /**
1717
+ * The identifier that’s used for JSX Element creation.
1718
+ * @default `"createElement"`
1719
+ */
1670
1720
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1721
+ /**
1722
+ * The identifier that’s used for JSX fragment elements.
1723
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1724
+ * @default `"Fragment"`
1725
+ */
1671
1726
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1727
+ /**
1728
+ * The name of the prop that is used for polymorphic components.
1729
+ * @description This is used to determine the type of the component.
1730
+ * @example `"as"`
1731
+ */
1672
1732
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1733
+ /**
1734
+ * @internal
1735
+ */
1673
1736
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1737
+ /**
1738
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1739
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1740
+ * @example `"18.3.1"`
1741
+ * @default `"detect"`
1742
+ */
1674
1743
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1744
+ /**
1745
+ * An array of user-defined components
1746
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1747
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1748
+ */
1675
1749
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1676
1750
  /**
1677
1751
  * The name of the user-defined component.
@@ -1723,6 +1797,11 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1723
1797
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1724
1798
  }, undefined>, undefined>, readonly []>;
1725
1799
  }, undefined>, undefined>, never>;
1800
+ /**
1801
+ * A object of aliases for React built-in hooks.
1802
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1803
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1804
+ */
1726
1805
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1727
1806
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1728
1807
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1749,12 +1828,46 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1749
1828
  * @deprecated
1750
1829
  */
1751
1830
  readonly reactOptions: OptionalSchema<ObjectSchema<{
1831
+ /**
1832
+ * The source where React is imported from.
1833
+ * @description This allows to specify a custom import location for React when not using the official distribution.
1834
+ * @default `"react"`
1835
+ * @example `"@pika/react"`
1836
+ */
1752
1837
  readonly importSource: OptionalSchema<StringSchema<undefined>, never>;
1838
+ /**
1839
+ * The identifier that’s used for JSX Element creation.
1840
+ * @default `"createElement"`
1841
+ */
1753
1842
  readonly jsxPragma: OptionalSchema<StringSchema<undefined>, never>;
1843
+ /**
1844
+ * The identifier that’s used for JSX fragment elements.
1845
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
1846
+ * @default `"Fragment"`
1847
+ */
1754
1848
  readonly jsxPragmaFrag: OptionalSchema<StringSchema<undefined>, never>;
1849
+ /**
1850
+ * The name of the prop that is used for polymorphic components.
1851
+ * @description This is used to determine the type of the component.
1852
+ * @example `"as"`
1853
+ */
1755
1854
  readonly polymorphicPropName: OptionalSchema<StringSchema<undefined>, never>;
1855
+ /**
1856
+ * @internal
1857
+ */
1756
1858
  readonly strict: OptionalSchema<BooleanSchema<undefined>, never>;
1859
+ /**
1860
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
1861
+ * If `importSource` is specified, an equivalent version of React should be provided here.
1862
+ * @example `"18.3.1"`
1863
+ * @default `"detect"`
1864
+ */
1757
1865
  readonly version: OptionalSchema<StringSchema<undefined>, never>;
1866
+ /**
1867
+ * An array of user-defined components
1868
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
1869
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
1870
+ */
1758
1871
  readonly additionalComponents: OptionalSchema<ArraySchema<ObjectSchema<{
1759
1872
  /**
1760
1873
  * The name of the user-defined component.
@@ -1806,6 +1919,11 @@ declare const ESLintSettingsSchema: OptionalSchema<ObjectSchema<{
1806
1919
  readonly defaultValue: OptionalSchema<StringSchema<undefined>, never>;
1807
1920
  }, undefined>, undefined>, readonly []>;
1808
1921
  }, undefined>, undefined>, never>;
1922
+ /**
1923
+ * A object of aliases for React built-in hooks.
1924
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
1925
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
1926
+ */
1809
1927
  readonly additionalHooks: OptionalSchema<ObjectSchema<{
1810
1928
  readonly use: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
1811
1929
  readonly useActionState: OptionalSchema<ArraySchema<StringSchema<undefined>, undefined>, never>;
@@ -1957,11 +2075,55 @@ interface ESLintReactSettingsExpanded extends ESLintReactSettings {
1957
2075
  additionalComponents: CustomComponentExpanded[];
1958
2076
  components: Map<string, string>;
1959
2077
  }
2078
+ /**
2079
+ * Defines the "react-x" settings in a type-safe way.
2080
+ * @param settings The settings.
2081
+ * @returns The ESLint settings containing the "react-x" object.
2082
+ */
2083
+ declare function defineSettings(settings: ESLintReactSettings): {
2084
+ importSource?: string | undefined;
2085
+ jsxPragma?: string | undefined;
2086
+ jsxPragmaFrag?: string | undefined;
2087
+ polymorphicPropName?: string | undefined;
2088
+ strict?: boolean | undefined;
2089
+ version?: string | undefined;
2090
+ additionalComponents?: {
2091
+ name: string;
2092
+ attributes: {
2093
+ name: string;
2094
+ as?: string | undefined;
2095
+ controlled?: boolean | undefined;
2096
+ defaultValue?: string | undefined;
2097
+ }[];
2098
+ as?: string | undefined;
2099
+ selector?: string | undefined;
2100
+ }[] | undefined;
2101
+ additionalHooks?: {
2102
+ use?: string[] | undefined;
2103
+ useActionState?: string[] | undefined;
2104
+ useCallback?: string[] | undefined;
2105
+ useContext?: string[] | undefined;
2106
+ useDebugValue?: string[] | undefined;
2107
+ useDeferredValue?: string[] | undefined;
2108
+ useEffect?: string[] | undefined;
2109
+ useId?: string[] | undefined;
2110
+ useImperativeHandle?: string[] | undefined;
2111
+ useInsertionEffect?: string[] | undefined;
2112
+ useLayoutEffect?: string[] | undefined;
2113
+ useMemo?: string[] | undefined;
2114
+ useOptimistic?: string[] | undefined;
2115
+ useReducer?: string[] | undefined;
2116
+ useRef?: string[] | undefined;
2117
+ useState?: string[] | undefined;
2118
+ useSyncExternalStore?: string[] | undefined;
2119
+ useTransition?: string[] | undefined;
2120
+ } | undefined;
2121
+ };
1960
2122
  /**
1961
2123
  * Decodes settings from a data object from `context.settings`.
2124
+ * @internal
1962
2125
  * @param data The data object.
1963
2126
  * @returns settings The settings.
1964
- * @internal
1965
2127
  */
1966
2128
  declare function decodeSettings(data: unknown): ESLintReactSettings;
1967
2129
  /**
@@ -1976,4 +2138,4 @@ declare const expandSettings: Memoized<(settings: ESLintReactSettings) => ESLint
1976
2138
  */
1977
2139
  declare const DEFAULT_ESLINT_REACT_SETTINGS: ESLintReactSettings;
1978
2140
 
1979
- export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentExpanded, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsExpanded, 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, expandSettings };
2141
+ export { type CustomAttribute, CustomAttributeSchema, type CustomComponent, type CustomComponentExpanded, CustomComponentSchema, type CustomHook, CustomHookSchema, DEFAULT_ESLINT_REACT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsExpanded, 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, expandSettings };
package/dist/index.js CHANGED
@@ -550,13 +550,52 @@ var CustomComponentSchema = object({
550
550
  attributes: optional(array(CustomAttributeSchema), [])
551
551
  });
552
552
  var ESLintReactSettingsSchema = object({
553
+ /**
554
+ * The source where React is imported from.
555
+ * @description This allows to specify a custom import location for React when not using the official distribution.
556
+ * @default `"react"`
557
+ * @example `"@pika/react"`
558
+ */
553
559
  importSource: optional(string()),
560
+ /**
561
+ * The identifier that’s used for JSX Element creation.
562
+ * @default `"createElement"`
563
+ */
554
564
  jsxPragma: optional(string()),
565
+ /**
566
+ * The identifier that’s used for JSX fragment elements.
567
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
568
+ * @default `"Fragment"`
569
+ */
555
570
  jsxPragmaFrag: optional(string()),
571
+ /**
572
+ * The name of the prop that is used for polymorphic components.
573
+ * @description This is used to determine the type of the component.
574
+ * @example `"as"`
575
+ */
556
576
  polymorphicPropName: optional(string()),
577
+ /**
578
+ * @internal
579
+ */
557
580
  strict: optional(boolean()),
581
+ /**
582
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
583
+ * If `importSource` is specified, an equivalent version of React should be provided here.
584
+ * @example `"18.3.1"`
585
+ * @default `"detect"`
586
+ */
558
587
  version: optional(string()),
588
+ /**
589
+ * An array of user-defined components
590
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
591
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
592
+ */
559
593
  additionalComponents: optional(array(CustomComponentSchema)),
594
+ /**
595
+ * A object of aliases for React built-in hooks.
596
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
597
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
598
+ */
560
599
  additionalHooks: optional(object({
561
600
  use: optional(array(string())),
562
601
  useActionState: optional(array(string())),
@@ -873,6 +912,9 @@ function createMemoizedFunction(fn, options) {
873
912
  memoized.options = normalizedOptions;
874
913
  return memoized;
875
914
  }
915
+ function defineSettings(settings) {
916
+ return parse(ESLintSettingsSchema, settings)["react-x"] ?? {};
917
+ }
876
918
  function decodeSettings(data) {
877
919
  return parse(ESLintSettingsSchema, data)["react-x"] ?? {};
878
920
  }
@@ -927,4 +969,5 @@ exports.RE_SNAKE_CASE = RE_SNAKE_CASE;
927
969
  exports.WEBSITE_URL = WEBSITE_URL;
928
970
  exports.createRuleForPlugin = createRuleForPlugin;
929
971
  exports.decodeSettings = decodeSettings;
972
+ exports.defineSettings = defineSettings;
930
973
  exports.expandSettings = expandSettings;
package/dist/index.mjs CHANGED
@@ -544,13 +544,52 @@ var CustomComponentSchema = object({
544
544
  attributes: optional(array(CustomAttributeSchema), [])
545
545
  });
546
546
  var ESLintReactSettingsSchema = object({
547
+ /**
548
+ * The source where React is imported from.
549
+ * @description This allows to specify a custom import location for React when not using the official distribution.
550
+ * @default `"react"`
551
+ * @example `"@pika/react"`
552
+ */
547
553
  importSource: optional(string()),
554
+ /**
555
+ * The identifier that’s used for JSX Element creation.
556
+ * @default `"createElement"`
557
+ */
548
558
  jsxPragma: optional(string()),
559
+ /**
560
+ * The identifier that’s used for JSX fragment elements.
561
+ * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
562
+ * @default `"Fragment"`
563
+ */
549
564
  jsxPragmaFrag: optional(string()),
565
+ /**
566
+ * The name of the prop that is used for polymorphic components.
567
+ * @description This is used to determine the type of the component.
568
+ * @example `"as"`
569
+ */
550
570
  polymorphicPropName: optional(string()),
571
+ /**
572
+ * @internal
573
+ */
551
574
  strict: optional(boolean()),
575
+ /**
576
+ * React version to use, "detect" means auto detect React version from the project’s dependencies.
577
+ * If `importSource` is specified, an equivalent version of React should be provided here.
578
+ * @example `"18.3.1"`
579
+ * @default `"detect"`
580
+ */
552
581
  version: optional(string()),
582
+ /**
583
+ * An array of user-defined components
584
+ * @description This is used to inform the ESLint React plugins how to treat these components during checks.
585
+ * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
586
+ */
553
587
  additionalComponents: optional(array(CustomComponentSchema)),
588
+ /**
589
+ * A object of aliases for React built-in hooks.
590
+ * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
591
+ * @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
592
+ */
554
593
  additionalHooks: optional(object({
555
594
  use: optional(array(string())),
556
595
  useActionState: optional(array(string())),
@@ -867,6 +906,9 @@ function createMemoizedFunction(fn, options) {
867
906
  memoized.options = normalizedOptions;
868
907
  return memoized;
869
908
  }
909
+ function defineSettings(settings) {
910
+ return parse(ESLintSettingsSchema, settings)["react-x"] ?? {};
911
+ }
870
912
  function decodeSettings(data) {
871
913
  return parse(ESLintSettingsSchema, data)["react-x"] ?? {};
872
914
  }
@@ -901,4 +943,4 @@ var DEFAULT_ESLINT_REACT_SETTINGS = {
901
943
  version: "detect"
902
944
  };
903
945
 
904
- export { CustomAttributeSchema, 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, expandSettings };
946
+ export { CustomAttributeSchema, 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, expandSettings };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "1.8.3-beta.1",
3
+ "version": "1.8.3-beta.3",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {