-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: react/no-danger β TypeError: Cannot read properties of undefined (reading 'split') #3833
Comments
Can you provide the code that this is crashing on? |
I have the same issue and it seems that there are two conditions that need to be present for this error to be thrown:
import React from 'react';
const Component = () => <></>;
const NestedComponent = () => <></>;
Component.NestedComponent = NestedComponent;
export const RenderTest = () => <Component.NestedComponent key=""/>; |
@halouvi that test case passes for me. What eslint config are you using? |
@ljharb these are my eslint package versions: "eslint": "8.27.0",
"@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.5",
"eslint-config-airbnb-typescript": "16.2.0",
"eslint-config-prettier": "8.5.0",
"eslint-import-resolver-typescript": "2.7.1",
"eslint-plugin-filenames": "1.3.2",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsx-a11y": "6.6.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.37.1",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-styled-components-a11y": "0.1.0", And this is my {
"root": true,
"env": {
"browser": true,
"es6": true
},
"extends": [
"airbnb-typescript",
"prettier",
"plugin:styled-components-a11y/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json",
"extraFileExtensions": [".html"]
},
"parser": "@typescript-eslint/parser",
"plugins": [
"react",
"react-hooks",
"jsx-a11y",
"filenames",
"import",
"@typescript-eslint",
"prettier"
],
"rules": {
"react/require-default-props": [0],
"import/prefer-default-export": "off",
"no-debugger": [1],
"no-console": [1],
"no-return-await": "off",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"arrow-body-style": "off",
"@typescript-eslint/no-use-before-define": "off",
"camelcase": "off",
"react/button-has-type": [0],
"react/no-unescaped-entities": [0],
"no-param-reassign": [
"error",
{
"props": false
}
],
"@typescript-eslint/indent": "off",
"@typescript-eslint/camelcase": "off",
"prefer-object-spread": "off",
"react/no-danger": [
"error",
{ "customComponentNames": ["*"] }
],
"react/jsx-props-no-spreading": "off",
"react/prop-types": "off",
"react/jsx-fragments": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
"lines-between-class-members": "off",
"class-methods-use-this": "off",
"filenames/match-exported": 2,
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"**/*.stories.tsx",
"**/*.test.tsx",
"**/*.test.ts",
"./setupTests.ts"
]
}
],
"import/no-cycle": "off",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/interactive-supports-focus": "warn",
"prettier/prettier": "error",
"react/destructuring-assignment": "off",
"jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/label-has-for": "warn",
"jsx-a11y/mouse-events-have-key-events": "warn",
"jsx-a11y/no-static-element-interactions": "warn",
"jsx-a11y/alt-text": "warn",
"styled-components-a11y/accessible-emoji": "warn",
"styled-components-a11y/anchor-has-content": "warn",
"styled-components-a11y/anchor-is-valid": "warn",
"styled-components-a11y/aria-activedescendant-has-tabindex": "warn",
"styled-components-a11y/aria-props": "warn",
"styled-components-a11y/aria-proptypes": "warn",
"styled-components-a11y/aria-role": "warn",
"styled-components-a11y/aria-unsupported-elements": "warn",
"styled-components-a11y/autocomplete-valid": "warn",
"styled-components-a11y/click-events-have-key-events": "warn",
"styled-components-a11y/control-has-associated-label": "warn",
"styled-components-a11y/heading-has-content": "warn",
"styled-components-a11y/img-redundant-alt": "warn",
"styled-components-a11y/interactive-supports-focus": "warn",
"styled-components-a11y/label-has-associated-control": ["warn"],
"styled-components-a11y/label-has-for": "off",
"styled-components-a11y/media-has-caption": "warn",
"styled-components-a11y/mouse-events-have-key-events": "warn",
"styled-components-a11y/no-access-key": "warn",
"styled-components-a11y/no-autofocus": "warn",
"styled-components-a11y/no-distracting-elements": "warn",
"styled-components-a11y/no-interactive-element-to-noninteractive-role": "warn",
"styled-components-a11y/no-noninteractive-element-interactions": "warn",
"styled-components-a11y/no-noninteractive-element-to-interactive-role": "warn",
"styled-components-a11y/no-noninteractive-tabindex": "warn",
"styled-components-a11y/no-onchange": "warn",
"styled-components-a11y/no-redundant-roles": "warn",
"styled-components-a11y/no-static-element-interactions": "warn",
"styled-components-a11y/role-has-required-aria-props": "warn",
"styled-components-a11y/role-supports-aria-props": "warn",
"styled-components-a11y/alt-text": "warn",
"styled-components-a11y/scope": "warn",
"styled-components-a11y/tabindex-no-positive": "warn",
"styled-components-a11y/html-has-lang": "off",
"styled-components-a11y/iframe-has-title": "off",
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/keyword-spacing": "off",
"@typescript-eslint/return-await": "warn",
"curly": ["error", "all"],
"react/jsx-key": ["error", { "checkFragmentShorthand": true }],
"react/jsx-indent": "off",
"react/jsx-indent-props": "off",
"react/jsx-no-bind": "off"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
}
}
}
|
Thank you @halouvi to find how to trigger the issue. Here is a sandbox that reproduce it. Uncomment |
Thanks, that helped! |
@ljharb Thanks for the fix π Do you know when the next version containing this fix is scheduled to be released? |
There's no release schedule, but probably within the next week or two. |
@ljharb I don't mean to bother but do you think there's any chance of releasing a version this week? |
I also encountered this problem now. If the release cannot be published yet, would you consider making a "canary"/"next" release, that is just the newest from the master branch? @ljharb |
@chribjel no, that would be identical to just publishing the default branch. |
@ljharb respectfully, is there a schedule for a version release? it's been two months now. |
|
@ljharb Appreciate it! π |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | devDependencies | patch | [`7.37.2` -> `7.37.3`](https://renovatebot.com/diffs/npm/eslint-plugin-react/7.37.2/7.37.3) | --- ### Release Notes <details> <summary>jsx-eslint/eslint-plugin-react (eslint-plugin-react)</summary> ### [`v7.37.3`](https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/CHANGELOG.md#7373---20241223) [Compare Source](jsx-eslint/eslint-plugin-react@v7.37.2...v7.37.3) ##### Fixed - \[`no-danger`]: avoid a crash on a nested component name ([#​3833][] [@​ljharb](https://github.com/ljharb)) - \[Fix] types: correct generated type declaration ([#​3840][] [@​ocavue](https://github.com/ocavue)) - \[`no-unknown-property`]: support `precedence` prop in react 19 ([#​3829][] [@​acusti](https://github.com/acusti)) - \[`prop-types`]: props missing in validation when using generic types from a namespace import ([#​3859][] [@​rbondoc96](https://github.com/rbondoc96)) ##### Changed - \[Tests] \[`jsx-no-script-url`]: Improve tests ([#​3849][] [@​radu2147](https://github.com/radu2147)) - \[Docs] fix broken links: \[`default-props-match-prop-types`], \[`jsx-boolean-value`], \[`jsx-curly-brace-presence`], \[`jsx-no-bind`], \[`no-array-index-key`], \[`no-is-mounted`], \[`no-render-return-value`], \[`require-default-props`] ([#​3841][] [@​bastiendmt](https://github.com/bastiendmt)) [7.37.3]: jsx-eslint/eslint-plugin-react@v7.37.2...v7.37.3 [#​3859]: jsx-eslint/eslint-plugin-react#3859 [#​3849]: jsx-eslint/eslint-plugin-react#3849 [#​3841]: jsx-eslint/eslint-plugin-react#3841 [#​3840]: jsx-eslint/eslint-plugin-react#3840 [#​3833]: jsx-eslint/eslint-plugin-react#3833 [#​3829]: jsx-eslint/eslint-plugin-react#3829 </details> --- ### Configuration π **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). π¦ **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. π **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS44My40IiwidXBkYXRlZEluVmVyIjoiMzkuODMuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: https://www.coastalcommits.com/cswimr/gauntlet-cswimr-plugins/pulls/9 Co-authored-by: Renovate <[email protected]> Co-committed-by: Renovate <[email protected]>
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:
When I run
eslint ./src
on my project, an error occurred (only usingcustomComponentNames
option):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
functionName
is undefinedeslint-plugin-react/lib/rules/no-danger.js
Line 80 in ec27e20
Expected Behavior
Locally I patched
eslint-plugin-react
like this:The first change is made to prevent
functionName
from 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
The text was updated successfully, but these errors were encountered: