ESLint InterlaceESLint Interlace
Plugin: conventionsRules

prefer-dom-node-text-content

ESLint rule documentation for prefer-dom-node-text-content

📡 Live from GitHub — This documentation is fetched directly from prefer-dom-node-text-content.md and cached for 6 hours.

Keywords: textContent, innerText, DOM, performance, ESLint rule, auto-fix, LLM-optimized

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✅ Yes (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.

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 following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// ❌ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not tracked

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// ❌ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings