close

prefer-global/text-decoder

Unreleased

Configuration

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

export default defineConfig([
  nodePlugin.configs.recommended,
  {
    rules: {
      'node/prefer-global/text-decoder': 'error',
    },
  },
]);

Enforces consistent use of the global TextDecoder or the TextDecoder export from Node.js's util module.

Options

  • "always" (default): use the global TextDecoder.
  • "never": use TextDecoder from util or node:util.

The rule recognizes CommonJS require, process.getBuiltinModule, and ES module imports and re-exports. It follows aliases and static property access, and respects shadowed or disabled globals. It does not provide automatic fixes or suggestions.

always

Examples of incorrect code:

const { TextDecoder } = require("node:util");
const decoder = new TextDecoder();

Examples of correct code:

const decoder = new TextDecoder();

never

Examples of incorrect code:

const decoder = new TextDecoder();

Examples of correct code:

import { TextDecoder } from "node:util";
const decoder = new TextDecoder();

Original Documentation