formatYamlFrontmatter
Format YAML frontmatter using proper YAML formatting rules.
Options
| Property | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable/disable this rule |
indent | number | 2 | Number of spaces for YAML indentation |
lineWidth | number | 100 | Maximum line width for folded strings |
quotingType | string | "\"" | Quote type for strings: "\"" or "'" |
forceQuotes | boolean | false | Force quotes on all string values |
noCompatMode | boolean | true | Use 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
---