> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# crlf-unsafe-line-split

> Splitting file text on a bare newline leaves carriage returns on CRLF lines and can change exact comparisons.

## What it flags

Text read with `fs.readFileSync`, `fs.promises.readFile` or `readFile` from `node:fs/promises` (with a known text encoding or a buffer `.toString()` that decodes text) is split on a literal `'\n'`, and a resulting line is then compared exactly: `===` or `!==` against a nonempty string or, when iterating over the lines, an empty string. It also covers a `switch` case, `endsWith` without an explicit end position, a regex with a nonempty literal suffix and an end anchor, or `lines.indexOf`, `lines.includes` or `lines.lastIndexOf` with a string. In a file checked out with CRLF line endings terminated lines keep a trailing `\r`, which can change the result of the comparison. Imports under another name, `require('fs')`, namespace imports, constants holding the separator or the literal, and lines passed to functions in the same file are followed. Return values are followed for functions with a single direct call site. Reassigned loop variables and arrays with writes to a computed index are skipped. The rule follows full-buffer conversions, split calls with the default limit or a nonzero numeric literal, and array accesses with a known numeric key or numeric type. A fixed-index write can suppress later reads of that index or reads with an unresolved numeric index. An earlier whole-array `fill()` or earlier assignments covering every line allowed by a static split limit suppresses that use. Splits on `/\r?\n/`, text normalized first, lines trimmed before the comparison and `startsWith` checks are excluded. A no-argument `.toString()` on decoded text preserves the line endings. Contextual only: LF-only files compare as intended.

The analysis treats overwrites inside `try` as conditional for comparisons inside the corresponding `catch` or `finally`. Earlier work or the overwrite itself can throw. A comparison in `finally` can still be reported when a simple `fill()` is the only statement in the `try` block.

The check follows a read promise stored in a local constant before it is awaited. It also follows the data parameter of a Node `fs.readFile` callback when the call specifies a known text encoding.

## How to review or fix

Split on `/\r?\n/`, or normalize the text with `.replaceAll('\r\n', '\n')` before splitting. The review edit replaces the literal delimiter at an unambiguous reported split. It is not offered when the split lines, or a variable copied from them, are joined again in the file, because the joined text would lose its CRLF line endings. Named or dynamic delimiters stay available for manual review.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "crlf-unsafe-line-split": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.