For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/prefer-dom-node-text-content.md.
close

prefer-dom-node-text-content

Unreleased

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-dom-node-text-content': 'error',
    },
  },
]);

Rule Details

Prefer .textContent over .innerText on DOM nodes. Reading .innerText depends on rendered layout and can trigger reflow. Use .innerText when you need the text as rendered. MDN Node.textContent

This rule checks dot access, including optional chains, and identifier keys in object destructuring. It skips values known to have a non-DOM type. Its editor suggestion preserves the local name in shorthand destructuring.

Examples of incorrect code

const text = foo.innerText;
const { innerText } = foo;
foo.innerText = '🦄';

Examples of correct code

const text = foo.textContent;
const { textContent } = foo;
foo.textContent = '🦄';

Options

This rule has no options.

Differences from upstream

With project type information, rslint can distinguish browser DOM types from application types that share their names. For example, if ./library exports its own Node class, eslint-plugin-unicorn reports the access below and rslint skips it.

import { Node as Model } from './library';

new Model().innerText;

Original Documentation