unicorn/prefer-dom-node-text-content Style
What it does
Enforces the use of .textContent over .innerText for DOM nodes.
Why is this bad?
There are some disadvantages of using .innerText.
.innerTextreturns rendered text and ignores hidden content, while.textContentreturns the node's full text content..innerTextcan trigger reflow because it takes CSS styles into account..innerTextis defined only for HTMLElement objects, while.textContentis defined for all Node objects.
Examples
Examples of incorrect code for this rule:
javascript
const text = foo.innerText;Examples of correct code for this rule:
javascript
const text = foo.textContent;How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/prefer-dom-node-text-content": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/prefer-dom-node-text-content": "error",
},
});bash
oxlint --deny unicorn/prefer-dom-node-text-contentVersion
This rule was added in v0.0.21.
