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.
Common errors
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. Warnings
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.
Install
npm install remark-lint-code-block-style yarn add remark-lint-code-block-style pnpm add remark-lint-code-block-style Imports
- remarkLintCodeBlockStyle wrong
import { remarkLintCodeBlockStyle } from 'remark-lint-code-block-style'correctimport remarkLintCodeBlockStyle from 'remark-lint-code-block-style' - Options wrong
import { Options } from 'remark-lint-code-block-style' (type-only import preferred)correctimport type { Options } from 'remark-lint-code-block-style' - Style
import type { Style } from 'remark-lint-code-block-style' - CommonJS require wrong
const { remarkLintCodeBlockStyle } = require('remark-lint-code-block-style')correctconst remarkLintCodeBlockStyle = require('remark-lint-code-block-style').default
Quickstart
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))