@@ -2,7 +2,7 @@ import { E, F } from "@eslint-react/eff";
22import pm from "picomatch" ;
33import { match , P } from "ts-pattern" ;
44import type { PartialDeep } from "type-fest" ;
5- import { parse } from "valibot" ;
5+ import { assert } from "valibot" ;
66
77import { normalizedSettingsCache } from "./cache" ;
88import { getReactVersion } from "./get-react-version" ;
@@ -22,30 +22,18 @@ export const DEFAULT_ESLINT_REACT_SETTINGS = {
2222} as const satisfies ESLintReactSettings ;
2323
2424/**
25- * Unsafely casts settings from a data object from ` context.settings` .
26- * @internal
27- * @param data The data object .
28- * @returns settings The settings.
25+ * Get the normalized ESLint settings for "react-x" from the given context.
26+ * @param context The context.
27+ * @param context.settings The ESLint settings .
28+ * @returns The normalized ESLint settings.
2929 */
30- export function unsafeReadSettings ( data : unknown ) : PartialDeep < ESLintReactSettings > {
31- // @ts -expect-error - skip type checking for unsafe cast
32- // eslint-disable-next-line @susisu/safe-typescript/no-type-assertion
33- return ( data ?. [ "react-x" ] ?? { } ) as PartialDeep < ESLintReactSettings > ;
34- }
35-
36- /**
37- * Normalizes the settings by converting all shorthand properties to their full form.
38- * @param data The raw settings.
39- * @returns The normalized settings.
40- * @internal
41- */
42- export function normalizeSettings ( data : unknown ) : ESLintReactSettingsNormalized {
43- const memoized = normalizedSettingsCache . get ( data ) ;
30+ export function getSettingsFromContext ( context : { settings : unknown } ) : ESLintReactSettingsNormalized {
31+ const memoized = normalizedSettingsCache . get ( context . settings ) ;
4432 if ( memoized ) return memoized ;
45-
33+ assert ( ESLintSettingsSchema , context . settings ) ;
4634 const settings = {
4735 ...DEFAULT_ESLINT_REACT_SETTINGS ,
48- ...parse ( ESLintSettingsSchema , data ) [ "react-x" ] ?? { } ,
36+ ...context . settings ?. [ "react-x" ] ,
4937 } ;
5038 const additionalComponents = settings . additionalComponents ?? [ ] ;
5139 const normalized = {
@@ -68,14 +56,10 @@ export function normalizeSettings(data: unknown): ESLintReactSettingsNormalized
6856 . with ( P . union ( P . nullish , "" , "detect" ) , ( ) => E . getOrElse ( getReactVersion ( ) , F . constant ( "19.0.0" ) ) )
6957 . otherwise ( F . identity ) ,
7058 } ;
71- normalizedSettingsCache . set ( data , normalized ) ;
59+ normalizedSettingsCache . set ( settings , normalized ) ;
7260 return normalized ;
7361}
7462
75- export function getSettingsFromContext ( context : { settings : unknown } ) : ESLintReactSettingsNormalized {
76- return normalizeSettings ( context . settings ) ;
77- }
78-
7963/**
8064 * A helper function to define settings for "react-x" with type checking in JavaScript files.
8165 * @param settings The settings.
0 commit comments