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

TypeError: Cannot read property 'match' of undefined with prefer-stateless-function #2596

Closed
garyking opened this issue Mar 18, 2020 · 2 comments

Comments

@garyking
Copy link

With the code:

/**
 * @param a.
 */
function Comp() {
  return <a></a>
}

Lint it with this rule, version eslint-plugin-react@7.19.0.

I get the error:

[Error - 11:18:15 PM] ESLint stack trace:
[Error - 11:18:15 PM] TypeError: Cannot read property 'match' of undefined
Occurred while linting test.tsx:4
    at scanIdentifier (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:259:96)
    at parseName (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:317:29)
    at TagParser.parseName (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:500:34)
    at TagParser.parse (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:769:34)
    at parseTag (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:790:26)
    at Object.parse (eslint-plugin-react/node_modules/doctrine/lib/doctrine.js:868:23)
    at Object.isExplicitComponent (eslint-plugin-react/lib/util/Components.js:269:35)
    at Object.isES6Component (eslint-plugin-react/lib/util/Components.js:237:17)
    at eslint-plugin-react/lib/rules/prefer-stateless-function.js:365:68
    at Array.forEach (<anonymous>)

This happens in particular, when I have ESLint linting while I type.

I managed to fix the issue in doctrine by adding && source[index], but then I find out that the package is archived on GitHub!

This bug might have been introduced recently (in the past week?), as I haven't seen it before.

@ljharb
Copy link
Member

ljharb commented Mar 18, 2020

I doubt that, as eslint-plugin-react v7.19 has been out awhile.

Generally speaking, linting while typing isn't a supported use case, but it's nice to avoid crashes.

Given that doctrine is archived, it's unlikely we'll be able to fix this without removing our use of it - which also seems unlikely, but would be great to see via a PR.

@danavil87
Copy link

Is there any update to this? I just ran into the same issue and also got around it by adding the check

@ljharb ljharb closed this as completed in 227cf88 Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants