remark-lint-final-newline

raw JSON →
3.0.1 verified Fri May 01 auth: no javascript

remark-lint rule to warn when a final newline character (\n) is missing at the end of a file. Part of the remark-lint ecosystem, this plugin enforces POSIX-style file endings. Current stable version is 3.0.1 (ESM-only, requires Node.js 16+). It is included in the `remark-preset-lint-recommended` preset. Unlike some linters that auto-fix, this rule only warns; auto-fixing can be done via `remark-stringify`. No configuration options.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Using CJS require() with ESM-only package.
fix
Change to import remarkLintFinalNewline from 'remark-lint-final-newline'
error Cannot find module 'remark-lint-final-newline'
cause Package not installed.
fix
npm install remark-lint-final-newline
error TypeError: remarkLintFinalNewline is not a function
cause Incorrect import or using the wrong symbol.
fix
Use default import: import remarkLintFinalNewline from 'remark-lint-final-newline'
breaking v3 is ESM-only; requires Node.js 16+ and cannot be used with require().
fix Switch to import syntax and ensure Node.js >=16.
deprecated The package does not accept options; passing options may cause unexpected behavior in future versions.
fix Do not pass any arguments to .use(remarkLintFinalNewline).
gotcha The rule only warns, it does not fix. Use remark-stringify to auto-add final newlines.
fix Ensure remark-stringify is included in your unified pipeline.
gotcha The rule checks for a single newline at end of file; multiple newlines or missing newline are flagged.
fix The rule expects exactly one \n at EOF. Use remark-stringify to normalize.
npm install remark-lint-final-newline
yarn add remark-lint-final-newline
pnpm add remark-lint-final-newline

Set up unified pipeline with remark-parse, remark-lint, the rule, and remark-stringify to lint and optionally fix missing final newline.

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintFinalNewline from 'remark-lint-final-newline';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';

const file = await read('example.md');

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintFinalNewline)
  .use(remarkStringify)
  .process(file);

console.error(reporter(file));