no-danger
Configuration
Disallow usage of dangerous JSX properties.
Rule Details
Dangerous properties in React are those whose behavior is known to be a common
source of application vulnerabilities. The names of these properties make their
dangerous nature explicit. Currently only dangerouslySetInnerHTML is checked.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
customComponentNames
An array of component name patterns. Defaults to [] (off for custom
components). Patterns use * as a wildcard (minimatch-style). Set to
["*"] to check every custom component, or list specific names such as
["MyComponent", "Sub*"] to opt in by name.
Examples of incorrect code with { "customComponentNames": ["*"] }:
When Not To Use It
Disable this rule if you know the content passed to dangerouslySetInnerHTML
has already been sanitized.
Differences from ESLint
- Deep member tag names. For
<A.B.C dangerouslySetInnerHTML={...} />,eslint-plugin-reactflattens only one level of member access, producing the string"undefined.C"when matching againstcustomComponentNames. rslint uses the full source-text name ("A.B.C"), so patterns such as["A.B.C"]or["A.*"]match deep member tags as intended. - JSX namespaced tag names. For
<ns:name dangerouslySetInnerHTML={...} />,eslint-plugin-reactpasses an Identifier AST node (not a string) intominimatch, which throwsf.split is not a functionat runtime — thecustomComponentNamesbranch crashes on namespaced tags in ESLint. rslint uses the string"ns:name", so patterns match as expected.