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

void-dom-elements-no-children checking every .createElement and crashing #1073

Closed
daltones opened this issue Feb 16, 2017 · 5 comments
Closed

Comments

@daltones
Copy link
Contributor

I've just updated to v6.10.0 and enabled void-dom-elements-no-children.

It's crashing with this error:

TypeError: Cannot read property 'properties' of undefined
    at EventEmitter.CallExpression ([...]/eslint-plugin-react/lib/rules/void-dom-elements-no-children.js:121:28)
[...]

It happens with this simple code:

document.createElement('img');

So here is the first problem:

  • The rule thinks that every .createElement( is the React.createElement.

Now testing with the actual React:

import React from 'react';

React.createElement('img');

The rule will crash too.

Second problem:

  • The rule doesn't treat incomplete number of createElement's arguments (as while typing React.createElement()).
@ljharb
Copy link
Member

ljharb commented Feb 16, 2017

The first problem is intentional, as it looks for anything that could be a createElement call first, then refines.

The second is clearly a bug.

@daltones
Copy link
Contributor Author

Okay, but what is the point of the first problem being intentional when document.createElement could be a trivial false positive?

Why can't it work same way as other rules that use pragma setting to verify React.(createClass|(Pure)?Component)?

@daltones
Copy link
Contributor Author

Oh, right, I missed something. Fixing the second problem would not warn about document.createElement('img').

But maybe first problem could turn into another issue to prevent some edge cases like objectNothingAboutReact.createElement('img', {foo: bar}, 'baz').

Thanks!

@ljharb
Copy link
Member

ljharb commented Feb 16, 2017

I believe that if the bug was fixed, only React createElement calls would be matched.

@jpickwell
Copy link

I just installed master in one of my projects, and I'm no longer getting the TypeError: Cannot read property 'properties' of undefined error. So #1080 fixed that, which solved my problem. Thanks @jomasti.

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