or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-remark-lint-hard-break-spaces

remark-lint rule to warn when too many spaces are used to create a hard break

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/remark-lint-hard-break-spaces@4.1.x

To install, run

npx @tessl/cli install tessl/npm-remark-lint-hard-break-spaces@4.1.0

index.mddocs/

remark-lint-hard-break-spaces

remark-lint-hard-break-spaces is a specialized remark-lint rule that validates the spacing used in Markdown hard line breaks. It warns when more than two spaces are used at the end of a line to create a hard break, or when spaces are used instead of the recommended backslash escape sequence.

Package Information

  • Package Name: remark-lint-hard-break-spaces
  • Package Type: npm
  • Language: JavaScript (with TypeScript types)
  • Installation: npm install remark-lint-hard-break-spaces

Core Imports

import remarkLintHardBreakSpaces from "remark-lint-hard-break-spaces";

For CommonJS:

const remarkLintHardBreakSpaces = require("remark-lint-hard-break-spaces");

Basic Usage

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

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

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

console.error(reporter(file));

Capabilities

Lint Rule Plugin

The main plugin function that creates a remark-lint rule to validate hard break spacing.

/**
 * remark-lint rule to warn when spaces are used incorrectly for hard breaks
 * @param {Options | null | undefined} options - Configuration options
 * @returns {Transformer} Transform function for unified pipeline
 */
function remarkLintHardBreakSpaces(options);

Usage with unified:

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkLint from "remark-lint";
import remarkLintHardBreakSpaces from "remark-lint-hard-break-spaces";

const processor = unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintHardBreakSpaces, { allowSpaces: false });

Usage with configuration:

// Allow trailing spaces (default behavior)
.use(remarkLintHardBreakSpaces)
.use(remarkLintHardBreakSpaces, { allowSpaces: true })

// Enforce escape-style hard breaks only
.use(remarkLintHardBreakSpaces, { allowSpaces: false })

Common integration patterns:

// In package.json remarkConfig
{
  "remarkConfig": {
    "plugins": [
      "remark-lint",
      "remark-lint-hard-break-spaces",
      // or with options
      ["remark-lint-hard-break-spaces", { "allowSpaces": false }]
    ]
  }
}

// With remark CLI
remark --use remark-lint --use remark-lint-hard-break-spaces .

Types

/**
 * Configuration options for the hard break spaces rule
 */
interface Options {
  /**
   * Allow trailing space hard breaks at all
   * @default true
   * When false: use escape hard breaks (backslash) instead
   * When true: allow 2-space hard breaks, warn on more than 2 spaces
   */
  allowSpaces?: boolean | null | undefined;
}

Error Messages

The plugin generates specific error messages based on configuration:

  • With allowSpaces: true (default): "Unexpected \3` spaces for hard break, expected `2` spaces"`
  • With allowSpaces: false: "Unexpected \2` spaces for hard break, expected escape"`

Configuration validation errors:

// Invalid option type
"Unexpected value `🌍` for `options`, expected object"

// Invalid allowSpaces type  
"Unexpected value `🌍` for `options.allowSpaces`, expected `boolean`"

Recommendation

Less than two spaces do not create hard breaks and more than two spaces have no effect. Due to this, it's recommended to turn this rule on.

With CommonMark, it is now possible to use a backslash (\) at the end of a line to create a hard break. It is now recommended to pass allowSpaces: false to enforce this cleaner approach.

Valid hard break examples:

<!-- With allowSpaces: true (default) -->
**Mercury** is the first planet from the Sun  
and the smallest in the Solar System.

<!-- With allowSpaces: false -->
**Venus** is the second planet from\
the Sun.

Invalid examples that trigger warnings:

<!-- Too many spaces (3+ spaces) -->
**Mercury** is the first planet from the Sun   
and the smallest in the Solar System.
<!-- Warning: "Unexpected `3` spaces for hard break, expected `2` spaces" -->

<!-- Spaces when allowSpaces: false -->
**Mercury** is the first planet from the Sun  
and the smallest in the Solar System.
<!-- Warning: "Unexpected `2` spaces for hard break, expected escape" -->