remark-lint-fenced-code-flag
raw JSON → 4.2.0 verified Fri May 01 auth: no javascript
A remark-lint rule that warns when fenced code blocks lack a language flag (infostring) or use an unrecognized one. Current stable version 4.2.0, released as part of the remark-lint monorepo with regular updates tied to remark ecosystem releases. Differentiates from generic linting by optionally validating against GitHub Linguist flags, ensuring code highlighting compatibility. Ships TypeScript definitions, ESM-only, requires Node.js 16+. Part of the remark-lint preset family.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/remark-lint-fenced-code-flag/index.js from /path/to/file.js not supported. ↓
cause Package is ESM-only from v4.
fix
Convert your project to ESM (use import/export) or use dynamic import: const m = await import('remark-lint-fenced-code-flag')
error TypeError: Cannot read properties of undefined (reading 'type') ↓
cause Missing 'remark-lint' in the unified pipeline.
fix
Ensure you have .use(remarkLint) before the rule: unified().use(remarkParse).use(remarkLint).use(remarkLintFencedCodeFlag)
Warnings
breaking Package is ESM-only since version 4.0.0. ↓
fix Use import statements. If required in CommonJS, use dynamic import() or downgrade to version 3.x.
breaking Node.js version requirement raised to 16+ in v4. ↓
fix Update Node.js to version 16 or later.
deprecated The built-in list of allowed flags may not be updated frequently; consider using the checkGithubLinguistFlag function for accurate validation. ↓
fix Use the checkGithubLinguistFlag imported utility to validate flags against GitHub Linguist.
gotcha Options can be passed as array, CheckFlag function, or Options object. Passing a string array directly is deprecated in favor of Options array property. ↓
fix Pass options as { allowEmpty: true, allowed: ['js', 'ts'] } for clarity.
Install
npm install remark-lint-fenced-code-flag yarn add remark-lint-fenced-code-flag pnpm add remark-lint-fenced-code-flag Imports
- remarkLintFencedCodeFlag wrong
const remarkLintFencedCodeFlag = require('remark-lint-fenced-code-flag')correctimport remarkLintFencedCodeFlag from 'remark-lint-fenced-code-flag' - checkGithubLinguistFlag
import { checkGithubLinguistFlag } from 'remark-lint-fenced-code-flag' - CheckFlag
import type { CheckFlag } from 'remark-lint-fenced-code-flag' - Options
import type { Options } from 'remark-lint-fenced-code-flag'
Quickstart
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintFencedCodeFlag from 'remark-lint-fenced-code-flag';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';
const file = await read('example.md');
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintFencedCodeFlag, { allowEmpty: false })
.use(remarkStringify)
.process(file);
console.error(reporter(file));