Open darkred opened 3 years ago
Maybe we could make a more general no-unsafe-dom
rule.
For example, with Trusted Types, .innerHTML
is not dangerous.
Alternatively, a prefer-trusted-types
rule.
Related developments: https://web.dev/sanitizer/
❌ el.innerHTML = html;
✅ el.setHTML(html)
My suggestion is to either expand the
prefer-dom-node-text-content
rule (source) to also enforce.textContent
over.innerHTML
, or implement a newno-inner-html
rule.The motive for this is mainly because, in extension development such of Refined GitHub, the use
innerHTML
should always be avoided, otherwise it becomes flagged by the extension stores.This came up in this PR comment https://github.com/sindresorhus/refined-github/pull/4520#discussion_r659362368 As described in the comment above, such a rule,
no-inner-html
, is already implemented in theeslint-plugin-lwc
plugin. However, that rule disallows the use of 'innerHTML' in ALL its forms. This includesinnerHTML
,outputHTML
andinsertAdjacentHTML
Concluding, I was wondering whether it could be beneficial for XO, to either expand the existing
prefer-dom-node-text-content
rule againstinnerHTML
, or incorporate that ruleno-inner-html
as a whole.Fail
Pass