Update MD055/table-pipe-style to support "consistent" and other styles, use micromark positioning, report ranges, add more tests.

This commit is contained in:
David Anson 2023-12-30 18:15:38 -08:00
parent a563c082a5
commit 7d2248d211
28 changed files with 4413 additions and 185 deletions

View file

@ -2323,6 +2323,63 @@ Inline links and images can include descriptive text, but take up more space in
Markdown form. Reference links and images can be easier to read and manipulate
in Markdown form, but require a separate link reference definition.
<a name="md055"></a>
## `MD055` - Table pipe style
Tags: `table`
Aliases: `table-pipe-style`
Parameters:
- `style`: Table pipe style (`string`, default `consistent`, values
`consistent` / `leading_and_trailing` / `leading_only` /
`no_leading_or_trailing` / `trailing_only`)
This rule is triggered when a [GitHub Flavored Markdown table][gfm-table] is
inconsistent about its use of leading and trailing pipe characters (`|`).
By default (`consistent` style), the header row of the first table in a document
is used to determine the style that is enforced for all tables in that document.
A specific style can be required by setting the `style` parameter accordingly.
This table's header row has leading and trailing pipes, but its delimiter row is
missing the trailing pipe and its first row of cells is missing the leading
pipe:
```markdown
| Heading | Heading |
| ------- | -------
Cell | Cell |
```
To fix these issues, make sure there is a pipe character at the beginning and
end of every row:
```markdown
| Heading | Heading |
| ------- | ------- |
| Cell | Cell |
```
Note that text immediately following a table (i.e., not separated by an empty
line) is treated as part of the table (per the specification) and may also
trigger this rule:
```markdown
| Heading | Heading |
| ------- | ------- |
| Cell | Cell |
This text is part of the table
```
Rationale: Some parsers have difficulty with tables that are missing their
leading or trailing pipe characters. The use of leading/trailing pipes can also
help provide visual clarity.
[gfm-table]: https://github.github.com/gfm/#tables-extension-
<!-- markdownlint-configure-file {
"no-inline-html": {
"allowed_elements": [