Gathering detailed insights and metrics for remark-lint-frontmatter-schema
Gathering detailed insights and metrics for remark-lint-frontmatter-schema
Gathering detailed insights and metrics for remark-lint-frontmatter-schema
Gathering detailed insights and metrics for remark-lint-frontmatter-schema
@julian_cataldo/remark-lint-frontmatter-schema
!!!⚠️ MOVED to → `remark-lint-frontmatter-schema` ⚠️!!! — Validate Markdown frontmatter YAML against an associated JSON schema — remark-lint rule plugin
content-maestro
A text based, structured content framework, for edition and consumption.
Validate your Markdown frontmatter data against a JSON schema — remark-lint rule plugin
npm install remark-lint-frontmatter-schema
Typescript
Module System
Node Version
NPM Version
92.1
Supply Chain
100
Quality
75.4
Maintenance
50
Vulnerability
98.9
License
TypeScript (94.83%)
JavaScript (5.17%)
Total Downloads
1,993,458
Last Day
2,887
Last Week
21,776
Last Month
74,234
Last Year
1,348,137
ISC License
61 Stars
299 Commits
7 Forks
3 Watchers
7 Branches
4 Contributors
Updated on Jun 24, 2025
Minified
Minified + Gzipped
Latest Version
3.15.4
Package Id
remark-lint-frontmatter-schema@3.15.4
Unpacked Size
48.67 kB
Size
14.97 kB
File Count
7
NPM Version
9.8.1
Node Version
18.18.0
Published on
Oct 15, 2023
Cumulative downloads
Total Downloads
Last Day
35.1%
2,887
Compared to previous day
Last Week
30.5%
21,776
Compared to previous week
Last Month
-7.2%
74,234
Compared to previous month
Last Year
111.1%
1,348,137
Compared to previous year
28
remark-lint-frontmatter-schema
📑Validate Markdown frontmatter YAML against an associated JSON schema with this remark-lint rule plugin.
Supports:
(w. Astro Content — Editor)
Jump to:
Quick shallow clone with:
1pnpx degit JulianCataldo/remark-lint-frontmatter-schema/demo ./demo
1pnpm install -D \ 2remark remark-cli \ 3remark-frontmatter \ 4remark-lint-frontmatter-schema
Remove
-D
flag for runtimeunified
MD / MDX pipeline (custom, Astro, Gatsby, etc.), for production.
Keep it if you just want to lint with CLI or your IDE locally, without any production / CI needs.
1code --install-extension unifiedjs.vscode-remark
👉 See ./demo folder to get a working, pre-configured, bare project workspace.
You also get example Markdown files and associated schema to play with.
Supports remark-cli
and/or unifiedjs.vscode-remark
extension.
📌 Check out the demo/README.md for bootstrapping it.
Create the root config. file for remark
to source from:
touch ./.remarkrc.mjs
Paste this base configuration:
1import remarkFrontmatter from 'remark-frontmatter'; 2import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema'; 3 4const remarkConfig = { 5 plugins: [remarkFrontmatter, remarkLintFrontmatterSchema], 6}; 7export default remarkConfig;
You can use YAML / JSON / …, too (uses cosmiconfig).
./content/creative-work.schema.yaml
1type: object 2properties: 3 title: 4 type: string 5# …
Referencing schema definitions allows re-using bit and piece instead of duplicate them, accross your content schemas.
You can reference an external schema relatively, using $ref
.
For example we can -kind of- merge an host object with a reference properties:
The host schema, content/articles/index.schema.yaml
1allOf: 2 - $ref: ../page.schema.yaml 3 4 - properties: 5 layout: 6 const: src/layouts/Article.astro 7 category: 8 type: string 9 enum: 10 - Book 11 - Movie 12 foo: 13 type: string 14 15 required: 16 - layout 17 - category
A referenced schema, content/page.schema.yaml
1properties: 2 title: 3 type: string 4 maxLength: 80 5 # ... 6 # ... 7 8required: 9 - title
The result will be (virtually) the same as this:
1properties: 2 title: 3 type: string 4 maxLength: 80 5 # ... 6 # ... 7 layout: 8 const: src/layouts/Article.astro 9 category: 10 type: string 11 enum: 12 - Book 13 - Movie 14 foo: 15 type: string 16 # ... 17 18required: 19 - title 20 - layout 21 - category
Inspired by VS Code JSON Schema
and redhat.vscode-yaml
conventions.
See ./demo/content files for examples.
Schema association can be done directly inside the frontmatter of the Markdown file,
relative to project root, thanks to the '$schema'
key:
1--- 2# From workspace root (`foo/…`, `/foo/…` or `./foo/…` is the same) 3'$schema': content/creative-work.schema.yaml 4 5# —Or— relatively, from this current file directory (`./foo/…` or `../foo/…`) 6# '$schema': ../creative-work.schema.yaml 7 8layout: src/layouts/Article.astro 9 10title: Hello there 11category: Book 12# … 13--- 14 15# You're welcome! 16 17🌝 My **Markdown** content… 🌚 18…
Note:
Locally defined'$schema'
takes precedence over global settings below.
1const remarkConfig = { 2 plugins: [ 3 remarkFrontmatter, 4 [ 5 remarkLintFrontmatterSchema, 6 { 7 schemas: { 8 /* One schema for many files */ 9 './content/creative-work.schema.yaml': [ 10 /* Per-file association */ 11 './content/creative-work/the-shipwreck__global-broken.md', 12 13 /* Support glob patterns ———v */ 14 // './content/creative-work/*.md', 15 // … 16 // `./` prefix is optional 17 // 'content/creative-work/foobiz.md', 18 ], 19 20 // './content/ghost.schema.yaml': [ 21 // './content/casper.md', 22 // './content/ether.md', 23 // ], 24 }, 25 }, 26 ], 27 ], 28};
'./foo'
, '/foo'
, 'foo'
, all will work.
It's always relative to your ./.remarkrc.mjs
file, in your workspace root.
Linting whole workspace files (as ./**/*.md
) with remark-cli
:
1pnpm remark .
Yields:
First, install the YAML for Visual Studio Code extension:
1code --install-extension redhat.vscode-yaml
Then, add this to your .vscode/settings.json
:
1{ 2 "yaml.schemas": { 3 "http://json-schema.org/draft-07/schema#": ["content/**/*.schema.yaml"] 4 } 5 /* ... */ 6}
Will work with the ESLint VS Code extension and the CLI command.
Install the ESLint MDX plugin, the MDX VS Code extension and the ESLint VS Code extension.
Add this dependencies to your project:
1pnpm i -D eslint eslint-plugin-mdx \ 2eslint-plugin-prettier eslint-config-prettier
Add a .eslintrc.cjs
:
1/** @type {import("@types/eslint").Linter.Config} */ 2 3module.exports = { 4 overrides: [ 5 { 6 files: ['*.md', '*.mdx'], 7 extends: ['plugin:mdx/recommended'], 8 }, 9 ], 10};
Add a .remarkrc.yaml
(or JSON, etc.), e.g.:
1plugins: 2 - remark-frontmatter 3 4 - - remark-lint-frontmatter-schema 5 - schemas: 6 src/schemas/blog-post.schema.yaml: 7 - content/blog-posts/*.{md,mdx} 8 9 # - remark-preset-lint-consistent 10 # - remark-preset-lint-markdown-style-guide 11 # - remark-preset-lint-recommended
Result:
Lint with CLI:
1pnpm eslint --ext .mdx .
Efforts has been made to have the best output for both remark and ESLint, for IDE extensions and CLIs.
enum
values suggestions are working with the remark extension, not with the ESLint one.eslint-plugin-mdx@2
, .remarkrc.mjs
(ES Module) is not loaded, JSON and YAML configs are fine.Use it as usual like any remark plugin inside your framework or your custom unified
pipeline.
When processing Markdown as single files inside your JS/TS app.
An minimal example is provided in ./demo/pipeline.ts
, you can launch it with pnpm pipeline
from ./demo
.
Schema should be provided programmatically like this:
1// … 2import remarkFrontmatter from 'remark-frontmatter'; 3import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema'; 4import type { JSONSchema7 } from 'json-schema'; 5import { reporter } from 'vfile-reporter'; 6 7const mySchema: JSONSchema7 = { 8 /* … */ 9}; 10 11const output = await unified() 12 // Your pipeline (basic example) 13 .use(remarkParse) 14 // … 15 .use(remarkFrontmatter) 16 17 .use(remarkLintFrontmatterSchema, { 18 /* Bring your own schema */ 19 embed: mySchema, 20 }) 21 22 // … 23 .use(remarkRehype) 24 .use(rehypeStringify) 25 .use(rehypeFormat) 26 .process(theRawMarkdownLiteral); 27 28/* `path` is for debugging purpose here, as MD literal comes from your app. */ 29output.path = './the-current-processed-md-file.md'; 30 31console.error(reporter([output]));
Yields:
./the-current-processed-md-file.md
1:1 warning Must have required property 'tag' frontmatter-schema remark-lint
⚠ 1 warning
Checkout Astro Content repository.
Astro Content relies on this library, among others, for providing linting reports.
This is different from static linting, with VS Code extension or CLI.
It will not source .remarkrc
(but you can source it by your own means, if you want).
In fact, it's not aware of your file structure,
nor it will associate or import any schema / Markdown files.
That way, it will integrate easier with your own business logic and existing pipelines.
I found that static linting (during editing) / and runtime validation are two different
uses cases enough to separate them in their setups, but I might converge them partially.
Warning
WIP. NOT tested yet! It is not a common use case forremark-lint
.
Linting data inside frameworks are generally ignored.
AFAIK,messages
data isn't forwarded to CLI output.
Feel free to open a PR if you have some uses cases in this area that need special care.
Maybe Astro or Astro Content could leverage these linter warnings in the future.
See global patterns schemas
associations for settings reference.
In astro.config.mjs
1// … 2export default defineConfig({ 3 // … 4 remarkPlugins: [ 5 // … 6 'remark-frontmatter', 7 ['remark-lint-frontmatter-schema', { schemas }], 8 // … 9 ]; 10 // … 11});
In gatsby-config.js
1{ 2 // … 3 plugins: [ 4 // … 5 { 6 resolve: 'gatsby-transformer-remark', 7 options: { 8 plugins: [ 9 // … 10 'remark-frontmatter', 11 ['remark-lint-frontmatter-schema', { schemas }], 12 // … 13 ], 14 }, 15 }, 16 // … 17 ]; 18}
1export interface Settings { 2 /** 3 * Global workspace file associations mapping (for linter extension). 4 * 5 * **Example**: `'schemas/thing.schema.yaml': ['content/things/*.md']` 6 */ 7 schemas?: Record<string, string[]>; 8 9 /** 10 * Direct schema embedding (for using inside an `unified` transform pipeline). 11 * 12 * Format: JSON Schema - draft-2019-09 13 * 14 * **Documentation**: https://ajv.js.org/json-schema.html#draft-07 15 */ 16 embed?: JSONSchema7; 17 18 /** 19 * **Documentation**: https://ajv.js.org/options.html 20 */ 21 ajvOptions?: AjvOptions; 22} 23 24export interface FrontmatterSchemaMessage extends VFileMessage { 25 schema: AjvErrorObject & { url: JSONSchemaReference }; 26}
Example of a VFileMessage
content you could collect from this lint rule:
1[ 2 // … 3 { 4 // JS native `Error` 5 "name": "Markdown YAML frontmatter error (JSON Schema)", 6 "message": "Keyword: type\nType: string\nSchema path: #/properties/title/type", 7 8 // `VFileMessage` (Linter / VS Code…) 9 "reason": "/clientType: Must be equal to one of the allowed values", 10 "line": 16, 11 "column": 13, 12 "url": "https://github.com/JulianCataldo/remark-lint-frontmatter-schema", 13 "source": "remark-lint", 14 "ruleId": "frontmatter-schema", 15 "position": { 16 "start": { 17 "line": 16, 18 "column": 13 19 }, 20 "end": { 21 "line": 16, 22 "column": 24 23 } 24 }, 25 "fatal": false, 26 "actual": "Individuaaaaaaaal", 27 "expected": ["Corporate", "Non-profit", "Individual"], 28 // Condensed string, human readable version of AJV error object 29 "note": "Keyword: enum\nAllowed values: Corporate, Non-profit, Individual\nSchema path: #/properties/clientType/enum", 30 31 // AJV's `ErrorObject` 32 "schema": { 33 "url": "https://ajv.js.org/json-schema.html", 34 "instancePath": "/clientType", 35 "schemaPath": "#/properties/clientType/enum", 36 "keyword": "enum", 37 "params": { 38 "allowedValues": ["Corporate", "Non-profit", "Individual"] 39 }, 40 "message": "must be equal to one of the allowed values" 41 } 42 } 43]
100% ESM, including dependencies.
Environments:
Remark lint | https://github.com/remarkjs/remark-lint
VS Code
unifiedjs.vscode-remark
https://github.com/remarkjs/vscode-remark
Major dependencies:
ajv
, yaml
, remark
, remark-frontmatter
, unified
, remark-cli
See CHANGELOG.md for release history.
Other projects 👀…
github
→ ✅ GitHub
.remark
plugin for embedding remote / local Markdown or code snippets.No vulnerabilities found.
No security vulnerabilities found.