mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 01:05:55 +03:00
[GH-ISSUE #1818] Proposal: Update MD060/table-column-style to allow exempting violations for the last column #2600
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#2600
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ravlen on GitHub (Oct 17, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1818
I'd like to propose an extra parameter for MD060, which is something we already implement in our docs through https://marketplace.visualstudio.com/items?itemName=fcrespo82.markdown-table-formatter:
That formatting extension has the
limitLastColumnLengthsetting, with an option called:Follow header row length, and the description is:Do not extend last column to more than the table's header row.Essentially, what it means is "Align all columns except the last column":
Before:
After
This is a very common formatting issue with Markdown tables, as we often put descriptions, requirements, etc in the last column and they can vary drastically in length, causing a huge amount of additional padding.
It would be great if we could add one more parameter to the existing
aligned/any/compact/tight. Maybealigned-compact? Which aligns all columns, except the last which uses 1 space if it's longer than the header row?@DavidAnson commented on GitHub (Oct 17, 2025):
I understand the issue and I considered something like this with the initial implementation. However, looking around for examples, it was pretty easy to find cases where it wasn't just the last column that needed special treatment. Sometimes it was the last two columns or maybe the first column has really long names sometimes. It didn't seem that there was a broadly applicable pattern, though I expect the last column is the most popular exceptional column as you show above.
@DavidAnson commented on GitHub (Oct 17, 2025):
Another issue (which I capture here largely for my own benefit now that I'm thinking about this again) is that rule configuration is done per project (or in extreme conditions per file) and there's nothing to say that every table in the project wants or needs its last column handled uniquely.
It would be ideal to be able to infer the need for this on a case-by-case basis. And although it might be straightforward to detect a table using this pattern and not report an issue for it, it may be difficult to detect a table NOT using this pattern that just happens to have a weird last column, etc. and recommending how to fix it could also be iffy.
@Ravlen commented on GitHub (Oct 20, 2025):
@DavidAnson Hrm, I feel there's not much you can do if an internal column needs special treatment, either all columns are aligned, or not. If an internal column requires special treatment, everything else to the right of it would likely get misaligned if you didn't just do the whole table?
Thinking a bit more about it too, perhaps I should have called it a "less-padding" or "tight-padding" option, rather than alignment. Because all "internal" pipe characters are still aligned, it's just checking if there's extra padding at the end. This sort of matches the "no external pipes" or "open" format (I'm not sure what it's called). But if you use that format, you omit the leading and trailing pipes, which also means at no point is padding used in the last cell. So my idea would be to do the same, but with the outer pipes.
"open" style of a table I was looking at recently, auto-formatted by any formatting tool always gives this, with no padding in any row in the last column:
Same table, but with the "tight-padding" style. Same as above, but with the pipes.
So perhaps adjust the proposal to be about limiting end-column padding?
@DavidAnson commented on GitHub (Oct 20, 2025):
This framing seems helpful, thanks! I'm still not sure I see how to distinguish your original example from being deliberate in your style vs. incorrect in the fully aligned style, so this capability seems to need to be an additional property on the rule that says something like "relaxed last column" (as you propose).
I'll need to experiment with this to see if there are unexpected implications, but it seems like it might do the trick.
@DavidAnson commented on GitHub (Dec 4, 2025):
FYI, I came back to this issue recently with the intent to fix it, but couldn't come up with an approach I liked after a couple of days thought. One challenge is that if you want to allow the
compactsingle-space format for the last column, you should also allow thetightstyle, so this option is more than aboolean. And per my comments earlier, it needs to be opt-in. Also, whatever it is should make sense (or at least not be silly) for people usingcompactortightfor the entire table.But even after sorting those questions out, it's unclear what to do with something like the following:
Does anyone really want to argue the second-to-last line should be reported as a violation? What's shown above seems truer to the
alignedstyle than if the two long lines both endedcompact. And surely the following table has a violation even though the proposed changes to this rule would not report one:Instead of jumping through hoops here, I feel like it makes sense for tables with funky last columns to simply delete the trailing pipe (and optionally the leading one) which leads to the following approach which is ALREADY valid today:
@DavidAnson commented on GitHub (Dec 4, 2025):
/cc @trentm and @yuluo-yx
@Ravlen commented on GitHub (Dec 15, 2025):
@DavidAnson Oh yes, I didn't think it would work as a boolean, it would have to be a completely separate parameter. Based on the current ones, the most similar is
aligned, but with the last column unpadded. So something likealigned-except-lastmight give a good hint as to what it does.Yeah, I've got ideas, but I got no skills 😓 I can't offer up any programming solutions, but in my mind the pseudocode/logic check would be like:
Regarding the three examples:
In the first two examples I'd call those both very minor issues, but violations of the rule nonetheless (to maintain consistency). To me it's the same as most other consistency markdownlint rules, like ordered list numbering. Either do it everywhere, or don't use markdownlint/the rule.
And yes, you are absolutely right that the third example is a sensible workaround. But I think people prefer to have everything enclosed in pipes. It feels unbalanced otherwise.
@trentm commented on GitHub (Feb 10, 2026):
Sorry for not ever having gotten back on this.
I don't hate this as answer. :)
I ran into this recently, and when I tried to delete the trailing pipe, I fell afowl of MD055:
because there was another table in the same file. This required me to change all tables in the same file to the same consistent table-pipe-style. My other option was to disable MD055 I guess.