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

Handle spread props in no-children-prop rule #862

Merged

Conversation

randycoulman
Copy link
Contributor

@randycoulman randycoulman commented Sep 23, 2016

Nodes of type ExperimentalSpreadProperty don’t have a key property, causing the no-children-prop to raise a “Cannot read property ‘name’ of undefined” error.

Code such as:

return React.createElement(
  elementType,
  { className: classNames, ...otherProps },
  children
)

will trigger the error.

Nodes of type `ExperimentalSpreadProperty` don’t have a `key` property,
causing the `no-children-prop` to raise a “Cannot read property ‘name’
of undefined” error.

Code such as:

```
  return React.createElement(
    elementType,
    { className: classNames, ...otherProps },
    children
  )
```

will trigger the error.
randycoulman added a commit to CodingZeal/react-boilerplate that referenced this pull request Sep 23, 2016
It turns out that eslint-plugin-react’s no `no-children-prop` has a bug
when dealing with spread props, and that gets triggered in
`layout/Base/index.js`.

I’ve submitted a PR to that project
(jsx-eslint/eslint-plugin-react#862), but for
now am pointing at my PR branch.

It would be possible to extract the props to a variable before passing
them to `React.createElement` to work around the bug.  I’m happy to go
that way instead of having a github dependency in the project.

Or, we could let this PR sit open for a few days to see if the PR gets
merged upstream.
@@ -15,6 +15,7 @@ var RuleTester = require('eslint').RuleTester;
var parserOptions = {
ecmaVersion: 6,
ecmaFeatures: {
experimentalObjectRestSpread: true,
Copy link
Member

Choose a reason for hiding this comment

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

let's not necessarily enable this for every test - can we enable it just for the new tests?

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 thought about doing that, but in looking through all of the tests in the project, there isn't a single other case where different parserOptions are used for different test cases. There are eight other test cases that add experimentalObjectRestSpread: true to their top-level parserOptions, though.

That said, if you think it's important to establish a new pattern here, I'm happy to make the change.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% on it either way - it just seems like it'd be useful to test the parser with common (non-experimental) options.

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 think you've got a valid point.

But I'm pretty big on code consistency, so I wonder if it would be better to do a separate PR with that change made in all of the cases like this.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why - this is the PR that adds experimentalObjectRestSpread. but i don't think this needs to block if other maintainers think it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this PR adds it here. But there are eight other tests that include experimentalObjectRestSpread in their default parserOptions just like this one does.

If it's important to only set that option for certain test cases, then I think we should make that consistent across all of the tests that use that option. That's why I suggested a separate PR to make that change.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, that's a fair point.

@yannickcr yannickcr merged commit f227eb4 into jsx-eslint:master Sep 24, 2016
@yannickcr
Copy link
Member

Merged, thanks!

@ljharb
Copy link
Member

ljharb commented Oct 7, 2016

@yannickcr any update on a release?

@yannickcr
Copy link
Member

@ljharb sorry, I was pretty busy last days but I'll try to craft a release this week-end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants