mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
This commit is contained in:
parent
4a52864b39
commit
a563c082a5
11 changed files with 228 additions and 12 deletions
1
.github/dictionary.txt
vendored
1
.github/dictionary.txt
vendored
|
|
@ -37,6 +37,7 @@ eslint-plugin-markdownlint
|
||||||
first-line-h1
|
first-line-h1
|
||||||
formatter
|
formatter
|
||||||
fs
|
fs
|
||||||
|
GFM
|
||||||
globbing
|
globbing
|
||||||
grunt-markdownlint
|
grunt-markdownlint
|
||||||
h1
|
h1
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ playground for learning and exploring.
|
||||||
- **[MD052](doc/md052.md)** *reference-links-images* - Reference links and images should use a label that is defined
|
- **[MD052](doc/md052.md)** *reference-links-images* - Reference links and images should use a label that is defined
|
||||||
- **[MD053](doc/md053.md)** *link-image-reference-definitions* - Link and image reference definitions should be needed
|
- **[MD053](doc/md053.md)** *link-image-reference-definitions* - Link and image reference definitions should be needed
|
||||||
- **[MD054](doc/md054.md)** *link-image-style* - Link and image style
|
- **[MD054](doc/md054.md)** *link-image-style* - Link and image style
|
||||||
|
- **[MD055](doc/md055.md)** *table-missing-border* - Table is missing leading or trailing pipe character
|
||||||
|
|
||||||
<!-- markdownlint-restore -->
|
<!-- markdownlint-restore -->
|
||||||
|
|
||||||
|
|
@ -175,6 +176,7 @@ rules at once.
|
||||||
- **`ol`** - `MD029`, `MD030`, `MD032`
|
- **`ol`** - `MD029`, `MD030`, `MD032`
|
||||||
- **`spaces`** - `MD018`, `MD019`, `MD020`, `MD021`, `MD023`
|
- **`spaces`** - `MD018`, `MD019`, `MD020`, `MD021`, `MD023`
|
||||||
- **`spelling`** - `MD044`
|
- **`spelling`** - `MD044`
|
||||||
|
- **`table`** - `MD055`
|
||||||
- **`ul`** - `MD004`, `MD005`, `MD007`, `MD030`, `MD032`
|
- **`ul`** - `MD004`, `MD005`, `MD007`, `MD030`, `MD032`
|
||||||
- **`url`** - `MD034`
|
- **`url`** - `MD034`
|
||||||
- **`whitespace`** - `MD009`, `MD010`, `MD012`, `MD027`, `MD028`, `MD030`,
|
- **`whitespace`** - `MD009`, `MD010`, `MD012`, `MD027`, `MD028`, `MD030`,
|
||||||
|
|
|
||||||
34
doc-build/md055.md
Normal file
34
doc-build/md055.md
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
This rule is triggered when a [GFM table][gfm-table] is missing a leading
|
||||||
|
or trailing pipe character `|`.
|
||||||
|
|
||||||
|
This table is missing pipes on both sides:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
| Heading | Heading |
|
||||||
|
|---------|---------
|
||||||
|
Cell | Cell |
|
||||||
|
```
|
||||||
|
|
||||||
|
To fix this, make sure there is a pipe character at the start and end of the
|
||||||
|
row:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
| Heading | Heading |
|
||||||
|
|---------|---------|
|
||||||
|
| Cell | Cell |
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that text immediately below a table is treated as part of the table and
|
||||||
|
will trigger this rule:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
| Heading | Heading |
|
||||||
|
|---------|---------|
|
||||||
|
| Cell | Cell |
|
||||||
|
This text will trigger the rule
|
||||||
|
```
|
||||||
|
|
||||||
|
Rationale: Some parsers have difficulty with tables that are missing their
|
||||||
|
leading or trailing pipe characters.
|
||||||
|
|
||||||
|
[gfm-table]: https://github.github.com/gfm/#tables-extension-
|
||||||
27
lib/md055.js
Normal file
27
lib/md055.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { addErrorContext } = require("../helpers");
|
||||||
|
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
"names": [ "MD055", "table-missing-border" ],
|
||||||
|
"description": "Table is missing leading or trailing pipe character",
|
||||||
|
"tags": [ "table" ],
|
||||||
|
"function": function MD055(params, onError) {
|
||||||
|
const tables = filterByTypes(params.parsers.micromark.tokens, [ "table" ]);
|
||||||
|
for (const table of tables) {
|
||||||
|
const rows = filterByTypes(table.children, [ "tableRow", "tableDelimiterRow" ]);
|
||||||
|
for (const row of rows) {
|
||||||
|
const { startLine, text } = row;
|
||||||
|
if (!text.startsWith("|")) {
|
||||||
|
addErrorContext(onError, startLine, text, true);
|
||||||
|
}
|
||||||
|
if (!text.endsWith("|")) {
|
||||||
|
addErrorContext(onError, startLine, text, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,8 +51,8 @@ const rules = [
|
||||||
require("./md051"),
|
require("./md051"),
|
||||||
require("./md052"),
|
require("./md052"),
|
||||||
require("./md053"),
|
require("./md053"),
|
||||||
require("./md054")
|
require("./md054"),
|
||||||
// md055: See https://github.com/markdownlint/markdownlint
|
require("./md055")
|
||||||
// md056: See https://github.com/markdownlint/markdownlint
|
// md056: See https://github.com/markdownlint/markdownlint
|
||||||
// md057: See https://github.com/markdownlint/markdownlint
|
// md057: See https://github.com/markdownlint/markdownlint
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@ Strong **with** different style {MD050}
|
||||||
<!-- markdownlint-disable-next-line MD053 -->
|
<!-- markdownlint-disable-next-line MD053 -->
|
||||||
[url]: https://example.com/page
|
[url]: https://example.com/page
|
||||||
|
|
||||||
|
| table | header |
|
||||||
|
|--------|--------|
|
||||||
|
{MD055} | cell |
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"required-headings": {
|
"required-headings": {
|
||||||
"headings": [
|
"headings": [
|
||||||
|
|
|
||||||
|
|
@ -51,3 +51,7 @@
|
||||||
| cell | <!-- \
|
| cell | <!-- \
|
||||||
| cell | `{MD038} ` --> |
|
| cell | `{MD038} ` --> |
|
||||||
| cell | cell |
|
| cell | cell |
|
||||||
|
|
||||||
|
<!-- markdownlint-configure-file {
|
||||||
|
"table-missing-border": false
|
||||||
|
} -->
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ This is a short line.
|
||||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||||
| ============== | ============== | ============== | ============== | ============== | ============== |
|
| ============== | ============== | ============== | ============== | ============== | ============== |
|
||||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
||||||
{: rules="groups"}
|
|
||||||
|
|
||||||
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
|
||||||
|
|
||||||
|
|
@ -44,7 +43,6 @@ Another line.
|
||||||
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
| Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
|
||||||
| ============== | ============== | ============== | ============== | ============== | ============== |
|
| ============== | ============== | ============== | ============== | ============== | ============== |
|
||||||
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
| Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
|
||||||
{: rules="groups"}
|
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"line-length": {
|
"line-length": {
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ test("projectFiles", (t) => {
|
||||||
"schema/*.md"
|
"schema/*.md"
|
||||||
]))
|
]))
|
||||||
.then((files) => {
|
.then((files) => {
|
||||||
t.is(files.length, 58);
|
t.is(files.length, 59);
|
||||||
const options = {
|
const options = {
|
||||||
files,
|
files,
|
||||||
"config": require("../.markdownlint.json")
|
"config": require("../.markdownlint.json")
|
||||||
|
|
@ -476,13 +476,14 @@ test("styleAll", (t) => new Promise((resolve) => {
|
||||||
"MD042": [ 81 ],
|
"MD042": [ 81 ],
|
||||||
"MD045": [ 85 ],
|
"MD045": [ 85 ],
|
||||||
"MD046": [ 49, 73, 77 ],
|
"MD046": [ 49, 73, 77 ],
|
||||||
"MD047": [ 126 ],
|
"MD047": [ 130 ],
|
||||||
"MD048": [ 77 ],
|
"MD048": [ 77 ],
|
||||||
"MD049": [ 90 ],
|
"MD049": [ 90 ],
|
||||||
"MD050": [ 94 ],
|
"MD050": [ 94 ],
|
||||||
"MD051": [ 96 ],
|
"MD051": [ 96 ],
|
||||||
"MD052": [ 98 ],
|
"MD052": [ 98 ],
|
||||||
"MD053": [ 100 ]
|
"MD053": [ 100 ],
|
||||||
|
"MD055": [ 110 ]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
@ -525,13 +526,14 @@ test("styleRelaxed", (t) => new Promise((resolve) => {
|
||||||
"MD042": [ 81 ],
|
"MD042": [ 81 ],
|
||||||
"MD045": [ 85 ],
|
"MD045": [ 85 ],
|
||||||
"MD046": [ 49, 73, 77 ],
|
"MD046": [ 49, 73, 77 ],
|
||||||
"MD047": [ 126 ],
|
"MD047": [ 130 ],
|
||||||
"MD048": [ 77 ],
|
"MD048": [ 77 ],
|
||||||
"MD049": [ 90 ],
|
"MD049": [ 90 ],
|
||||||
"MD050": [ 94 ],
|
"MD050": [ 94 ],
|
||||||
"MD051": [ 96 ],
|
"MD051": [ 96 ],
|
||||||
"MD052": [ 98 ],
|
"MD052": [ 98 ],
|
||||||
"MD053": [ 100 ]
|
"MD053": [ 100 ],
|
||||||
|
"MD055": [ 110 ]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
@ -841,7 +843,7 @@ test("customFileSystemAsync", (t) => new Promise((resolve) => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test("readme", async(t) => {
|
test("readme", async(t) => {
|
||||||
t.plan(121);
|
t.plan(124);
|
||||||
const tagToRules = {};
|
const tagToRules = {};
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
for (const tag of rule.tags) {
|
for (const tag of rule.tags) {
|
||||||
|
|
@ -916,7 +918,7 @@ test("readme", async(t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
||||||
t.plan(171);
|
t.plan(173);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const ajv = new Ajv(ajvOptions);
|
const ajv = new Ajv(ajvOptions);
|
||||||
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
||||||
|
|
@ -1036,7 +1038,7 @@ test("validateConfigExampleJson", async(t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("allBuiltInRulesHaveValidUrl", (t) => {
|
test("allBuiltInRulesHaveValidUrl", (t) => {
|
||||||
t.plan(144);
|
t.plan(147);
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
t.truthy(rule.information);
|
t.truthy(rule.information);
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,7 @@ Head | Head
|
||||||
<br/> | {MD033}
|
<br/> | {MD033}
|
||||||
text | text
|
text | text
|
||||||
{MD033} | <b>text</b>
|
{MD033} | <b>text</b>
|
||||||
|
|
||||||
|
<!-- markdownlint-configure-file {
|
||||||
|
"table-missing-border": false
|
||||||
|
} -->
|
||||||
|
|
|
||||||
140
test/table-missing-pipes.md
Normal file
140
test/table-missing-pipes.md
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
# Table Missing Pipes
|
||||||
|
|
||||||
|
## Bad Header Row
|
||||||
|
|
||||||
|
| Table | {MD055}
|
||||||
|
|-------|---------|
|
||||||
|
|
||||||
|
Table | {MD055} |
|
||||||
|
|-------|---------|
|
||||||
|
|
||||||
|
Table | {MD055}
|
||||||
|
|-------|---------|
|
||||||
|
|
||||||
|
## Bad Separator Row
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------|---------
|
||||||
|
|
||||||
|
{MD055:17}
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
-------|--------|
|
||||||
|
|
||||||
|
{MD055:22}
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
-------|--------
|
||||||
|
|
||||||
|
{MD055:27}
|
||||||
|
|
||||||
|
## Missing everything
|
||||||
|
|
||||||
|
{MD055} | Header
|
||||||
|
---------|-------
|
||||||
|
{MD055} | cell
|
||||||
|
|
||||||
|
{MD055:34}
|
||||||
|
|
||||||
|
{MD055} | Header
|
||||||
|
--------:|:-----:
|
||||||
|
{MD055} | cell
|
||||||
|
|
||||||
|
{MD055:40}
|
||||||
|
|
||||||
|
## Missing trailing pipe
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------:|:-------|
|
||||||
|
| {MD055} | cell
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|---------|--------|
|
||||||
|
| {MD055} | cell
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|---------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
| {MD055} | cell
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|---------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
| {MD055} | cell
|
||||||
|
|
||||||
|
## Missing leading pipe
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------:|:-------|
|
||||||
|
{MD055} | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
{MD055} | cell |
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
{MD055} | cell |
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
{MD055} | cell |
|
||||||
|
|
||||||
|
## Missing both sides
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------:|:-------|
|
||||||
|
{MD055} | cell
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
{MD055} | cell
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
{MD055} | cell
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|--------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
{MD055} | cell
|
||||||
|
|
||||||
|
## No false-positive
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
| cell | cell |
|
||||||
|
|
||||||
|
## No trailing blank line
|
||||||
|
|
||||||
|
| Table | Header |
|
||||||
|
|-------|--------|
|
||||||
|
| cell | cell |
|
||||||
|
{MD055} Text
|
||||||
|
|
||||||
|
## Markdown Combination
|
||||||
|
|
||||||
|
> | Table | Header |
|
||||||
|
> |-------|--------|
|
||||||
|
> -{MD055}| cell |
|
||||||
Loading…
Add table
Add a link
Reference in a new issue