mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-09-11 19:57:15 +03:00
Fix table alignment related rules for micromark
changes
Related-to: micromark#146. Recently, an underlying package used throughout remark received some great changes, improving performance significantly, and fixing several (uncommon) bugs: [`micromark-extension-gfm-table@1.0.6`](https://github.com/micromark/micromark-extension-gfm-table/releases/tag/1.0.6). Unfortunately, that release changed *which* cell owns the pipes compared to before. Old behavior was that the first column would receive two pipes, and later ones the final pipe. New behavior is for the columns to receive one pipe, and the last column two. I think the new behavior makes slightly more sense, but it’s a bit vague, and as the behavior is unspecified, and the release is very tough to roll back, I instead fixed the two packages that use the position info here. If you’re getting these updated packages, you’re likely also getting last week’s `micromark-extension-gfm-table`, and it’ll all work.
This commit is contained in:
parent
04cffeca1e
commit
639271aed9
@ -66,11 +66,11 @@
|
|||||||
* 3:9: Cell should be padded
|
* 3:9: Cell should be padded
|
||||||
* 7:2: Cell should be padded
|
* 7:2: Cell should be padded
|
||||||
* 7:17: Cell should be padded
|
* 7:17: Cell should be padded
|
||||||
* 13:9: Cell should be padded with 1 space, not 2
|
* 13:7: Cell should be padded with 1 space, not 2
|
||||||
* 13:20: Cell should be padded with 1 space, not 2
|
* 13:18: Cell should be padded with 1 space, not 2
|
||||||
* 13:21: Cell should be padded with 1 space, not 2
|
* 13:23: Cell should be padded with 1 space, not 2
|
||||||
* 13:29: Cell should be padded with 1 space, not 2
|
* 13:27: Cell should be padded with 1 space, not 2
|
||||||
* 13:30: Cell should be padded with 1 space, not 2
|
* 13:32: Cell should be padded with 1 space, not 2
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* {"name": "ok.md", "config": "compact", "gfm": true}
|
* {"name": "ok.md", "config": "compact", "gfm": true}
|
||||||
@ -93,9 +93,9 @@
|
|||||||
* @example
|
* @example
|
||||||
* {"name": "not-ok.md", "label": "output", "config": "compact", "gfm": true}
|
* {"name": "not-ok.md", "label": "output", "config": "compact", "gfm": true}
|
||||||
*
|
*
|
||||||
* 3:2: Cell should be compact
|
* 3:5: Cell should be compact
|
||||||
* 3:11: Cell should be compact
|
* 3:12: Cell should be compact
|
||||||
* 7:16: Cell should be compact
|
* 7:15: Cell should be compact
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* {"name": "ok-padded.md", "config": "consistent", "gfm": true}
|
* {"name": "ok-padded.md", "config": "consistent", "gfm": true}
|
||||||
@ -149,7 +149,7 @@
|
|||||||
* @example
|
* @example
|
||||||
* {"name": "not-ok-compact.md", "label": "output", "config": "consistent", "gfm": true}
|
* {"name": "not-ok-compact.md", "label": "output", "config": "consistent", "gfm": true}
|
||||||
*
|
*
|
||||||
* 7:16: Cell should be compact
|
* 7:15: Cell should be compact
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* {"name": "not-ok.md", "label": "output", "config": "💩", "positionless": true, "gfm": true}
|
* {"name": "not-ok.md", "label": "output", "config": "💩", "positionless": true, "gfm": true}
|
||||||
@ -255,7 +255,6 @@ const remarkLintTableCellPadding = lintRule(
|
|||||||
while (++column < row.children.length) {
|
while (++column < row.children.length) {
|
||||||
const cell = row.children[column]
|
const cell = row.children[column]
|
||||||
|
|
||||||
if (cell.children.length > 0) {
|
|
||||||
const cellStart = pointStart(cell).offset
|
const cellStart = pointStart(cell).offset
|
||||||
const cellEnd = pointEnd(cell).offset
|
const cellEnd = pointEnd(cell).offset
|
||||||
const contentStart = pointStart(cell.children[0]).offset
|
const contentStart = pointStart(cell.children[0]).offset
|
||||||
@ -274,21 +273,22 @@ const remarkLintTableCellPadding = lintRule(
|
|||||||
|
|
||||||
entries.push({
|
entries.push({
|
||||||
node: cell,
|
node: cell,
|
||||||
start: contentStart - cellStart - (column ? 0 : 1),
|
start: contentStart - cellStart - 1,
|
||||||
end: cellEnd - contentEnd - 1,
|
end:
|
||||||
|
cellEnd -
|
||||||
|
contentEnd -
|
||||||
|
(column === row.children.length - 1 ? 1 : 0),
|
||||||
column
|
column
|
||||||
})
|
})
|
||||||
|
|
||||||
// Detect max space per column.
|
// Detect max space per column.
|
||||||
sizes[column] = Math.max(
|
sizes[column] = Math.max(
|
||||||
// More cells could exist than the align row for generated tables.
|
|
||||||
/* c8 ignore next */
|
/* c8 ignore next */
|
||||||
sizes[column] || 0,
|
sizes[column] || 0,
|
||||||
contentEnd - contentStart
|
contentEnd - contentStart
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const style =
|
const style =
|
||||||
option === 'consistent'
|
option === 'consistent'
|
||||||
@ -346,28 +346,12 @@ const remarkLintTableCellPadding = lintRule(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {Point} */
|
file.message(
|
||||||
let point
|
reason,
|
||||||
|
side === 'start'
|
||||||
if (side === 'start') {
|
? pointStart(cell.children[0])
|
||||||
point = pointStart(cell)
|
: pointEnd(cell.children[cell.children.length - 1])
|
||||||
if (!column) {
|
)
|
||||||
point.column++
|
|
||||||
|
|
||||||
if (typeof point.offset === 'number') {
|
|
||||||
point.offset++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
point = pointEnd(cell)
|
|
||||||
point.column--
|
|
||||||
|
|
||||||
if (typeof point.offset === 'number') {
|
|
||||||
point.offset--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.message(reason, point)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -199,11 +199,11 @@ Too much padding isn’t good either:
|
|||||||
3:9: Cell should be padded
|
3:9: Cell should be padded
|
||||||
7:2: Cell should be padded
|
7:2: Cell should be padded
|
||||||
7:17: Cell should be padded
|
7:17: Cell should be padded
|
||||||
13:9: Cell should be padded with 1 space, not 2
|
13:7: Cell should be padded with 1 space, not 2
|
||||||
13:20: Cell should be padded with 1 space, not 2
|
13:18: Cell should be padded with 1 space, not 2
|
||||||
13:21: Cell should be padded with 1 space, not 2
|
13:23: Cell should be padded with 1 space, not 2
|
||||||
13:29: Cell should be padded with 1 space, not 2
|
13:27: Cell should be padded with 1 space, not 2
|
||||||
13:30: Cell should be padded with 1 space, not 2
|
13:32: Cell should be padded with 1 space, not 2
|
||||||
```
|
```
|
||||||
|
|
||||||
##### `empty.md`
|
##### `empty.md`
|
||||||
@ -290,9 +290,9 @@ When configured with `'compact'`.
|
|||||||
###### Out
|
###### Out
|
||||||
|
|
||||||
```text
|
```text
|
||||||
3:2: Cell should be compact
|
3:5: Cell should be compact
|
||||||
3:11: Cell should be compact
|
3:12: Cell should be compact
|
||||||
7:16: Cell should be compact
|
7:15: Cell should be compact
|
||||||
```
|
```
|
||||||
|
|
||||||
##### `ok-padded.md`
|
##### `ok-padded.md`
|
||||||
@ -384,7 +384,7 @@ When configured with `'consistent'`.
|
|||||||
###### Out
|
###### Out
|
||||||
|
|
||||||
```text
|
```text
|
||||||
7:16: Cell should be compact
|
7:15: Cell should be compact
|
||||||
```
|
```
|
||||||
|
|
||||||
##### `not-ok.md`
|
##### `not-ok.md`
|
||||||
|
@ -54,6 +54,14 @@
|
|||||||
*
|
*
|
||||||
* 3:9-3:10: Misaligned table fence
|
* 3:9-3:10: Misaligned table fence
|
||||||
* 3:17-3:18: Misaligned table fence
|
* 3:17-3:18: Misaligned table fence
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* {"name": "ok-empty-cells.md", "gfm": true}
|
||||||
|
*
|
||||||
|
* | | B | |
|
||||||
|
* |-| ----- | - |
|
||||||
|
* | | Bravo | |
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,8 +95,16 @@ const remarkLintTablePipeAlignment = lintRule(
|
|||||||
const cell = row.children[column]
|
const cell = row.children[column]
|
||||||
const nextColumn = column + 1
|
const nextColumn = column + 1
|
||||||
const next = row.children[nextColumn]
|
const next = row.children[nextColumn]
|
||||||
const initial = cell ? pointEnd(cell).offset : pointStart(row).offset
|
const initial = cell
|
||||||
const final = next ? pointStart(next).offset : pointEnd(row).offset
|
? cell.children.length === 0
|
||||||
|
? pointStart(cell).offset
|
||||||
|
: pointEnd(cell.children[cell.children.length - 1]).offset
|
||||||
|
: pointStart(row).offset
|
||||||
|
const final = next
|
||||||
|
? next.children.length === 0
|
||||||
|
? pointEnd(next).offset
|
||||||
|
: pointStart(next.children[0]).offset
|
||||||
|
: pointEnd(row).offset
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof initial !== 'number' ||
|
typeof initial !== 'number' ||
|
||||||
|
@ -184,6 +184,22 @@ No messages.
|
|||||||
3:17-3:18: Misaligned table fence
|
3:17-3:18: Misaligned table fence
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### `ok-empty-cells.md`
|
||||||
|
|
||||||
|
###### In
|
||||||
|
|
||||||
|
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
| | B | |
|
||||||
|
|-| ----- | - |
|
||||||
|
| | Bravo | |
|
||||||
|
```
|
||||||
|
|
||||||
|
###### Out
|
||||||
|
|
||||||
|
No messages.
|
||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
Projects maintained by the unified collective are compatible with all maintained
|
Projects maintained by the unified collective are compatible with all maintained
|
||||||
|
4
test.js
4
test.js
@ -288,10 +288,8 @@ test('rules', async (t) => {
|
|||||||
const info = rule(base)
|
const info = rule(base)
|
||||||
const href = url.pathToFileURL(base).href + '/index.js'
|
const href = url.pathToFileURL(base).href + '/index.js'
|
||||||
|
|
||||||
// type-coverage:ignore-next-line
|
/** @type {{default: Plugin}} */
|
||||||
const pluginMod = await import(href)
|
const pluginMod = await import(href)
|
||||||
/** @type {Plugin} */
|
|
||||||
// type-coverage:ignore-next-line
|
|
||||||
const fn = pluginMod.default
|
const fn = pluginMod.default
|
||||||
|
|
||||||
if (Object.keys(info.tests).length === 0) {
|
if (Object.keys(info.tests).length === 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user