remark plugin to lint Markdown code style
npx @tessl/cli install tessl/npm-remark-lint@10.0.0remark-lint is a remark plugin that adds support for configuration comments to control remark lint rule messages. It serves as the foundational plugin that enables ignoring lint warnings through HTML comments and provides the core infrastructure for the entire remark-lint ecosystem.
npm install remark-lintimport remarkLint from 'remark-lint';For Deno:
import remarkLint from 'https://esm.sh/remark-lint@10';For browsers:
<script type="module">
import remarkLint from 'https://esm.sh/remark-lint@10?bundle';
</script>import remarkLint from 'remark-lint';
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(remarkStringify)
.process(file);
console.error(reporter(file));remark-lint follows the unified plugin architecture:
The core capability that enables authors to ignore or control lint messages using HTML comments embedded in markdown documents.
/**
* Add support for configuration comments to control remark lint rule messages.
* This is the main and only export of the remark-lint package.
*
* When used as a unified plugin, this function registers a transformer that enables
* configuration comments like <!--lint ignore--> in markdown documents.
* The function calls this.use() internally to register the message control transformer.
*
* @this {Processor} - Unified processor instance (plugin is bound to this context)
* @returns {undefined} - No explicit return value (modifies processor via this.use())
*/
export default function remarkLint(): undefined;Configuration Comment Syntax:
<!-- Ignore all lint rules for the next content -->
<!--lint ignore-->
<!-- Disable specific rule -->
<!--lint disable rule-name-->
<!-- Enable specific rule -->
<!--lint enable rule-name-->
<!-- Disable multiple rules -->
<!--lint disable rule-name-1 rule-name-2-->Usage with Lint Rules:
import {unified} from 'unified';
import remarkParse from 'remark-parse';
import remarkLint from 'remark-lint';
import remarkLintFinalNewline from 'remark-lint-final-newline';
import remarkLintNoHeadingPunctuation from 'remark-lint-no-heading-punctuation';
const processor = unified()
.use(remarkParse)
.use(remarkLint) // Must be included for comment support
.use(remarkLintFinalNewline)
.use(remarkLintNoHeadingPunctuation);
const file = await processor.process(markdownContent);Integration Patterns:
// Can be used before lint rules
const processor1 = unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintFinalNewline);
// Can be used after lint rules
const processor2 = unified()
.use(remarkParse)
.use(remarkLintFinalNewline)
.use(remarkLint);
// Both patterns provide identical functionalityRule Configuration:
// Rules can be configured with severity levels
unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintFinalNewline, [2]) // Error level (fatal)
.use(remarkLintNoHeadingPunctuation, true) // Warning level
.use(remarkLintNoUndefinedReferences, false); // Disabled/**
* Internal helper function that configures remark-message-control.
* This function is not directly exported but is used internally by remarkLint.
* It calls remarkMessageControl with the appropriate configuration for lint messages.
*
* @returns {Function} Transform function from remark-message-control configured for lint
*/
function lintMessageControl(): Function;remark-lint integrates with the vfile message system to provide consistent error reporting:
Example Error Output:
virtual.md:3:1-3:24: Unexpected character `.` at end of heading, remove it
3:1-3:24 warning no-heading-punctuation remark-lint