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

Check for createElement being called from React #1011

Merged
merged 3 commits into from Jan 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/util/Components.js
Expand Up @@ -258,6 +258,8 @@ function componentRule(rule, context) {
var returnsReactCreateElement =
node[property] &&
node[property].callee &&
node[property].callee.object &&
node[property].callee.object.name === 'React' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this prevent import { createElement } from 'react'; from being detected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I found a way to check for this by using the ModuleScope of the Variable when importing createElement like that. However, it involves using Map, and it doesn't seem like I can get away with that with the project setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just temporarily add in a disable comment so I can feel good about pushing it up. I'll remove it after receiving feedback.

node[property].callee.property &&
node[property].callee.property.name === 'createElement'
;
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -378,6 +378,13 @@ ruleTester.run('display-name', rule, {
')'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'module.exports = {',
' createElement: tagName => document.createElement(tagName)',
'};'
].join('\n'),
parser: 'babel-eslint'
}],

invalid: [{
Expand Down