Skip to content

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

Closed
@daltones

Description

@daltones

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()).

Activity

ljharb

ljharb commented on Feb 16, 2017

@ljharb
Member

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

daltones commented on Feb 16, 2017

@daltones
ContributorAuthor

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

daltones commented on Feb 16, 2017

@daltones
ContributorAuthor

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

ljharb commented on Feb 16, 2017

@ljharb
Member

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

jpickwell

jpickwell commented on Mar 3, 2017

@jpickwell

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.

36 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ljharb@jpickwell@daltones

        Issue actions

          `void-dom-elements-no-children` checking every .createElement and crashing · Issue #1073 · jsx-eslint/eslint-plugin-react