Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/dual-react-dom-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@eslint/js": "^9.17.0",
"@tsconfig/node22": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^22.10.4",
"@types/node": "^22.10.5",
"@types/react": "^19.0.2",
"eslint": "^9.17.0",
"eslint-plugin-react-hooks": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
},
"devDependencies": {
"@eslint-react/eslint-plugin": "^1.23.1",
"@eslint/config-inspector": "^0.6.0",
"@eslint/config-inspector": "^0.7.0",
"@eslint/js": "^9.17.0",
"@next/eslint-plugin-next": "^15.1.3",
"@types/negotiator": "^0.6.3",
"@types/node": "^22.10.4",
"@types/node": "^22.10.5",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"autoprefixer": "10.4.20",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-react-dom-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@eslint-react/eslint-plugin": "^1.23.1",
"@eslint/config-inspector": "^0.6.0",
"@eslint/config-inspector": "^0.7.0",
"@eslint/js": "^9.17.0",
"@tsconfig/node22": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-react-dom-js-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@eslint-react/eslint-plugin": "^1.23.1",
"@eslint/config-inspector": "^0.6.0",
"@eslint/config-inspector": "^0.7.0",
"@eslint/js": "^9.17.0",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-react-dom-js-with-babel-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.26.3",
"@eslint-react/eslint-plugin": "^1.23.1",
"@eslint/config-inspector": "^0.6.0",
"@eslint/config-inspector": "^0.7.0",
"@eslint/js": "^9.17.0",
"@types/babel__core": "~7.20.5",
"@types/babel__preset-env": "~7.9.7",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
"@effect/platform-bun": "^0.52.0",
"@effect/platform-node": "^0.68.0",
"@effect/schema": "^0.75.5",
"@eslint/config-inspector": "^0.6.0",
"@eslint/config-inspector": "^0.7.0",
"@eslint/js": "^9.17.0",
"@swc/core": "^1.10.4",
"@tsconfig/node22": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^22.10.4",
"@types/node": "^22.10.5",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@typescript-eslint/parser": "^8.19.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/element/get-element-represent-name.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { F, isString, O } from "@eslint-react/eff";
import * as JSX from "@eslint-react/jsx";
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleContext } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/types";

export function getElementRepresentName(node: TSESTree.JSXOpeningElement, context: RuleContext) {
const rawElementName = JSX.getElementName(node);
if (rawElementName === rawElementName.toLowerCase()) return rawElementName;
const { components, polymorphicPropName } = normalizeSettings(decodeSettings(context.settings));
const { components, polymorphicPropName } = getSettingsFromContext(context);
const asElementName = components.get(rawElementName);
if (isString(asElementName)) return asElementName;
return F.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isInitializedFromReact } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import type { Scope } from "@typescript-eslint/scope-manager";
import type { TSESTree } from "@typescript-eslint/utils";
Expand Down Expand Up @@ -33,7 +33,7 @@ export default createRule<[], MessageID>({
},
name: RULE_NAME,
create(context) {
const settings = decodeSettings(context.settings);
const settings = getSettingsFromContext(context);
const finalSettings = {
...settings,
strictImportCheck: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Ported from https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/no-unknown-property.js
// TODO: Port to TypeScript

import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import { createRule } from "../utils";
import { compare, compareVersions } from "compare-versions";
import type { RuleFeature } from "@eslint-react/types";
Expand Down Expand Up @@ -1203,6 +1203,6 @@ function report(context, message, messageId, data) {
}

function testReactVersion(context, comparator, version) {
const { version: localVersion } = normalizeSettings(decodeSettings(context.settings));
const { version: localVersion } = getSettingsFromContext(context);
return compare(localVersion, version, comparator);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getElementRepresentName } from "@eslint-react/core";
import { F, isString, O } from "@eslint-react/eff";
import * as JSX from "@eslint-react/jsx";
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/utils";
import type { ReportDescriptor } from "@typescript-eslint/utils/ts-eslint";
Expand Down Expand Up @@ -44,7 +44,7 @@ export default createRule<[], MessageID>({
},
name: RULE_NAME,
create(context) {
const settings = normalizeSettings(decodeSettings(context.settings));
const settings = getSettingsFromContext(context);
const additionalComponents = settings.additionalComponents.filter(c => c.as === "a");
function getReportDescriptor(node: TSESTree.JSXElement): O.Option<ReportDescriptor<MessageID>> {
const name = JSX.getElementName(node.openingElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AST from "@eslint-react/ast";
import { isReactHookCallWithNameAlias } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import * as VAR from "@eslint-react/var";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
Expand Down Expand Up @@ -43,7 +43,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
const settings = decodeSettings(context.settings);
const settings = getSettingsFromContext(context);
const additionalHooks = settings.additionalHooks ?? {};

const isUseEffectLikeCall = isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AST from "@eslint-react/ast";
import { isReactHookCallWithNameAlias } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import * as VAR from "@eslint-react/var";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
Expand Down Expand Up @@ -44,7 +44,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
const settings = decodeSettings(context.settings);
const settings = getSettingsFromContext(context);
const additionalHooks = settings.additionalHooks ?? {};

const isUseLayoutEffectLikeCall = isReactHookCallWithNameAlias(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AST from "@eslint-react/ast";
import { isReactHookCall, isReactHookCallWithNameLoose, isUseCallbackCall } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import * as VAR from "@eslint-react/var";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
Expand Down Expand Up @@ -34,7 +34,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!context.sourceCode.text.includes("use")) return {};
const alias = decodeSettings(context.settings).additionalHooks?.useCallback ?? [];
const alias = getSettingsFromContext(context).additionalHooks?.useCallback ?? [];
return {
CallExpression(node) {
if (!isReactHookCall(node)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AST from "@eslint-react/ast";
import { isReactHookCall, isReactHookCallWithNameLoose, isUseMemoCall } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import * as VAR from "@eslint-react/var";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
Expand Down Expand Up @@ -33,7 +33,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!context.sourceCode.text.includes("use")) return {};
const alias = decodeSettings(context.settings).additionalHooks?.useMemo ?? [];
const alias = getSettingsFromContext(context).additionalHooks?.useMemo ?? [];
return {
CallExpression(node) {
if (!isReactHookCall(node)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Ported from https://github.com/jsx-eslint/eslint-plugin-react/pull/3579/commits/ebb739a0fe99a2ee77055870bfda9f67a2691374
import * as AST from "@eslint-react/ast";
import { isReactHookCall, isReactHookCallWithNameLoose, isUseStateCall } from "@eslint-react/core";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import type { CamelCase } from "string-ts";

Expand Down Expand Up @@ -35,7 +35,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!context.sourceCode.text.includes("use")) return {};
const alias = decodeSettings(context.settings).additionalHooks?.useState ?? [];
const alias = getSettingsFromContext(context).additionalHooks?.useState ?? [];
return {
CallExpression(node) {
if (!isReactHookCall(node)) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isReactHookCallWithNameLoose, isUseStateCall, useComponentCollector } from "@eslint-react/core";
import { F, O } from "@eslint-react/eff";
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
import type { ReportDescriptor } from "@typescript-eslint/utils/ts-eslint";
Expand Down Expand Up @@ -39,7 +39,7 @@ export default createRule<[], MessageID>({
},
name: RULE_NAME,
create(context) {
const alias = decodeSettings(context.settings).additionalHooks?.useState ?? [];
const alias = getSettingsFromContext(context).additionalHooks?.useState ?? [];
const { ctx, listeners } = useComponentCollector(context);

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as JSX from "@eslint-react/jsx";
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import { compare } from "compare-versions";
import type { CamelCase } from "string-ts";
Expand Down Expand Up @@ -31,7 +31,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!context.sourceCode.text.includes(".Provider")) return {};
const { version } = normalizeSettings(decodeSettings(context.settings));
const { version } = getSettingsFromContext(context);
if (compare(version, "19.0.0", "<")) return {};
return {
JSXElement(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as AST from "@eslint-react/ast";
import { isForwardRefCall } from "@eslint-react/core";
import { O } from "@eslint-react/eff";
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleContext, RuleFeature } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/types";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
Expand Down Expand Up @@ -37,7 +37,7 @@ export default createRule<[], MessageID>({
name: RULE_NAME,
create(context) {
if (!context.sourceCode.text.includes("forwardRef")) return {};
const { version } = normalizeSettings(decodeSettings(context.settings));
const { version } = getSettingsFromContext(context);
if (compare(version, "19.0.0", "<")) return {};
return {
CallExpression(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as AST from "@eslint-react/ast";
import { F, O } from "@eslint-react/eff";
import { decodeSettings, normalizeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import * as VAR from "@eslint-react/var";
import type { Variable } from "@typescript-eslint/scope-manager";
Expand Down Expand Up @@ -218,7 +218,7 @@ export default createRule<[], MessageID>({
create(context) {
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) return {};

const { version } = normalizeSettings(decodeSettings(context.settings));
const { version } = getSettingsFromContext(context);

// Allowed left node type variants
const allowedVariants = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeSettings } from "@eslint-react/shared";
import { getSettingsFromContext } from "@eslint-react/shared";
import type { RuleFeature } from "@eslint-react/types";
import type { TSESTree } from "@typescript-eslint/types";
import type { CamelCase } from "string-ts";
Expand Down Expand Up @@ -29,7 +29,7 @@ export default createRule<[], MessageID>({
},
name: RULE_NAME,
create(context) {
const importSource = decodeSettings(context.settings).importSource ?? "react";
const importSource = getSettingsFromContext(context).importSource ?? "react";
return {
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](
node: TSESTree.ImportDefaultSpecifier,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@

- [defineSettings](functions/defineSettings.md)
- [getReactVersion](functions/getReactVersion.md)
- [getSettingsFromContext](functions/getSettingsFromContext.md)
21 changes: 21 additions & 0 deletions packages/shared/docs/functions/getSettingsFromContext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[**@eslint-react/shared**](../README.md)

***

[@eslint-react/shared](../README.md) / getSettingsFromContext

# Function: getSettingsFromContext()

> **getSettingsFromContext**(`context`): `ESLintReactSettingsNormalized`

## Parameters

### context

#### settings

`unknown`

## Returns

`ESLintReactSettingsNormalized`
2 changes: 0 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
"dependencies": {
"@eslint-react/eff": "workspace:*",
"@typescript-eslint/utils": "^8.19.0",
"fast-equals": "^5.0.1",
"micro-memoize": "^4.1.2",
"picomatch": "^4.0.2",
"ts-pattern": "^5.6.0",
"valibot": "^1.0.0-beta.9"
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { ESLintReactSettingsNormalized } from "./schemas";

export const normalizedSettingsCache = new Map<unknown, ESLintReactSettingsNormalized>();
Loading
Loading