remark-lint/packages/remark-lint-table-cell-padding
2019-01-12 11:27:12 +01:00
..
index.js Refactor code-style 2018-11-22 12:25:55 +01:00
package.json remark-lint-table-cell-padding: 1.0.3 2019-01-12 11:27:12 +01:00
readme.md Move URLs to HTTPS 2018-11-22 12:19:09 +01:00

remark-lint-table-cell-padding

Warn when table cells are incorrectly padded.

Options: 'consistent', 'padded', or 'compact', default: 'consistent'.

'consistent' detects the first used cell padding style and warns when subsequent cells use different styles.

Fix

remark-stringify formats tables with padding by default. Pass spacedTable: false to not use padding.

See Using remark to fix your markdown on how to automatically fix warnings for this rule.

Presets

This rule is included in the following presets:

Preset Setting
remark-preset-lint-consistent 'consistent'
remark-preset-lint-markdown-style-guide 'padded'

Example

valid.md

When configured with 'padded'.

In
| A     | B     |
| ----- | ----- |
| Alpha | Bravo |
Out

No messages.

invalid.md

When configured with 'padded'.

In
| A    |    B |
| :----|----: |
| Alpha|Bravo |

| C      |    D |
| :----- | ---: |
|Charlie | Delta|

Too much padding isnt good either:

| E     | F        |   G    |      H |
| :---- | -------- | :----: | -----: |
| Echo  | Foxtrot  |  Golf  |  Hotel |
Out
3:8: Cell should be padded
3:9: Cell should be padded
7:2: Cell should be padded
7:17: Cell should be padded
13:23: Cell should be padded with 1 space, not 2
13:32: Cell should be padded with 1 space, not 2
empty.md

When configured with 'padded'.

In
<!-- Empty cells are OK, but those surrounding them may not be. -->

|        | Alpha | Bravo|
| ------ | ----- | ---: |
| Charlie|       |  Echo|
Out
3:25: Cell should be padded
5:10: Cell should be padded
5:25: Cell should be padded
missing-body.md

When configured with 'padded'.

In
<!-- Missing cells are fine as well. -->

| Alpha | Bravo    | Charlie |
| ----- | -------- | ------- |
| Delta |
| Echo  | Foxtrott |
Out

No messages.

valid.md

When configured with 'compact'.

In
|A    |B    |
|-----|-----|
|Alpha|Bravo|
Out

No messages.

invalid.md

When configured with 'compact'.

In
|   A    | B    |
|   -----| -----|
|   Alpha| Bravo|

|C      |     D|
|:------|-----:|
|Charlie|Delta |
Out
3:5: Cell should be compact
3:12: Cell should be compact
7:15: Cell should be compact
valid-padded.md

When configured with 'consistent'.

In
| A     | B     |
| ----- | ----- |
| Alpha | Bravo |

| C       | D     |
| ------- | ----- |
| Charlie | Delta |
Out

No messages.

invalid-padded.md

When configured with 'consistent'.

In
| A     | B     |
| ----- | ----- |
| Alpha | Bravo |

| C      |     D |
| :----- | ----: |
|Charlie | Delta |
Out
7:2: Cell should be padded
valid-compact.md

When configured with 'consistent'.

In
|A    |B    |
|-----|-----|
|Alpha|Bravo|

|C      |D    |
|-------|-----|
|Charlie|Delta|
Out

No messages.

invalid-compact.md

When configured with 'consistent'.

In
|A    |B    |
|-----|-----|
|Alpha|Bravo|

|C      |     D|
|:------|-----:|
|Charlie|Delta |
Out
7:15: Cell should be compact
invalid.md

When configured with 'invalid'.

Out
1:1: Invalid table-cell-padding style `invalid`

Install

npm install remark-lint-table-cell-padding

Usage

You probably want to use it on the CLI through a config file:

 ...
 "remarkConfig": {
   "plugins": [
     ...
     "lint",
+    "lint-table-cell-padding",
     ...
   ]
 }
 ...

Or use it on the CLI directly

remark -u lint -u lint-table-cell-padding readme.md

Or use this on the API:

 var remark = require('remark');
 var report = require('vfile-reporter');

 remark()
   .use(require('remark-lint'))
+  .use(require('remark-lint-table-cell-padding'))
   .process('_Emphasis_ and **importance**', function (err, file) {
     console.error(report(err || file));
   });

License

MIT © Titus Wormer