jsx-eslint/eslint-plugin-react

Rule proposal: enforce shape of dangerouslySetInnerHTML

Open

#711 opened on Jul 26, 2016

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (8,630 stars) (2,797 forks)batch import
help wantednew rulequestion

Description

React will issue a warning if you try to use dangerouslySetInnerHTML with a value of the wrong shape.

https://github.com/facebook/react/blob/85dcbf83/src/renderers/dom/shared/ReactDOMComponent.js#L173-L177

This should be easy enough to enforce for most cases with a linter rule.

Bad:

<div dangerouslySetInnerHTML={{ }} />
<div dangerouslySetInnerHTML={{ html: 'HTML' }} />
<div dangerouslySetInnerHTML={true} />

Good:

<div dangerouslySetInnerHTML={{ __html: 'HTML' }} />

Contributor guide