diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.mdx b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.mdx index 781a5896c..2164b5524 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.mdx +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.mdx @@ -34,7 +34,9 @@ Replaces usages of `` with ``. In React 19, you can render `` as a provider instead of ``. -In addition, it is recommended to enable the [`naming-convention/context-name`](./naming-convention-context-name) rule to enforce consistent naming conventions for contexts. + + This rule depends on the [`naming-convention/context-name`](./naming-convention-context-name) rule to identify context components. Make sure to enable that rule to ensure this rule works correctly. + ## Examples @@ -81,7 +83,7 @@ function App({ children }) { ## See Also -- [`no-forward-ref`](./no-forward-ref)\ - Replaces usages of `forwardRef` with passing `ref` as a prop. - [`no-use-context`](./no-use-context)\ Replaces usages of `useContext` with `use`. +- [`naming-convention/context-name`](./naming-convention-context-name)\ + Enforces consistent naming conventions for contexts. diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.spec.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.spec.ts index e287ed901..4b9e52471 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.spec.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.spec.ts @@ -5,19 +5,6 @@ import rule, { RULE_NAME } from "./no-context-provider"; ruleTester.run(RULE_NAME, rule, { invalid: [ - { - code: tsx``, - errors: [ - { - messageId: "noContextProvider", - }, - ], - settings: { - "react-x": { - version: "19.0.0", - }, - }, - }, { code: tsx``, errors: [ @@ -60,47 +47,6 @@ ruleTester.run(RULE_NAME, rule, { }, }, }, - { - code: tsx`{children}`, - errors: [ - { - messageId: "noContextProvider", - }, - ], - output: tsx`{children}`, - settings: { - "react-x": { - version: "19.0.0", - }, - }, - }, - { - code: tsx`{children}`, - errors: [ - { - messageId: "noContextProvider", - }, - ], - output: tsx`{children}`, - settings: { - "react-x": { - version: "19.0.0", - }, - }, - }, - { - code: tsx`{children}`, - errors: [ - { - messageId: "noContextProvider", - }, - ], - settings: { - "react-x": { - version: "19.0.0", - }, - }, - }, ], valid: [ { @@ -165,5 +111,19 @@ ruleTester.run(RULE_NAME, rule, { }, }, }, + { + code: tsx` + import { Tooltip } from '@base-ui-components/react/tooltip' + + function Component() { + return hello world; + } + `, + settings: { + "react-x": { + version: "19.0.0", + }, + }, + }, ], }); diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts index 33a119b87..3285d479c 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts @@ -49,8 +49,8 @@ export function create(context: RuleContext): RuleListener { const contextSelfName = parts.pop(); // Exit if the element is not a "Provider" if (selfName !== "Provider") return; - // Exit if there is no context name - if (contextSelfName == null) return; + // Exit if there is no context name or it doesn't end with "Context" + if (contextSelfName == null || !contextSelfName.endsWith("Context")) return; context.report({ messageId: "noContextProvider", node, diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.mdx b/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.mdx index 8a2a505d2..d51991ab1 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.mdx +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.mdx @@ -112,7 +112,3 @@ function MyInput({ - [`no-useless-forward-ref`](./no-useless-forward-ref)\ Enforces that `forwardRef` is only used when a `ref` parameter is declared. -- [`no-context-provider`](./no-context-provider)\ - Replaces usages of `` with ``. -- [`no-use-context`](./no-use-context)\ - Replaces usages of `useContext` with `use`. diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-use-context.mdx b/packages/plugins/eslint-plugin-react-x/src/rules/no-use-context.mdx index 0c500e644..1763b0745 100644 --- a/packages/plugins/eslint-plugin-react-x/src/rules/no-use-context.mdx +++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-use-context.mdx @@ -76,5 +76,5 @@ function Button() { - [`no-context-provider`](./no-context-provider)\ Replaces usages of `` with ``. -- [`no-forward-ref`](./no-forward-ref)\ - Replace usages of `forwardRef` with passing `ref` as a prop. +- [`naming-convention/context-name`](./naming-convention-context-name)\ + Enforces consistent naming conventions for contexts. diff --git a/packages/plugins/eslint-plugin/README.md b/packages/plugins/eslint-plugin/README.md index fcb6b6a91..438557d39 100644 --- a/packages/plugins/eslint-plugin/README.md +++ b/packages/plugins/eslint-plugin/README.md @@ -186,8 +186,8 @@ ESLint React is not affiliated with Meta Corporation or [facebook/react](https:/ Contributions are welcome! -Please follow our [contributing guidelines](https://github.com/Rel1cx/eslint-react/tree/main/.github/CONTRIBUTING.md). +Please follow our [contributing guidelines](https://github.com/Rel1cx/eslint-react/tree/no-context-provider/.github/CONTRIBUTING.md). ## License -This project is licensed under the MIT License - see the [LICENSE](https://github.com/Rel1cx/eslint-react/tree/main/LICENSE) file for details. +This project is licensed under the MIT License - see the [LICENSE](https://github.com/Rel1cx/eslint-react/tree/no-context-provider/LICENSE) file for details.