remark-lint-hard-break-spaces

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

A remark-lint rule to warn when too many spaces are used to create a hard break (line break) in Markdown. Current stable version: 4.1.1 (ESM-only, TypeScript types included). Release cadence: follows remark-lint monorepo releases. Key differentiators: as part of the official remark-lint ecosystem, it integrates seamlessly with unified/remark and supports presets like remark-preset-lint-recommended. It enforces consistent hard break style (exactly 2 trailing spaces) and can optionally disallow space-based hard breaks entirely in favor of backslash escapes.

error Error: Cannot find module 'remark-lint-hard-break-spaces'
cause Package not installed or incorrect import path.
fix
Run npm install remark-lint-hard-break-spaces and ensure the import path matches the package name.
error ERR_REQUIRE_ESM: require() of ES Module /node_modules/remark-lint-hard-break-spaces/index.js from ... not supported.
cause Using CommonJS require() on an ESM-only package (v4+).
fix
Use import remarkLintHardBreakSpaces from 'remark-lint-hard-break-spaces' in an ESM context, or downgrade to v3.x.
error TypeError: remarkLintHardBreakSpaces is not a function
cause Wrong import style (named import instead of default import).
fix
Use import remarkLintHardBreakSpaces from 'remark-lint-hard-break-spaces' (no curly braces).
error Error: The plugin `remark-lint-hard-break-spaces` does not export a `default` property.
cause Attempting to use the plugin with a configuration object that expects a named export.
fix
Ensure the plugin is referenced correctly in .use(): unified().use(remarkLintHardBreakSpaces).
breaking Version 4.0.0 dropped CommonJS support. The package is now ESM-only.
fix Use dynamic import() or switch to an ESM project. If you must use CommonJS, stay on v3.x.
breaking The default export was renamed (previously exported as `remarkLintHardBreakSpaces`). In v4, the default export is the plugin function directly.
fix Use `import remarkLintHardBreakSpaces from 'remark-lint-hard-break-spaces'` instead of `import { default } from ...`.
deprecated The `allowSpaces` option default may change in future major versions to encourage backslash escapes per CommonMark recommendation.
fix Explicitly set `{ allowSpaces: true/false }` to avoid surprises in future upgrades.
gotcha Requires `remark-lint` to be used as a plugin before this rule in the unified pipeline; otherwise the rule has no effect.
fix Ensure `.use(remarkLint)` is called before `.use(remarkLintHardBreakSpaces)`.
gotcha This rule only checks trailing spaces; it does not warn about hard breaks created by backslash escapes, which are always allowed unless `allowSpaces: false` is set.
fix Use `allowSpaces: false` to require backslash escapes for hard breaks.
gotcha The rule does not detect hard breaks in code blocks or raw HTML; it applies only to standard Markdown block/span content.
fix This is by design. If you need to lint inside code comments or HTML, use a separate plugin.
npm install remark-lint-hard-break-spaces
yarn add remark-lint-hard-break-spaces
pnpm add remark-lint-hard-break-spaces

Lints a Markdown file using remark, with the hard-break-spaces rule configured to disallow trailing space hard breaks (enforce backslash).

import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintHardBreakSpaces from 'remark-lint-hard-break-spaces';

const file = await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintHardBreakSpaces, { allowSpaces: false })
  .use(remarkStringify)
  .process(await read('example.md'));

console.error(reporter(file));