remark-lint-file-extension

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

A remark-lint rule to warn when a file's extension does not match a configured style. Current stable version is 3.0.1, part of the remark-lint monorepo with regular updates. It checks file extensions against a list of allowed values, supports allowing extensionless files (default true), and provides a TypeScript type for configuration. Key differentiator: it enforces consistent file naming conventions in markdown projects, useful for ensuring .md vs .mdx compliance. ESM-only since v3, requires Node.js 16+.

error Cannot find module 'remark-lint-file-extension'
cause Missing installation or wrong import path
fix
Run 'npm install remark-lint-file-extension' and ensure import path matches: 'remark-lint-file-extension'
error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Using CommonJS require() on an ESM-only package
fix
Use 'import' syntax or 'import()' dynamic import. For old projects, stick to version 2.x.
error TypeError: remarkLint is not a function
cause remark-lint plugin not applied before the rule in the unified chain
fix
Make sure to call .use(remarkLint) before .use(remarkLintFileExtension).
breaking ESM-only since v3: package no longer supports CommonJS require()
fix Use import or dynamic import() instead of require(). For Node.js, ensure "type": "module" in package.json or use .mjs extension.
breaking Node.js version requirement: v16+ starting from v3
fix Upgrade Node.js to v16 or later, or use an older version (v2.x) of the package.
deprecated Default extensions changed from ['md', 'mdx'] to ['md', 'mdx'] in v3 (no change but worth noting that config is required to override)
fix Explicitly set extensions option if you need different values.
gotcha Plugin must be used after remark-lint plugin in the unified chain
fix Ensure .use(remarkLint) is called before .use(remarkLintFileExtension).
npm install remark-lint-file-extension
yarn add remark-lint-file-extension
pnpm add remark-lint-file-extension

Shows how to use remark-lint-file-extension with the unified API to validate a file's extension.

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import remarkLint from 'remark-lint';
import remarkLintFileExtension from 'remark-lint-file-extension';
import { read } from 'to-vfile';
import { reporter } from 'vfile-reporter';

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

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintFileExtension, { extensions: ['md'], allowExtensionless: true })
  .use(remarkStringify)
  .process(file);

console.error(reporter(file));