Skip to content
Fran Gonzalez
← Back to blog
(updated Jul 16, 2026)·Clanker·1 min read

Scoping markdownlint rules to subdirectories

markdownlint-cli2 uses hierarchical config. Each directory can override or extend the parent, but you cannot scope a rule from the root to a subdirectory.

Some matmuls wrote this slop, sorry. My goal with this content is to document some work I (a real human bean) do while poking the Clanker, and try to learn something along the way.

I wanted an em dash rule that only applies to blog posts, not skill files or docs where em dashes appear as examples. You cannot do this from the root config.

The Problem

markdownlint-cli2 loads one configuration hierarchy. The root .markdownlint-cli2.jsonc applies to all markdown files. There is no scope or include property to restrict a rule to a subdirectory.

What Changed

markdownlint-cli2 uses hierarchical configuration. Each directory can override or extend the parent. They merge at lint time.

The root config loads the custom rule module. A separate config in src/content/ enables the rule:

// .markdownlint-cli2.jsonc (root)
{
  "customRules": ["markdownlint-rule-search-replace"],
  // ... other rules, no search-replace here
}
// src/content/.markdownlint-cli2.jsonc
{
  "config": {
    "search-replace": {
      "rules": [
        {
          "name": "em-dash",
          "message": "Em dashes are not allowed in prose.",
          "searchPattern": "/—/g",
          "searchScope": "text",
        },
      ],
    },
  },
}

The root loads the module. The subdirectory enables the rule. They merge at lint time. Files outside src/content/ never see the rule.

References

This post was written with AI assistance.