Skip to content

Make table-syntax validation error location more precise - #605

Merged
yue-stripe merged 6 commits into
mainfrom
yue/table-validation-error-location
Mar 24, 2026
Merged

yue-stripe merged 6 commits into
mainfrom
yue/table-validation-error-location

Conversation

@yue-stripe

@yue-stripe yue-stripe commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary & motivation

#603 added validation for invalid table syntax. However, all the errors report their location at the first line of the {% table %} tag, making it hard to pinpoint where the actually invalid syntax is in large complex tables.

This change attaches the offending node's location to the ValidationError and updates validateTree to prefer it over the parent node's location.

Also bumps version to 0.5.7 for a future release.

Test plan

  • Table validation tests updated to assert errors point to the offending node
  • All tests pass

Table syntax errors were all reported at the table tag's location,
making it hard to find the offending content. Now errors carry the
location of the invalid node, and validateTree prefers it over the
parent node's location.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude
@yue-stripe
yue-stripe requested a review from Copilot March 11, 2026 02:47
@yue-stripe yue-stripe changed the title Yue/table validation error location Make validation error location more precise from #603 Mar 11, 2026
@yue-stripe yue-stripe changed the title Make validation error location more precise from #603 Make table-syntax validation error location more precise Mar 11, 2026
@yue-stripe
yue-stripe force-pushed the yue/table-validation-error-location branch from 91e6af5 to ee7ecb6 Compare March 11, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Improves Markdoc table-syntax validation diagnostics by reporting errors at the offending node location (instead of always pointing at the {% table %} tag), and bumps the package version for a future release.

Changes:

  • Attach location to table-syntax ValidationErrors based on the offending node in the table transform.
  • Update validateTree to prefer ValidationError.location over the parent node’s location when producing ValidateErrors.
  • Update table validation tests to assert the more precise error location; bump version to 0.5.7.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/validator.ts Prefer error.location when emitting validation errors to improve pinpointing.
src/transforms/table.ts Populate ValidationError.location from the offending AST node for table-syntax errors.
src/transforms/table.test.ts Update assertions to expect errors to point to the invalid content.
package.json Bump package version to 0.5.7.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/validator.ts Resolved
Comment thread package.json Resolved
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/validator.ts Resolved
…ocations

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/validator.ts Resolved
Comment thread src/validator.ts Resolved
@yue-stripe
yue-stripe force-pushed the yue/table-validation-error-location branch from 091acbb to f03be80 Compare March 11, 2026 14:56
@yue-stripe
yue-stripe force-pushed the yue/table-validation-error-location branch from f03be80 to b6bf880 Compare March 11, 2026 15:03
Comment thread src/validator.ts
if (hasValidLocation(error)) {
return {
type: node.type,
lines: [error.location.start.line, error.location.end.line],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lines is initially set by parser here:

node.lines = token.map || parent.lines || [];

Without overriding the lines in this case, the line numbers in lines would be inconsistent with location.start.line and location.end.line

@yue-stripe
yue-stripe requested a review from a team March 24, 2026 17:05
Comment thread package.json Outdated
"name": "@markdoc/markdoc",
"author": "Ryan Paul",
"version": "0.5.6",
"version": "0.5.7",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we bump the package separately of this change? I'll bump the version in a separate PR!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread package-lock.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this needs to be unbumped too!

@yue-stripe yue-stripe Mar 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The version in package-lock was originally not matching the package.json (we're on 0.5.6) which Copilot flagged, so this PR still updates it to match- I'm not sure what ramifications there are for bumping this out of band

@yue-stripe
yue-stripe merged commit 697f114 into main Mar 24, 2026
5 checks passed
@yue-stripe
yue-stripe deleted the yue/table-validation-error-location branch March 24, 2026 17:41
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.

3 participants