markdown-preferences/table-leading-trailing-pipes
enforce consistent use of leading and trailing pipes in tables.
- ⚙️ This rule is included in
plugin.configs.standard
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule enforces the presence or absence of leading and trailing pipe (|
) characters in Markdown tables, according to your configuration. It helps maintain a consistent table style throughout your Markdown documents. You can require both leading and trailing pipes (default), disallow both, or configure each side individually. The rule automatically detects and reports lines in tables that do not match the configured style, and can autofix them.
md
<!-- eslint markdown-preferences/table-leading-trailing-pipes: 'error' -->
<!-- ✓ GOOD -->
| User Name | Date Of Birth | Favorite Color |
| --------- | ------------- | -------------- |
| Alice | 2000-01-01 | Blue |
| Bob | 1995-05-23 | Green |
<!-- ✗ BAD -->
User Name | Date Of Birth | Favorite Color
--------- | ------------- | --------------
Alice | 2000-01-01 | Blue
Bob | 1995-05-23 | Green
🔧 Options
json
{
"markdown-preferences/table-leading-trailing-pipes": ["error", "always"]
}
There are two types of options: string format and object format.
- String format: Specify either
"always"
or"never"
. The default is"always"
."always"
: Requires a pipe (|
) at both the beginning and end of each table line."never"
: Disallows a pipe (|
) at both the beginning and end of each table line.
- Object format: Allows you to configure the presence of leading and trailing pipes individually.
leading
: Specifies whether to include a pipe (|
) at the beginning of each line ("always"
or"never"
).trailing
: Specifies whether to include a pipe (|
) at the end of each line ("always"
or"never"
).
Example of "never"
md
<!-- eslint markdown-preferences/table-leading-trailing-pipes: ["error", "never"] -->
<!-- ✓ GOOD -->
User Name | Date Of Birth | Favorite Color
--------- | ------------- | --------------
Alice | 2000-01-01 | Blue
Bob | 1995-05-23 | Green
<!-- ✗ BAD -->
| User Name | Date Of Birth | Favorite Color |
| --------- | ------------- | -------------- |
| Alice | 2000-01-01 | Blue |
| Bob | 1995-05-23 | Green |
Example of { "leading": "always", "trailing": "never" }
md
<!-- eslint markdown-preferences/table-leading-trailing-pipes: ["error", { "leading": "always", "trailing": "never" }] -->
<!-- ✓ GOOD -->
| User Name | Date Of Birth | Favorite Color
| --------- | ------------- | --------------
| Alice | 2000-01-01 | Blue
| Bob | 1995-05-23 | Green
<!-- ✗ BAD -->
| User Name | Date Of Birth | Favorite Color |
| --------- | ------------- | -------------- |
| Alice | 2000-01-01 | Blue |
| Bob | 1995-05-23 | Green |
User Name | Date Of Birth | Favorite Color
--------- | ------------- | --------------
Alice | 2000-01-01 | Blue
Bob | 1995-05-23 | Green
Example of { "leading": "never", "trailing": "always" }
md
<!-- eslint markdown-preferences/table-leading-trailing-pipes: ["error", { "leading": "never", "trailing": "always" }] -->
<!-- ✓ GOOD -->
User Name | Date Of Birth | Favorite Color |
--------- | ------------- | -------------- |
Alice | 2000-01-01 | Blue |
Bob | 1995-05-23 | Green |
<!-- ✗ BAD -->
| User Name | Date Of Birth | Favorite Color |
| --------- | ------------- | -------------- |
| Alice | 2000-01-01 | Blue |
| Bob | 1995-05-23 | Green |
User Name | Date Of Birth | Favorite Color
--------- | ------------- | --------------
Alice | 2000-01-01 | Blue
Bob | 1995-05-23 | Green
📚 Further Reading
👫 Related Rules
- markdown-preferences/table-pipe-alignment
- markdown-preferences/table-pipe-spacing
- markdown-preferences/table-header-casing
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.25.0