Skip to content
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

eslint crashes when using rest syntax in component params #2817

Closed
PeterPanen opened this issue Oct 2, 2020 · 3 comments
Closed

eslint crashes when using rest syntax in component params #2817

PeterPanen opened this issue Oct 2, 2020 · 3 comments

Comments

@PeterPanen
Copy link

PeterPanen commented Oct 2, 2020

I am running newest eslint 7.10.0 and eslint-plugin-react 7.21.2, and i'm having this weird issue in functional components where eslint crashes whenever i use rest like below:

// test.js
import React from "react"

const Header = ({ text, ...other }) => {
  return <h1>Test</h1>
}

eslint produces the following error:

Oops! Something went wrong! :(

ESLint: 7.10.0

TypeError: Cannot read property 'type' of undefined
Occurred while linting /home/username/Webapps/project/src/components/ApplicantViewerModal/test.js:1
    at /home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:156:39
    at Array.forEach (<anonymous>)
    at /home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:152:26
    at Array.forEach (<anonymous>)
    at isDeclaredInDestructuredParam (/home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:147:14)
    at isDeclaredInComponent (/home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:189:18)
    at /home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:204:13
    at Array.filter (<anonymous>)
    at reportUndeclaredPropTypes (/home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:201:51)
    at /home/username/Webapps/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:226:11

However, if i just pull the rest syntax down into the function body, everything works fine:

// test.js
import React from 'react'

const Header = props => {
  const { text, ...other } = props
  return <h1>Test</h1>
}
@ljharb
Copy link
Member

ljharb commented Oct 2, 2020

Duplicate of #2816. Duplicate of #2810. Duplicate of #2806. Duplicate of #2804.

@ljharb ljharb closed this as completed Oct 2, 2020
@PeterPanen
Copy link
Author

Oh, sorry i thought i had been looking thoroughly for duplicates and was slowly becoming insane haha xD
Thanks in advance!

@ljharb
Copy link
Member

ljharb commented Oct 2, 2020

np, i'll try to get a release out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants