standard / standard

🌟 JavaScript Style Guide, with linter & automatic code fixer
https://standardjs.com
MIT License
29.12k stars 2.33k forks source link

Cannot read properties of undefined (reading 'type') (Rule: "react/jsx-key") on a non-React project #1844

Open FMGordillo opened 2 years ago

FMGordillo commented 2 years ago

What version of this package are you using?

17.0.0

What operating system, Node.js, and npm version?

OS: Windows 11 Version 10.0.22000 Build 22000, under WSL 2 (Ubuntu 20.04) Node: 18.5.0 npm: 8.12.1

What happened?

This test executes a function generator. All tests works fine, the code runs as expected, but standard throws this error

TypeError: Cannot read properties of undefined (reading 'type')
Occurred while linting /home/fmgordillo/code/data-structures-javascript/01-linked-lists/LinkedList.test.js:147
Rule: "react/jsx-key"
    at Object.isFunctionLikeExpression (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint-plugin-react/lib/util/ast.js:223:15)
    at CallExpression[callee.type="MemberExpression"][callee.property.name="map"],       CallExpression[callee.type="OptionalMemberExpression"][callee.property.name="map"],       OptionalCallExpression[callee.type="MemberExpression"][callee.property.name="map"],       OptionalCallExpression[callee.type="OptionalMemberExpression"][callee.property.name="map"] (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint-plugin-react/lib/rules/jsx-key.js:230:22)
    at ruleErrorHandler (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/linter.js:1114:28)
    at /home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/fmgordillo/code/data-structures-javascript/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)

If you think this is a bug in `standard`, open an issue: https://github.com/standard/standard/issues

What did you expect to happen?

To run standard without any error related to react

Are you willing to submit a pull request to fix this bug?

I'm still looking for a fix

LinusU commented 2 years ago

Seems like a bug in eslint-plugin-react, would be great if you could reproduce this in a minimal test case, and submit an issue to them!