remark-lint-code-block-syntax
raw JSON → 0.11.0 verified Fri May 01 auth: no javascript
A remark-lint rule that validates syntax of code blocks in Markdown files. Supports JavaScript, JSON, JSONC, JSON5, YAML, and CSS. Uses SWC for JavaScript parsing (since v0.4.0) and PostCSS for CSS (since v0.5.0). ESM-only since v0.3.0, requires Node.js >=18 (since v0.8.0). Active development, monthly releases. Differentiators: language alias support, broad language coverage, integrates with remark ecosystem.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module ↓
cause Using require() on an ESM-only package (v0.3.0+).
fix
Convert to import statement or use dynamic import().
error TypeError: remark().use is not a function ↓
cause Using a string plugin name instead of importing the function.
fix
Import the rule and pass it as a function: .use(remarkLintCodeBlockSyntax).
Warnings
breaking Node.js >=18 required since v0.8.0 ↓
fix Upgrade Node.js to version 18 or higher.
breaking ESM-only since v0.3.0 ↓
fix Use import syntax instead of require().
breaking Migrated from Esprima to SWC in v0.4.0 ↓
fix No action needed, but note that parsing is now faster and may catch different errors.
deprecated Node.js 16 support dropped in v0.8.0 ↓
fix Upgrade to Node.js 18 or higher.
gotcha CSS support added in v0.5.0; language aliases supported but not all languages ↓
fix Check if your language is supported. See README for list.
Install
npm install remark-lint-code-block-syntax yarn add remark-lint-code-block-syntax pnpm add remark-lint-code-block-syntax Imports
- remarkLintCodeBlockSyntax wrong
const remarkLintCodeBlockSyntax = require('remark-lint-code-block-syntax')correctimport remarkLintCodeBlockSyntax from 'remark-lint-code-block-syntax' - remarkLintCodeBlockSyntax (with remark) wrong
remark().use('remark-lint-code-block-syntax')correctimport remark from 'remark'; import remarkLintCodeBlockSyntax from 'remark-lint-code-block-syntax'; remark().use(remarkLintCodeBlockSyntax) - remarkLintCodeBlockSyntax (type import) wrong
import { remarkLintCodeBlockSyntax } from 'remark-lint-code-block-syntax'correctimport type { Plugin } from 'unified'; import remarkLintCodeBlockSyntax from 'remark-lint-code-block-syntax'
Quickstart
import { remark } from 'remark';
import remarkLintCodeBlockSyntax from 'remark-lint-code-block-syntax';
import { reporter } from 'vfile-reporter';
const code = `
\`\`\`js
const sum = 1 +;
\`\`\`
`;
async function main() {
const file = await remark()
.use(remarkLintCodeBlockSyntax)
.process(code);
console.error(reporter(file));
}
main();