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

no-danger-with-children false positive with newline in element #1262

Closed
mockdeep opened this issue Jun 15, 2017 · 4 comments
Closed

no-danger-with-children false positive with newline in element #1262

mockdeep opened this issue Jun 15, 2017 · 4 comments

Comments

@mockdeep
Copy link

The following reports an error on the no-danger-with-children rule:

<div dangerouslySetInnerHTML={'<span>stuff</span>'}>
</div>

I would expect if there is a newline between the opening and closing tag that the rule would not complain.

@ljharb
Copy link
Member

ljharb commented Jun 15, 2017

That's still considered "children", afaik - why not <div dangerouslySetInnerHTML={'<span>stuff</span>'} />?

@mockdeep
Copy link
Author

Ah, I didn't realize we could do self-closing divs in jsx. Still, I don't think newlines between tags are considered children. Hacked together this quick test:

import React from 'react';
import { mount } from 'enzyme';

class Parent extends React.Component {

  render() {
    console.log(this.props.children);
    return <div>{this.props.children}</div>;
  }

}

it('does stuff', () => {
  mount(<Parent></Parent>); // => `undefined`
  mount(<Parent>
      </Parent>); // => `undefined`
  mount(<Parent />); // => `undefined`
  mount(<Parent> </Parent>); // => `' '`
  mount(<Parent>

      </Parent>); // => `undefined`
  mount(<Parent>foo</Parent>); // => `'foo'`
})

@ljharb
Copy link
Member

ljharb commented Jun 16, 2017

Fair point - both your example and https://jsfiddle.net/ljharb/69z2wepo/80986/ implies it's a bug in eslint-plugin-react.

@mockdeep
Copy link
Author

Ha, nice. I started typing ReactDOM and then fell back to what I knew off the top of my head.

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

No branches or pull requests

2 participants