-
Notifications
You must be signed in to change notification settings - Fork 70
feat: added new rule table-column-count #392
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good start, I have a few suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice rule👍 I've left a few comments.
> | ||
> This rule relies on the `table` AST node, typically available when using a GFM-compatible parser (e.g., `language: "markdown/gfm"`). | ||
|
||
This rule is triggered if a data row in a GFM table contains more cells than the header row. It does not flag rows with fewer cells than the header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It does not flag rows with fewer cells than the header."
Can I ask why this rule doesn’t report rows with fewer cells than the header? Is there a specific constraint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We chose to report tables with extra cells because, in Markdown, having more cells than headers leads to data loss, those extra cells are ignored when rendering the table. On the other hand, if a row has fewer cells, the table still renders correctly, and no data is lost.
Reporting rows with fewer cells felt more like a style concern rather than a functional issue, which is why I decided not to flag those.
Examples:
Valid (fewer cells, no data loss):
Input
| Header | Header | Header |
|--------|--------|--------|
| Cell | Cell | |
Output
Header | Header | Header |
---|---|---|
Cell | Cell |
Invalid (extra cell, data is lost):
Input
| Head1 | Head2 |
|-------|-------|
| R1C1 | R1C2 | R1C3 |
Output
Head1 | Head2 |
---|---|
R1C1 | R1C2 |
As shown, the actual problem arises when there are more cells than expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference: #392 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add that explanation into the docs?
Prerequisites checklist
What is the purpose of this pull request?
This PR adds a new rule
table-column-count
to disallow data rows in a GitHub Flavored Markdown table from having more cells than the header rowWhat changes did you make? (Give an overview)
Added the
table-column-count
rule, along with documentation and tests.Related Issues
fixes #389
Is there anything you'd like reviewers to focus on?