Skip to main content
  • Created:
  • Updated:
  • Author:
    Takeshi Takatsudo

formatYamlFrontmatter

Format YAML frontmatter using proper YAML formatting rules.

Options

PropertyTypeDefaultDescription
enabledbooleantrueEnable/disable this rule
indentnumber2Number of spaces for YAML indentation
lineWidthnumber100Maximum line width for folded strings
quotingTypestring"\""Quote type for strings: "\"" or "'"
forceQuotesbooleanfalseForce quotes on all string values
noCompatModebooleantrueUse YAML 1.2 spec (not 1.1)

Config

{
"formatYamlFrontmatter": {
"enabled": true,
"indent": 2,
"lineWidth": 80,
"quotingType": "'",
"forceQuotes": false,
"noCompatMode": true
}
}

Examples

Remove unnecessary quotes and extra blank lines

Before:

---
title: "Test Article"

description: "A long description"

tags:

- tag1
- tag2
---

# Content

After:

---
title: Test Article
description: A long description
tags:
- tag1
- tag2
---

# Content

Normalize inline arrays to block style

Before:

---
title: "Article Title"
tags: [tag1, tag2, tag3]
---

After:

---
title: Article Title
tags:
- tag1
- tag2
- tag3
---

Complex frontmatter

Before:

---
title: "My Post"
date: 2024-01-15
author: "John Doe"
categories: [blog, tech]
draft: false
---

After:

---
title: My Post
date: 2024-01-15
author: John Doe
categories:
- blog
- tech
draft: false
---