noDangerouslySetInnerHtmlWithChildren
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/security/noDangerouslySetInnerHtmlWithChildren¥Diagnostic Category:
lint/security/noDangerouslySetInnerHtmlWithChildren -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
与
react/no-danger-with-children相同¥Same as
react/no-danger-with-children
-
¥How to configure
{ "linter": { "rules": { "security": { "noDangerouslySetInnerHtmlWithChildren": "error" } } }}¥Description
报告 DOM 元素或组件同时使用 children 和 dangerouslySetInnerHTML prop 的情况。
¥Report when a DOM element or a component uses both children and dangerouslySetInnerHTML prop.
¥Examples
¥Invalid
function createMarkup() { return { __html: 'child' }}<Component dangerouslySetInnerHTML={createMarkup()}>"child1"</Component>code-block.jsx:4:12 lint/security/noDangerouslySetInnerHtmlWithChildren ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid passing both children and the dangerouslySetInnerHTML prop.
2 │ return { __html: ‘child’ }
3 │ }
> 4 │ <Component dangerouslySetInnerHTML={createMarkup()}>“child1”</Component>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │
ℹ This is the source of the children prop
2 │ return { __html: ‘child’ }
3 │ }
> 4 │ <Component dangerouslySetInnerHTML={createMarkup()}>“child1”</Component>
│ ^^^^^^^^
5 │
ℹ Setting HTML content will inadvertently override any passed children in React
function createMarkup() { return { __html: 'child' }}<Component dangerouslySetInnerHTML={createMarkup()} children="child1" />code-block.jsx:4:12 lint/security/noDangerouslySetInnerHtmlWithChildren ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid passing both children and the dangerouslySetInnerHTML prop.
2 │ return { __html: ‘child’ }
3 │ }
> 4 │ <Component dangerouslySetInnerHTML={createMarkup()} children=“child1” />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │
ℹ This is the source of the children prop
2 │ return { __html: ‘child’ }
3 │ }
> 4 │ <Component dangerouslySetInnerHTML={createMarkup()} children=“child1” />
│ ^^^^^^^^^^^^^^^^^
5 │
ℹ Setting HTML content will inadvertently override any passed children in React
React.createElement('div', { dangerouslySetInnerHTML: { __html: 'HTML' } }, 'children')code-block.js:1:30 lint/security/noDangerouslySetInnerHtmlWithChildren ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid passing both children and the dangerouslySetInnerHTML prop.
> 1 │ React.createElement(‘div’, { dangerouslySetInnerHTML: { __html: ‘HTML’ } }, ‘children’)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ This is the source of the children prop
> 1 │ React.createElement(‘div’, { dangerouslySetInnerHTML: { __html: ‘HTML’ } }, ‘children’)
│ ^^^^^^^^^^
2 │
ℹ Setting HTML content will inadvertently override any passed children in React
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号