Registry / serialization / remark-lint-frontmatter-schema

remark-lint-frontmatter-schema

JSON →
library3.15.4jsnpmunverified

Validate Markdown frontmatter YAML against an associated JSON schema using remark-lint. Current version: 3.15.4 (released Oct 2023). Released regularly with bug fixes. Key differentiators: supports JSON Schema draft-07, both in-file $schema and global pattern associations, auto-fixes, integration with VS Code and ESLint MDX, and CLI reporting. Uses ajv for validation.

npm install remark-lint-frontmatter-schema
INSTALL
IMPORT
SIG · REMARK-LINT-FRONTM
R
remark-lint-frontmatter-schema
serializationjavascriptv3.15.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

remarkLintFrontmatterSchema
import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema'
const { remarkLintFrontmatterSchema } = require('remark-lint-frontmatter-schema')
Default export is a function that returns a remark plugin. CommonJS require is also supported.
default
const plugin = require('remark-lint-frontmatter-schema')
const { default: plugin } = require('remark-lint-frontmatter-schema')
In CJS, default export is accessed directly via require, not destructured.
remarkLintFrontmatterSchema
import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema'
import { remarkLintFrontmatterSchema } from 'remark-lint-frontmatter-schema'
This is a default export, not named export. Named import will result in undefined.

Set up a remark processor with remark-lint and remark-lint-frontmatter-schema, validate frontmatter against a JSON schema, and see lint messages.

import { readSync } from 'fs'; import { remark } from 'remark'; import remarkLint from 'remark-lint'; import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema'; const processor = remark() .use(remarkLint) .use(remarkLintFrontmatterSchema, { schemas: [ { pattern: '*.md', schema: { type: 'object', properties: { title: { type: 'string' }, date: { type: 'string', format: 'date' } }, required: ['title', 'date'] } } ] }); const result = processor.processSync( '---\ntitle: Hello\ndate: 2023-01-01\n---\n# Content' ); console.log(result.messages); // [] (no errors) const result2 = processor.processSync( '---\ntitle: 123\ndate: not-a-date\n---\n# Content' ); console.log(result2.messages); // [ { message: 'title: must be string', ... } ]
Debug
Known issues
gotchaSchema must be a valid JSON Schema (draft-07) object. Invalid schemas will fail silently or throw obscure errors.
fix
Validate your schema against JSON Schema meta-schema before use.
affects: >=3.0.0
breakingFrom v3.0.0, the plugin changed from a custom configuration format to using a `schemas` array with `pattern` and `schema` objects. Old `schemaPath` option removed.
fix
Update configuration to new format: { schemas: [{ pattern: '*.md', schema: {...} }] }
affects: >=3.0.0
deprecatedThe `schemaPath` option was deprecated in v3.0.0 and removed in v3.14.0.
fix
Use `schemas` array with inline schema or `$ref` to external file.
affects: >=3.14.0
gotchaIn-file `$schema` key in frontmatter is only supported if the schema URL is an HTTP(S) URL or a relative file path. Absolute file paths are not supported.
fix
Use relative paths (e.g., `$schema: ./schema.json`) or a URL. For local schemas, ensure the file resolves relative to the working directory.
affects: >=3.13.0
gotchaThe plugin only validates the first YAML block in the Markdown file even if multiple YAML blocks exist. It treats the first YAML as frontmatter.
fix
Ensure that only one YAML frontmatter block exists, or the first one is the intended frontmatter.
affects: >=3.15.3
Errors
Common errors & fixes
Error: Cannot find module 'remark-lint-frontmatter-schema'
Package not installed or incorrect import path.
fix
Run `npm install remark-lint-frontmatter-schema` and ensure import path is correct.
TypeError: plugin is not a function
Importing the module incorrectly (e.g., named import instead of default).
fix
Use default import: `import plugin from 'remark-lint-frontmatter-schema'`
ValidationError: data must have required property 'title'
Frontmatter missing required fields as per schema.
fix
Add the missing required fields to the frontmatter YAML.
Error: No schema defined for pattern '*.md'
Glob pattern in configuration doesn't match any defined schema.
fix
Check the `schemas` array configuration and ensure the pattern matches the file being processed.
Upgrade
Version history
3.15.4latest on npm
Audit
Dependencies
unifiedrequiredRequired for remark-lint plugin integration
remark-lintrequiredRequired for lint rule base
ajvrequiredUsed for JSON Schema validation
yamlrequiredUsed to parse frontmatter YAML
Agent activity
2 hits · last 30 days
node
2
Resources
remark-lint-frontmatter-schema — npm install remark-lint-frontmatter-schema · libregistry