Skip to main content
interlace
Plugin: conventionsRules

prefer-dom-node-text-content

Prefer textContent over innerText. This rule is part of eslint-plugin-conventions.

Prefer textContent over innerText. This rule is part of eslint-plugin-conventions.

Quick Summary

AspectDetails
SeverityWarning (performance)
Auto-Fix💡 Suggestion (converts property)
CategoryQuality
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForDOM manipulation, performance-critical code

Rule Details

innerText triggers reflow and is slower. textContent is more performant and works in all contexts.

The rule reports reading or writing innerText in every spelling: el.innerText, el['innerText'], el?.innerText, an assignment target, and destructuring it (const { innerText } = el, renamed too). It does not report textContent, a runtime key (el[key]), an innerText key in an object literal (it builds an object; no element is touched) or a variable named innerText. The suggestion rewrites member accesses; destructuring gets no suggestion, because renaming the key would rename the binding too.

Why This Matters

IssueImpactSolution
⚡ PerformanceinnerText triggers reflowtextContent
🎨 Style awarenessinnerText reads computed styleAvoid when not needed
🖥️ SSR supportinnerText requires layouttextContent works always

Examples

❌ Incorrect

const text = element.innerText;  // Triggers reflow
element.innerText = 'Hello';  // Slower

✅ Correct

const text = element.textContent;  // No reflow
element.textContent = 'Hello';  // Faster

// Use innerText only when you need style-aware text
// (hidden elements, CSS text-transform, etc.)

Configuration Examples

Basic Usage

{
  rules: {
    'conventions/prefer-dom-node-text-content': 'warn'
  }
}

Further Reading

Known False Negatives

  • The rule is not type-aware: it does not check that the receiver is a DOM element, so a non-DOM object with an innerText property is reported too, and an element reached through Reflect.get(el, 'innerText') is not.

Use this rule

npm install -D oxlint-plugin-conventions
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-conventions"],  "rules": {    "conventions/prefer-dom-node-text-content": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-conventions'],    rules: {      'conventions/prefer-dom-node-text-content': 'error',    },  },});

oxlint-plugin-conventions re-exports eslint-plugin-conventions/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.