markdown/fenced-code-meta

Require or disallow metadata for fenced code blocks

The text after the language on the opening fence is the block's metadata. Many documentation tools read a title, a file name or the lines to highlight from it. This rule keeps a project consistent: either every block with a language has metadata, or none does.

Configure#

Off by default. It needs an ESLint config that says which files are in the language:

eslint.config.js
import markdown from "@eslint/markdown";

export default [
  {
    files: ["**/*.md"],
    plugins: { markdown },
    language: "markdown/commonmark",
    rules: { "markdown/fenced-code-meta": "error" },
  },
];

It also works with markdown/gfm.

Examples#

example.md1 problem
```js
const port = 3000;
```
example.mdNo problems
```js title="server.js"
const port = 3000;
```

A block without a language is not reported:

example.mdNo problems
```
const port = 3000;
```

Options#

OptionWhat it does
"always" (default)A block that has a language needs metadata too.
"never"No block can have anything after its language.
example.mdwith "never"1 problem
```js title="server.js"
const port = 3000;
```
example.mdwith "never"No problems
```js
const port = 3000;
```