Skip to content

feat: add frontmatterTitle option to heading-increment #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xbinaryx
Copy link
Contributor

@xbinaryx xbinaryx commented Jul 1, 2025

Prerequisites checklist

What is the purpose of this pull request?

This pull request adds a new frontmatterTitle option to the heading-increment rule. The rule will treat a frontmatter title as a level 1 heading for the purpose of heading increment checks, ensuring that heading levels are not skipped after a frontmatter title.

What changes did you make? (Give an overview)

  • Added a frontmatterTitle option to the heading-increment rule, allowing users to specify a regex pattern to detect a title in frontmatter blocks.
  • Added tests to verify the new behavior.
  • Updated documentation to describe the new option and its usage.

Related Issues

Fixes #443

Is there anything you'd like reviewers to focus on?

@lumirlumir lumirlumir added this to Triage Jul 1, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jul 1, 2025
@nzakas nzakas requested a review from Copilot July 2, 2025 15:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a frontmatterTitle option to the heading-increment rule so that a matching title in frontmatter counts as an H1, preventing skipped-heading errors. It adds a helper, integrates frontmatter handlers, expands tests, and updates documentation.

  • Introduce frontmatterHasTitle in util.js and use it in heading-increment
  • Expand heading-increment rule with schema, default options, and frontmatter listeners
  • Add tests covering YAML/TOML/JSON frontmatter variations and update docs

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/rules/heading-increment.test.js Added valid/invalid cases for frontmatter title handling
src/util.js Added frontmatterHasTitle helper
src/rules/no-multiple-h1.js Imported helper and updated JSDoc typedefs (unused import)
src/rules/heading-increment.js Added schema, defaultOptions, and YAML/TOML/JSON handlers
docs/rules/heading-increment.md Documented new frontmatterTitle option

@@ -7,14 +7,17 @@
// Imports
//-----------------------------------------------------------------------------

import { findOffsets } from "../util.js";
import { findOffsets, frontmatterHasTitle } from "../util.js";
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imported frontmatterHasTitle is never used in this rule. Either integrate it to support a frontmatterTitle option or remove the unused import.

Copilot uses AI. Check for mistakes.


//-----------------------------------------------------------------------------
// Type Definitions
//-----------------------------------------------------------------------------

/**
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: [{ frontmatterTitle?: string; }]; }>}
* @import { MarkdownRuleDefinition } from "../types.js";
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc does not recognize @import as a type declaration. Replace this with a valid import-based typedef, e.g., @typedef {import("../types.js").MarkdownRuleDefinition<...>} NoMultipleH1RuleDefinition.

Suggested change
* @import { MarkdownRuleDefinition } from "../types.js";
* @typedef {import("../types.js").MarkdownRuleDefinition} MarkdownRuleDefinition

Copilot uses AI. Check for mistakes.

Comment on lines 17 to 20
* @import { MarkdownRuleDefinition } from "../types.js";
* @typedef {"skippedHeading"} HeadingIncrementMessageIds
* @typedef {[{ frontmatterTitle?: string }]} HeadingIncrementOptions
* @typedef {MarkdownRuleDefinition<{ RuleOptions: HeadingIncrementOptions, MessageIds: HeadingIncrementMessageIds }>}
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc does not support an @import tag for types. Use @typedef {import("../types.js").MarkdownRuleDefinition<...>} HeadingIncrementRuleDefinition to ensure the type is correctly recognized.

Suggested change
* @import { MarkdownRuleDefinition } from "../types.js";
* @typedef {"skippedHeading"} HeadingIncrementMessageIds
* @typedef {[{ frontmatterTitle?: string }]} HeadingIncrementOptions
* @typedef {MarkdownRuleDefinition<{ RuleOptions: HeadingIncrementOptions, MessageIds: HeadingIncrementMessageIds }>}
* @typedef {"skippedHeading"} HeadingIncrementMessageIds
* @typedef {[{ frontmatterTitle?: string }]} HeadingIncrementOptions
* @typedef {import("../types.js").MarkdownRuleDefinition<{ RuleOptions: HeadingIncrementOptions, MessageIds: HeadingIncrementMessageIds }>}

Copilot uses AI. Check for mistakes.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

Rule Change: Add frontmatterTitle option to heading-increment
3 participants