🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@eslint-react/shared

Package Overview
Dependencies
Maintainers
1
Versions
2648
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint-react/shared - npm Package Compare versions

Comparing version
5.17.3
to
5.18.0
+78
-62
dist/index.d.ts
import { z } from "zod/v4";
import { RuleContext } from "@eslint-react/eslint";
//#region src/regexp.d.ts
/**
* Regular expressions for matching a HTML tag name.
*/
/** Regular expression for matching an HTML tag name. */
declare const RE_HTML_TAG: RegExp;
/**
* Regular expression for matching a TypeScript file extension.
*/
/** Regular expression for matching a TypeScript file extension. */
declare const RE_TS_EXT: RegExp;
/**
* Regular expression for matching a JavaScript file extension.
*/
/** Regular expression for matching a JavaScript file extension. */
declare const RE_JS_EXT: RegExp;
/**
* Regular expression for matching a PascalCase string.
*/
/** Regular expression for matching a PascalCase string. */
declare const RE_PASCAL_CASE: RegExp;
/**
* Regular expression for matching a camelCase string.
*/
/** Regular expression for matching a camelCase string. */
declare const RE_CAMEL_CASE: RegExp;
/**
* Regular expression for matching a kebab-case string.
*/
/** Regular expression for matching a kebab-case string. */
declare const RE_KEBAB_CASE: RegExp;
/**
* Regular expression for matching a snake_case string.
*/
/** Regular expression for matching a snake_case string. */
declare const RE_SNAKE_CASE: RegExp;
/** Regular expression for matching a CONSTANT_CASE string. */
declare const RE_CONSTANT_CASE: RegExp;
/**
* Regular expression for matching a CONSTANT_CASE string.
* Regular expression for matching the `javascript:` protocol.
* @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
*/
declare const RE_CONSTANT_CASE: RegExp;
declare const RE_JAVASCRIPT_PROTOCOL: RegExp;
/**
* Regular expression for matching a valid JavaScript identifier.
*/
/** Regular expression for matching a valid JavaScript identifier. */
declare const RE_JS_IDENTIFIER: RegExp;
/**
* Regular expression for matching a RegExp string.
*/
/** Regular expression for matching a RegExp string. */
declare const RE_REGEXP_STR: RegExp;
/**
* Regular expression for matching a `@jsx` annotation comment.
*/
/** Regular expression for matching a `@jsx` annotation comment. */
declare const RE_ANNOTATION_JSX: RegExp;
/**
* Regular expression for matching a `@jsxFrag` annotation comment.
*/
/** Regular expression for matching a `@jsxFrag` annotation comment. */
declare const RE_ANNOTATION_JSX_FRAG: RegExp;
/**
* Regular expression for matching a `@jsxRuntime` annotation comment.
*/
/** Regular expression for matching a `@jsxRuntime` annotation comment. */
declare const RE_ANNOTATION_JSX_RUNTIME: RegExp;
/**
* Regular expression for matching a `@jsxImportSource` annotation comment.
*/
/** Regular expression for matching a `@jsxImportSource` annotation comment. */
declare const RE_ANNOTATION_JSX_IMPORT_SOURCE: RegExp;
/**
* Regular expression for matching a React component name.
*/
/** Regular expression for matching a React component name. */
declare const RE_COMPONENT_NAME: RegExp;
/**
* Regular expression for matching a React component name (loose).
*/
/** Regular expression for matching a React component name (loose). */
declare const RE_COMPONENT_NAME_LOOSE: RegExp;
/**
* Regular expression for matching a React Hook name.
*/
/** Regular expression for matching a React Hook name. */
declare const RE_HOOK_NAME: RegExp;
/**
* A type represents RegExp-like object with `test` method.
*/
/** Represents a RegExp-like object with a `test` method. */
type RegExpLike = {

@@ -80,14 +48,15 @@ test: (s: string) => boolean;

/**
* Convert a string to the `RegExp`.
* Normal strings (ex: `"foo"`) is converted to `/^foo$/` of `RegExp`.
* Strings like `"/^foo/i"` are converted to `/^foo/i` of `RegExp`.
* Convert a string to a `RegExpLike` object.
*
* Normal strings (ex: `"foo"`) are converted to `/^foo$/`.
* RegExp strings (ex: `"/^foo/i"`) are converted to `/^foo/i`.
* @param string The string to convert.
* @returns The converted `RegExpLike` object.
* @see https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/utils/regexp.ts
* @param string The string to convert.
* @returns Returns the `RegExp`.
*/
declare function toRegExp(string: string | null | undefined): RegExpLike;
/**
* Check whether given string is regexp string.
* Check if the string is a RegExp string.
* @param string The string to check.
* @returns boolean.
* @returns `true` if the string is a RegExp string.
*/

@@ -98,2 +67,3 @@ declare function isRegExp(string: string): boolean;

/**
* The zod schema for the ESLint React settings.
* @internal

@@ -111,2 +81,3 @@ */

version: z.ZodOptional<z.ZodString>;
additionalRefHooks: z.ZodOptional<z.ZodString>;
additionalStateHooks: z.ZodOptional<z.ZodString>;

@@ -116,2 +87,3 @@ additionalEffectHooks: z.ZodOptional<z.ZodString>;

/**
* The zod schema for the ESLint settings.
* @internal

@@ -122,12 +94,24 @@ */

}, z.core.$strip>>;
/** The ESLint settings inferred from `ESLintSettingsSchema`. */
type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
/** The ESLint React settings inferred from `ESLintReactSettingsSchema`. */
type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
/** Represents the normalized ESLint React settings used by rules. */
interface ESLintReactSettingsNormalized {
/** The React version. */
version: string;
/** The source where React is imported from. */
importSource: string;
/** The React Compiler compilation mode, or "off" when not used. */
compilationMode: ESLintReactSettings["compilationMode"] | "off";
/** The prop name used for polymorphic components. */
polymorphicPropName: string | null;
/** Regex pattern matching custom hooks that should be treated as ref hooks. */
additionalRefHooks: RegExpLike;
/** Regex pattern matching custom hooks that should be treated as state hooks. */
additionalStateHooks: RegExpLike;
/** Regex pattern matching custom hooks that should be treated as effect hooks. */
additionalEffectHooks: RegExpLike;
}
/** The default ESLint React settings. */
declare const DEFAULT_ESLINT_REACT_SETTINGS: {

@@ -138,2 +122,3 @@ readonly version: "detect";

};
/** The default ESLint settings. */
declare const DEFAULT_ESLINT_SETTINGS: {

@@ -146,7 +131,32 @@ readonly "react-x": {

};
/**
* Check if the value is valid ESLint settings.
* @param settings The value to check.
* @returns `true` if the value is valid ESLint settings.
*/
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
/**
* Check if the value is valid ESLint React settings.
* @param settings The value to check.
* @returns `true` if the value is valid ESLint React settings.
*/
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
/**
* Decode the ESLint settings, falling back to the defaults when invalid.
* @param settings The value to decode.
* @returns The decoded ESLint settings.
*/
declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
/**
* Decode the ESLint React settings, falling back to the defaults when invalid.
* @param settings The value to decode.
* @returns The decoded ESLint React settings.
*/
declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
declare const normalizeSettings: ({ importSource, compilationMode, polymorphicPropName, version, additionalStateHooks, additionalEffectHooks, ...rest }: ESLintReactSettings) => {
/**
* Normalize the ESLint React settings to the form used by rules.
* @param settings The ESLint React settings to normalize.
* @returns The normalized ESLint React settings.
*/
declare const normalizeSettings: ({ importSource, compilationMode, polymorphicPropName, version, additionalRefHooks, additionalStateHooks, additionalEffectHooks, ...rest }: ESLintReactSettings) => {
readonly importSource: string;

@@ -156,2 +166,3 @@ readonly compilationMode: "infer" | "annotation" | "syntax" | "all" | "off";

readonly version: string;
readonly additionalRefHooks: RegExpLike;
readonly additionalStateHooks: RegExpLike;

@@ -161,3 +172,3 @@ readonly additionalEffectHooks: RegExpLike;

/**
* Gets the React version from the project's dependencies.
* Get the React version from the project's dependencies.
* @param fallback The fallback version to return if React is not found.

@@ -167,2 +178,7 @@ * @returns The detected React version or the fallback version.

declare function getReactVersion(fallback: string): string;
/**
* Get the normalized ESLint React settings from the rule context.
* @param context The rule context.
* @returns The normalized ESLint React settings.
*/
declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;

@@ -169,0 +185,0 @@ declare module "@typescript-eslint/utils/ts-eslint" {

@@ -487,78 +487,49 @@ import module from "node:module";

//#region src/regexp.ts
/**
* Regular expressions for matching a HTML tag name.
*/
/** Regular expression for matching an HTML tag name. */
const RE_HTML_TAG = /^[a-z][^-]*$/u;
/**
* Regular expression for matching a TypeScript file extension.
*/
/** Regular expression for matching a TypeScript file extension. */
const RE_TS_EXT = /^[cm]?tsx?$/u;
/**
* Regular expression for matching a JavaScript file extension.
*/
/** Regular expression for matching a JavaScript file extension. */
const RE_JS_EXT = /^[cm]?jsx?$/u;
/**
* Regular expression for matching a PascalCase string.
*/
/** Regular expression for matching a PascalCase string. */
const RE_PASCAL_CASE = /^[A-Z][\dA-Za-z]*$/u;
/**
* Regular expression for matching a camelCase string.
*/
/** Regular expression for matching a camelCase string. */
const RE_CAMEL_CASE = /^[a-z][\dA-Za-z]*$/u;
/**
* Regular expression for matching a kebab-case string.
*/
/** Regular expression for matching a kebab-case string. */
const RE_KEBAB_CASE = /^[a-z][\d\-a-z]*$/u;
/**
* Regular expression for matching a snake_case string.
*/
/** Regular expression for matching a snake_case string. */
const RE_SNAKE_CASE = /^[a-z][\d_a-z]*$/u;
/** Regular expression for matching a CONSTANT_CASE string. */
const RE_CONSTANT_CASE = /^[A-Z][\d_A-Z]*$/u;
/**
* Regular expression for matching a CONSTANT_CASE string.
* Regular expression for matching the `javascript:` protocol.
* @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
*/
const RE_CONSTANT_CASE = /^[A-Z][\d_A-Z]*$/u;
const RE_JAVASCRIPT_PROTOCOL = /^[\u0000-\u001F ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\r]*s[\t\n\r]*c[\t\n\r]*r[\t\n\r]*i[\t\n\r]*p[\t\n\r]*t[\t\n\r]*:/iu;
/**
* Regular expression for matching a valid JavaScript identifier.
*/
/** Regular expression for matching a valid JavaScript identifier. */
const RE_JS_IDENTIFIER = /^[_$a-z][\w$]*$/i;
/**
* Regular expression for matching a RegExp string.
*/
/** Regular expression for matching a RegExp string. */
const RE_REGEXP_STR = /^\/(.+)\/([A-Za-z]*)$/u;
/**
* Regular expression for matching a `@jsx` annotation comment.
*/
/** Regular expression for matching a `@jsx` annotation comment. */
const RE_ANNOTATION_JSX = /@jsx\s+(\S+)/u;
/**
* Regular expression for matching a `@jsxFrag` annotation comment.
*/
/** Regular expression for matching a `@jsxFrag` annotation comment. */
const RE_ANNOTATION_JSX_FRAG = /@jsxFrag\s+(\S+)/u;
/**
* Regular expression for matching a `@jsxRuntime` annotation comment.
*/
/** Regular expression for matching a `@jsxRuntime` annotation comment. */
const RE_ANNOTATION_JSX_RUNTIME = /@jsxRuntime\s+(\S+)/u;
/**
* Regular expression for matching a `@jsxImportSource` annotation comment.
*/
/** Regular expression for matching a `@jsxImportSource` annotation comment. */
const RE_ANNOTATION_JSX_IMPORT_SOURCE = /@jsxImportSource\s+(\S+)/u;
/**
* Regular expression for matching a React component name.
*/
/** Regular expression for matching a React component name. */
const RE_COMPONENT_NAME = /^[A-Z]/u;
/**
* Regular expression for matching a React component name (loose).
*/
/** Regular expression for matching a React component name (loose). */
const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
/**
* Regular expression for matching a React Hook name.
*/
/** Regular expression for matching a React Hook name. */
const RE_HOOK_NAME = /^use/u;
/**
* Convert a string to the `RegExp`.
* Normal strings (ex: `"foo"`) is converted to `/^foo$/` of `RegExp`.
* Strings like `"/^foo/i"` are converted to `/^foo/i` of `RegExp`.
* Convert a string to a `RegExpLike` object.
*
* Normal strings (ex: `"foo"`) are converted to `/^foo$/`.
* RegExp strings (ex: `"/^foo/i"`) are converted to `/^foo/i`.
* @param string The string to convert.
* @returns The converted `RegExpLike` object.
* @see https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/utils/regexp.ts
* @param string The string to convert.
* @returns Returns the `RegExp`.
*/

@@ -572,5 +543,5 @@ function toRegExp(string) {

/**
* Check whether given string is regexp string.
* Check if the string is a RegExp string.
* @param string The string to check.
* @returns boolean.
* @returns `true` if the string is a RegExp string.
*/

@@ -584,2 +555,3 @@ function isRegExp(string) {

/**
* The zod schema for the ESLint React settings.
* @internal

@@ -589,3 +561,3 @@ */

/**
* The source where React is imported from
* The source where React is imported from.
* Allows specifying a custom import location for React.

@@ -597,3 +569,3 @@ * @default "react"

/**
* The React Compiler compilationMode that the project is using
* The React Compiler compilationMode that the project is using.
* Used to inform the rule about how components and hooks will be picked up by the compiler.

@@ -609,3 +581,3 @@ * @example "infer"

/**
* The prop name used for polymorphic components
* The prop name used for polymorphic components.
* Used to determine the component's type.

@@ -616,3 +588,3 @@ * @example "as"

/**
* React version to use
* React version to use.
* "detect" means auto-detect React version from project dependencies.

@@ -624,2 +596,7 @@ * @example "18.3.1"

/**
* Regex pattern matching custom hooks that should be treated as ref hooks.
* @example "useMyRef|useCustomRef"
*/
additionalRefHooks: z.optional(z.string()),
/**
* Regex pattern matching custom hooks that should be treated as state hooks.

@@ -636,5 +613,7 @@ * @example "useMyState|useCustomState"

/**
* The zod schema for the ESLint settings.
* @internal
*/
const ESLintSettingsSchema = z.optional(z.object({ "react-x": z.optional(z.unknown()) }));
/** The default ESLint React settings. */
const DEFAULT_ESLINT_REACT_SETTINGS = {

@@ -645,9 +624,25 @@ version: "detect",

};
/** The default ESLint settings. */
const DEFAULT_ESLINT_SETTINGS = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
/**
* Check if the value is valid ESLint settings.
* @param settings The value to check.
* @returns `true` if the value is valid ESLint settings.
*/
function isESLintSettings(settings) {
return ESLintSettingsSchema.safeParse(settings).success;
}
/**
* Check if the value is valid ESLint React settings.
* @param settings The value to check.
* @returns `true` if the value is valid ESLint React settings.
*/
function isESLintReactSettings(settings) {
return ESLintReactSettingsSchema.safeParse(settings).success;
}
/**
* Decode the ESLint settings, falling back to the defaults when invalid.
* @param settings The value to decode.
* @returns The decoded ESLint settings.
*/
const decodeESLintSettings = (settings) => {

@@ -657,2 +652,7 @@ if (isESLintSettings(settings)) return settings;

};
/**
* Decode the ESLint React settings, falling back to the defaults when invalid.
* @param settings The value to decode.
* @returns The decoded ESLint React settings.
*/
const decodeSettings = (settings) => {

@@ -662,3 +662,8 @@ if (isESLintReactSettings(settings)) return settings;

};
const normalizeSettings = ({ importSource = "react", compilationMode, polymorphicPropName = "as", version, additionalStateHooks, additionalEffectHooks, ...rest }) => {
/**
* Normalize the ESLint React settings to the form used by rules.
* @param settings The ESLint React settings to normalize.
* @returns The normalized ESLint React settings.
*/
const normalizeSettings = ({ importSource = "react", compilationMode, polymorphicPropName = "as", version, additionalRefHooks, additionalStateHooks, additionalEffectHooks, ...rest }) => {
return {

@@ -670,2 +675,3 @@ ...rest,

version: match(version).with(P.union(P.nullish, "", "detect"), () => getReactVersion("19.2.7")).otherwise(identity),
additionalRefHooks: toRegExp(additionalRefHooks),
additionalStateHooks: toRegExp(additionalStateHooks),

@@ -677,3 +683,3 @@ additionalEffectHooks: toRegExp(additionalEffectHooks)

/**
* Gets the React version from the project's dependencies.
* Get the React version from the project's dependencies.
* @param fallback The fallback version to return if React is not found.

@@ -689,2 +695,7 @@ * @returns The detected React version or the fallback version.

}
/**
* Get the normalized ESLint React settings from the rule context.
* @param context The rule context.
* @returns The normalized ESLint React settings.
*/
function getSettingsFromContext(context) {

@@ -691,0 +702,0 @@ const settings = context.settings["react-x"];

{
"name": "@eslint-react/shared",
"version": "5.17.3",
"version": "5.18.0",
"description": "ESLint React's Shared constants and functions.",

@@ -32,6 +32,6 @@ "homepage": "https://github.com/Rel1cx/eslint-react",

"dependencies": {
"@typescript-eslint/utils": "^8.64.0",
"@typescript-eslint/utils": "^8.65.0",
"ts-pattern": "^5.9.0",
"zod": "^3.25.0 || ^4.0.0",
"@eslint-react/eslint": "5.17.3"
"@eslint-react/eslint": "5.18.0"
},

@@ -43,3 +43,3 @@ "devDependencies": {

"eslint": "^10.7.0",
"tsdown": "^0.22.9",
"tsdown": "^0.22.13",
"typescript": "6.0.3",

@@ -46,0 +46,0 @@ "@local/configs": "0.0.0",