remark-lint-code-block-style

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

remark-lint rule to enforce a consistent code block style (indented or fenced) in Markdown. Version 4.0.1 is the current stable release. Part of the remark-lint ecosystem, it allows 'consistent' (auto-detect first style), 'indented', or 'fenced'. It is ESM-only since v4 and ships TypeScript definitions. Unlike other lint rules, this focuses solely on code block style, making it minimal and composable with other remark plugins. Frequently used in presets like remark-preset-lint-consistent.

error SyntaxError: Named export 'remarkLintCodeBlockStyle' not found. The requested module 'remark-lint-code-block-style' is a CommonJS module, which may not support all module.exports as named exports.
cause Attempting named import instead of default import.
fix
Use import remarkLintCodeBlockStyle from 'remark-lint-code-block-style' (default import).
error Error: Cannot find module 'remark-lint-code-block-style'
cause Package not installed or ESM module not resolved in CommonJS environment.
fix
Ensure package is installed: npm install remark-lint-code-block-style. If in CommonJS, use dynamic import: const mod = await import('remark-lint-code-block-style').
error TypeError: remarkLintCodeBlockStyle is not a function
cause Using `require('remark-lint-code-block-style')` without `.default` in ESM-only package.
fix
Use const remarkLintCodeBlockStyle = require('remark-lint-code-block-style').default in CommonJS, or switch to import.
breaking Since v4, this package is ESM-only and no longer supports CommonJS require().
fix Use import syntax or switch to dynamic import in CommonJS.
deprecated Options via 'options.style' is now accepted as first argument; old pattern 'options.style' still works but deprecated.
fix Pass style directly as string or object with 'style' key; e.g., .use(remarkLintCodeBlockStyle, 'fenced')
gotcha When using 'consistent' mode, the rule uses the first code block encountered as reference; mixing indented and fenced blocks in same file will warn after the first.
fix Use explicit style like 'fenced' to avoid ambiguity.
npm install remark-lint-code-block-style
yarn add remark-lint-code-block-style
pnpm add remark-lint-code-block-style

Shows how to set up remark-lint with this rule to enforce fenced code blocks and report lint warnings.

import remarkLint from 'remark-lint'
import remarkLintCodeBlockStyle from 'remark-lint-code-block-style'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import { read } from 'to-vfile'
import { unified } from 'unified'
import { reporter } from 'vfile-reporter'

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

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintCodeBlockStyle, { style: 'fenced' })
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))