A remark preset to configure remark-lint with rules that prevent mistakes or stuff that fails across vendors.
npx @tessl/cli install tessl/npm-remark-preset-lint-recommended@6.1.0remark-preset-lint-recommended is a unified (remark) preset that configures remark-lint with a curated collection of rules designed to prevent mistakes and ensure consistent markdown rendering across different vendors. It provides a standardized approach to markdown linting with rules for Unix compatibility, consistent formatting, and common mistake prevention.
npm install remark-preset-lint-recommendedDeno:
import remarkPresetLintRecommended from 'https://esm.sh/remark-preset-lint-recommended@6';Browser:
<script type="module">
import remarkPresetLintRecommended from 'https://esm.sh/remark-preset-lint-recommended@6?bundle';
</script>ES Module:
import remarkPresetLintRecommended from 'remark-preset-lint-recommended';CommonJS:
const remarkPresetLintRecommended = require('remark-preset-lint-recommended');import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkPresetLintRecommended from 'remark-preset-lint-recommended'
main()
async function main() {
const file = await remark()
.use(remarkPresetLintRecommended)
.process(await read('example.md'))
console.error(reporter(file))
}CLI usage:
remark --use remark-preset-lint-recommended example.mdPackage.json configuration:
{
"remarkConfig": {
"plugins": [
"remark-preset-lint-recommended"
]
}
}The main export is a unified preset that provides a comprehensive linting configuration.
const remarkPresetLintRecommended: Preset;The preset contains a curated collection of 15 remark-lint rules organized into three categories:
Unix Compatibility:
remark-lint-final-newline - Ensures files end with a newlineConsistent Rendering:
remark-lint-list-item-bullet-indent - Ensures consistent list item bullet indentationremark-lint-list-item-indent - Enforces tab-size indentation for list itemsremark-lint-no-blockquote-without-marker - Requires blockquote markersremark-lint-no-literal-urls - Prevents literal URLsremark-lint-ordered-list-marker-style - Uses '.' style for ordered listsMistake Prevention:
remark-lint-hard-break-spaces - Manages hard break spacesremark-lint-no-duplicate-definitions - Prevents duplicate definitionsremark-lint-no-heading-content-indent - Prevents heading content indentationremark-lint-no-inline-padding - Prevents inline paddingremark-lint-no-shortcut-reference-image - Prevents shortcut reference imagesremark-lint-no-shortcut-reference-link - Prevents shortcut reference linksremark-lint-no-undefined-references - Prevents undefined referencesremark-lint-no-unused-definitions - Prevents unused definitionsThe preset follows the unified Preset interface:
interface Preset {
plugins?: PluggableList;
settings?: Record<string, unknown>;
}
type PluggableList = Array<Pluggable>;
type Pluggable = Plugin | PluginTuple | Preset;Two rules are configured with specific settings:
// List item indentation uses tab-size
[remarkLintListItemIndent, 'tab-size']
// Ordered list markers use period style
[remarkLintOrderedListMarkerStyle, '.']All other rules use their default configurations.
The preset is compatible with the unified ecosystem types:
// From unified
interface Preset {
plugins?: PluggableList;
settings?: Record<string, unknown>;
}
type PluggableList = Array<Pluggable>;
type Pluggable = Plugin | PluginTuple | Preset;
type Plugin = (this: Processor, ...args: any[]) => Transformer | void;
type PluginTuple = [Plugin, ...any[]];
interface Transformer {
(tree: Node, file: VFile): Promise<Node | null | undefined> | Node | null | undefined;
}
// From @types/mdast
type Node = import('@types/mdast').Node;
// From vfile
interface VFile {
readonly path?: string;
readonly basename?: string;
readonly stem?: string;
readonly extname?: string;
readonly dirname?: string;
readonly history: string[];
readonly messages: VFileMessage[];
data: {[key: string]: unknown};
value: string | Uint8Array;
}import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
import {unified} from 'unified';
import remarkParse from 'remark-parse';
const processor = unified()
.use(remarkParse)
.use(remarkPresetLintRecommended);import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
import {unified} from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
const processor = unified()
.use(remarkParse)
.use(remarkPresetLintRecommended)
.use(remarkStringify, {
bullet: '*',
emphasis: '*',
fences: true
});Rules can be reconfigured after applying the preset:
import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
import remarkLintOrderedListMarkerStyle from 'remark-lint-ordered-list-marker-style';
import {unified} from 'unified';
const processor = unified()
.use(remarkPresetLintRecommended)
// Override the ordered list marker style
.use(remarkLintOrderedListMarkerStyle, ')');