Skip to content

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

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

Conversation

SwetaTanwar
Copy link
Contributor

@SwetaTanwar SwetaTanwar commented May 24, 2025

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 row

What 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?

Copy link
Contributor

@snitin315 snitin315 left a 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.

Copy link
Member

@lumirlumir lumirlumir left a 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.
Copy link
Member

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?

Copy link
Contributor Author

@SwetaTanwar SwetaTanwar May 26, 2025

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reference: #392 (comment)

Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Rule: table-column-count
4 participants