# require-text-decoder-streaming

Rule `unicorn/require-text-decoder-streaming`. Require streaming decoding of fetch-body chunks with `TextDecoder`.

- Source: unicorn
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1010 by reach, #1265 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/require-text-decoder-streaming` | no | suggestion | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/require-text-decoder-streaming.md) |

## Code examples

### Incorrect: the rule reports this

```js
const response = await fetch(url);
const decoder = new TextDecoder();
let text = '';

for await (const chunk of response.body) {
  text += decoder.decode(chunk);
}
```

### Correct: the rule accepts this

```js
const response = await fetch(url);
const decoder = new TextDecoder();
let text = '';

for await (const chunk of response.body) {
  text += decoder.decode(chunk, {stream: true});
}

text += decoder.decode();
```

```js
const response = await fetch(url);
const decoder = new TextDecoder();
const reader = response.body.getReader();
let text = '';

while (true) {
  const {value, done} = await reader.read();
  if (done) {
    break;
  }

  text += decoder.decode(value, {stream: true});
}

text += decoder.decode();
```

```js
const response = await fetch(url);
let text = '';

for await (const chunk of response.body.pipeThrough(new TextDecoderStream())) {
  text += chunk;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/require-text-decoder-streaming": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/require-proxy-trap-boolean-return](https://lintradar.dev/rules/unicorn/require-proxy-trap-boolean-return.md): Require boolean-returning Proxy traps to return booleans.
- [unicorn/explicit-length-check](https://lintradar.dev/rules/unicorn/explicit-length-check.md): Enforce explicitly comparing the `length` or `size` property of a value.
- [unicorn/require-passive-events](https://lintradar.dev/rules/unicorn/require-passive-events.md): Require passive event listeners for high-frequency events.
- [unicorn/no-nested-ternary](https://lintradar.dev/rules/unicorn/no-nested-ternary.md): Disallow nested ternary expressions.
- [unicorn/require-css-escape](https://lintradar.dev/rules/unicorn/require-css-escape.md): Require `CSS.escape()` for interpolated values in CSS selectors.
- [unicorn/no-null](https://lintradar.dev/rules/unicorn/no-null.md): Disallow the use of the `null` literal.

---

Web page: https://lintradar.dev/rules/unicorn/require-text-decoder-streaming. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
