Skip to content

fix(generator): let expr win over pattern and guard empty filenames - #85

Merged
jackchuka merged 1 commit into
mainfrom
fix/generator-expr-precedence
Aug 27, 2026
Merged

fix(generator): let expr win over pattern and guard empty filenames#85
jackchuka merged 1 commit into
mainfrom
fix/generator-expr-precedence

Conversation

@jackchuka

Copy link
Copy Markdown
Owner

Follow-up to #84 — two cases where generate still emits a file that fails its own check.

1. Inverted precedence vs. the matcher

resolveHeadingText resolved the filename only when Pattern == "" && Literal == "" && Expr != "", but vast.PatternMatcher.MatchesHeading checks Expr first and ignores Pattern/Literal when it is set. Nothing rejects a heading carrying both keys, so:

structure:
  - heading:
      pattern: "^# .+$"
      expr: "filename == heading"
$ mdschema generate s.yml -o out/Bar.md
$ head -1 out/Bar.md
# ^# .+$
$ mdschema check --schema s.yml out/Bar.md
✗ 1:3 [structure] Heading "# ^# .+$" does not match expression "filename == heading"

Now gated on hp.Expr != "" && outputPath != "", mirroring MatchesHeading. Output is # Bar, check passes.

2. Missing filename == "" guard

matchesHeadingExpr returns early when the extracted filename is empty; resolveHeadingText did not. For an output path whose base is only an extension (-o out/.md), filename == heading evaluated "" == "" → true and a bare # heading was written — one that check time, with the guard in place, can never accept. The generator now falls back to the expression text for that case.

Tests

  • docs/.md row added to TestGenerateExprHeading
  • new TestGenerateExprWinsOverPatternAndLiteral

go build ./... and go test ./... pass.

resolveHeadingText only resolved the filename when neither pattern nor
literal was set, but PatternMatcher.MatchesHeading checks expr first and
ignores pattern/literal entirely. A schema with both pattern and expr
still generated a file that failed its own check.

It also lacked the `filename == ""` guard that matchesHeadingExpr has, so
an output path like `out/.md` evaluated `"" == ""` to true and emitted a
bare `# ` heading that check time can never accept.
@jackchuka
jackchuka marked this pull request as ready for review August 27, 2026 17:29
@jackchuka
jackchuka merged commit c6c04c7 into main Aug 27, 2026
1 check passed
@jackchuka
jackchuka deleted the fix/generator-expr-precedence branch August 27, 2026 17:29
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 28, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jackchuka/mdschema](https://github.com/jackchuka/mdschema) | patch | `v0.15.1` → `v0.15.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jackchuka/mdschema (jackchuka/mdschema)</summary>

### [`v0.15.2`](https://github.com/jackchuka/mdschema/releases/tag/v0.15.2)

[Compare Source](jackchuka/mdschema@v0.15.1...v0.15.2)

#### What's Changed

- fix(generator): resolve expr-based headings to the target filename by [@&#8203;toiroakr](https://github.com/toiroakr) in [#&#8203;84](jackchuka/mdschema#84)
- fix(generator): let expr win over pattern and guard empty filenames by [@&#8203;jackchuka](https://github.com/jackchuka) in [#&#8203;85](jackchuka/mdschema#85)

#### New Contributors

- [@&#8203;toiroakr](https://github.com/toiroakr) made their first contribution in [#&#8203;84](jackchuka/mdschema#84)

**Full Changelog**: <jackchuka/mdschema@v0.15.1...v0.15.2>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yODguMCIsInVwZGF0ZWRJblZlciI6IjQzLjI4OC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6cGF0Y2giXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant