Is there an existing issue for this?
Description Overview
Hi team, thanks for your work on this lib 🙏
Using react/no-danger rule with option ['error', { customComponentNames: ['*'] }] cause a command-line error.
Documentation about it: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger.md
Here is how I use the rule in my eslint configuration:
'react/no-danger': ['error', { customComponentNames: ['*'] }],
When I run eslint ./src on my project, an error occurred (only using customComponentNames option):
❯ eslint ./src
Oops! Something went wrong! :(
ESLint: 8.57.0
TypeError: Cannot read properties of undefined (reading 'split')
Occurred while linting /Users/sylvain/react-app/src/App.tsx:74
Rule: "react/no-danger"
at Minimatch.match (/Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/minimatch/minimatch.js:743:9)
at minimatch (/Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/minimatch/minimatch.js:125:42)
at /Users/sylvain/react-app/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react/lib/rules/no-danger.js:82:83
at Array.some (<anonymous>)
at JSXAttribute (/Users/sylvain/react-app/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react/lib/rules/no-danger.js:82:68)
at ruleErrorHandler (/Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28)
at /Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/sylvain/react-app/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
/Users/sylvain/react-app:
Exit status 2
This error is triggered by this line
|
const enableCheckingCustomComponent = customComponentNames.some((name) => minimatch(functionName, name)); |
Actually I don't know why, but sometimes functionName is undefined
|
const functionName = node.parent.name.name; |
Expected Behavior
Locally I patched eslint-plugin-react like this:
diff --git a/lib/rules/no-danger.js b/lib/rules/no-danger.js
index fb702632082068b08954ebb849d0994da6fac5b6..be0f82185cd9bc8358f29f5a19104ad3343996d7 100644
--- a/lib/rules/no-danger.js
+++ b/lib/rules/no-danger.js
@@ -77,10 +77,9 @@ module.exports = {
return {
JSXAttribute(node) {
- const functionName = node.parent.name.name;
-
- const enableCheckingCustomComponent = customComponentNames.some((name) => minimatch(functionName, name));
+ const functionName = node.parent.name.name ?? '';
+ const enableCheckingCustomComponent = customComponentNames.some((name) => name === '*' || minimatch(functionName, name));
if ((enableCheckingCustomComponent || jsxUtil.isDOMComponent(node.parent)) && isDangerous(node.name.name)) {
report(context, messages.dangerousProp, 'dangerousProp', {
node,
The first change is made to prevent functionName from being undefined (although this doesn't explain why).
The second change is made to skip the check on component names if we defined the rule on '*'.
I can make a PR if you want.
eslint-plugin-react version
v7.37.0
eslint version
v8.57.0
node version
v20.16.0
Is there an existing issue for this?
Description Overview
Hi team, thanks for your work on this lib 🙏
Using
react/no-dangerrule with option['error', { customComponentNames: ['*'] }]cause a command-line error.Documentation about it: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger.md
Here is how I use the rule in my eslint configuration:
When I run
eslint ./srcon my project, an error occurred (only usingcustomComponentNamesoption):This error is triggered by this line
eslint-plugin-react/lib/rules/no-danger.js
Line 82 in ec27e20
Actually I don't know why, but sometimes
functionNameis undefinedeslint-plugin-react/lib/rules/no-danger.js
Line 80 in ec27e20
Expected Behavior
Locally I patched
eslint-plugin-reactlike this:diff --git a/lib/rules/no-danger.js b/lib/rules/no-danger.js index fb702632082068b08954ebb849d0994da6fac5b6..be0f82185cd9bc8358f29f5a19104ad3343996d7 100644 --- a/lib/rules/no-danger.js +++ b/lib/rules/no-danger.js @@ -77,10 +77,9 @@ module.exports = { return { JSXAttribute(node) { - const functionName = node.parent.name.name; - - const enableCheckingCustomComponent = customComponentNames.some((name) => minimatch(functionName, name)); + const functionName = node.parent.name.name ?? ''; + const enableCheckingCustomComponent = customComponentNames.some((name) => name === '*' || minimatch(functionName, name)); if ((enableCheckingCustomComponent || jsxUtil.isDOMComponent(node.parent)) && isDangerous(node.name.name)) { report(context, messages.dangerousProp, 'dangerousProp', { node,The first change is made to prevent
functionNamefrom beingundefined(although this doesn't explain why).The second change is made to skip the check on component names if we defined the rule on
'*'.I can make a PR if you want.
eslint-plugin-react version
v7.37.0
eslint version
v8.57.0
node version
v20.16.0