Skip to content

Commit d325f67

Browse files
committed
fix: false positive in 'react-x/no-context-provider' on components named 'Provider', closes #991
1 parent 3615541 commit d325f67

File tree

17 files changed

+51
-17
lines changed

17 files changed

+51
-17
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.34.0
1+
1.34.1-next.0

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/monorepo",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"private": true,
55
"description": "Monorepo for eslint-plugin-react-[x, dom, web-api, hooks-extra, naming-convention].",
66
"keywords": [

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/core",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/plugins/eslint-plugin-react-debug/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-debug",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint plugin for debugging related rules.",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-dom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-dom",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint plugin for React DOM related rules.",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-hooks-extra/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-hooks-extra",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-naming-convention/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-naming-convention",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint plugin for naming convention related rules.",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-web-api/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-web-api",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's ESLint plugin for interacting with Web APIs",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-x/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-x",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
55
"keywords": [
66
"react",

packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.spec.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import rule, { RULE_NAME } from "./no-context-provider";
66
ruleTester.run(RULE_NAME, rule, {
77
invalid: [
88
{
9-
code: tsx`<Provider />`,
9+
code: tsx`<context.Provider />`,
1010
errors: [
1111
{
1212
messageId: "noContextProvider",
@@ -101,6 +101,26 @@ ruleTester.run(RULE_NAME, rule, {
101101
},
102102
},
103103
},
104+
// TODO: Evaluate the necessity of supporting this kind of usage
105+
// {
106+
// code: tsx`
107+
// const Provider = Context.Provider;
108+
109+
// function Component() {
110+
// return <Provider>hello world</Provider>;
111+
// }
112+
// `,
113+
// errors: [
114+
// {
115+
// messageId: "noContextProvider",
116+
// },
117+
// ],
118+
// settings: {
119+
// "react-x": {
120+
// version: "19.0.0",
121+
// },
122+
// },
123+
// },
104124
],
105125
valid: [
106126
{
@@ -151,5 +171,19 @@ ruleTester.run(RULE_NAME, rule, {
151171
},
152172
},
153173
},
174+
{
175+
code: tsx`
176+
import { Provider } from "jotai";
177+
178+
function Component() {
179+
return <Provider>hello world</Provider>;
180+
}
181+
`,
182+
settings: {
183+
"react-x": {
184+
version: "19.0.0",
185+
},
186+
},
187+
},
154188
],
155189
});

packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4747
const contextFullName = parts.join(".");
4848
const contextSelfName = parts.pop();
4949
if (selfName !== "Provider") return;
50+
if (contextSelfName == null) return;
5051
context.report({
5152
messageId: "noContextProvider",
5253
node,
5354
fix(fixer) {
54-
if (contextSelfName == null) return null;
5555
if (!isComponentNameLoose(contextSelfName)) return null;
5656
const openingElement = node.openingElement;
5757
const closingElement = node.closingElement;

packages/plugins/eslint-plugin/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/eslint-plugin",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "More than 80 high-quality linting rules for writing better React code.",
55
"keywords": [
66
"react",

packages/shared/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/shared",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's Shared constants and functions.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/utilities/ast/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/ast",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's TSESTree AST utility module.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/utilities/eff/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/eff",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "JavaScript and TypeScript utilities (previously some re-exports of the effect library).",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/utilities/jsx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/jsx",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/utilities/var/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/var",
3-
"version": "1.34.0",
3+
"version": "1.34.1-next.0",
44
"description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

0 commit comments

Comments
 (0)