remark-lint-table-pipe-alignment
Advanced tools
Comparing version 3.1.0 to 3.1.1
export default remarkLintTablePipeAlignment | ||
export type Root = import('mdast').Root | ||
export type Marker = '-' | '*' | '+' | ||
export type Options = 'consistent' | Marker | ||
declare const remarkLintTablePipeAlignment: import('unified').Plugin< | ||
| void[] | ||
| [unknown] | ||
| void[] | ||
| [ | ||
( | ||
| boolean | ||
| import('unified-lint-rule').Label | ||
| import('unified-lint-rule').Severity | ||
| import('unified-lint-rule').Label | ||
), | ||
@@ -14,0 +12,0 @@ unknown |
56
index.js
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @module table-pipe-alignment | ||
* @fileoverview | ||
* Warn when table pipes are not aligned. | ||
* ## When should I use this? | ||
* | ||
* ## Fix | ||
* You can use this package to check that table cell dividers are aligned. | ||
* Tables are a GFM feature enabled with | ||
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm). | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify) | ||
* tries to align tables by default. | ||
* Pass | ||
* [`paddedTable: false`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionspaddedtable) | ||
* to not align cells. | ||
* ## API | ||
* | ||
* Aligning cells perfectly is impossible as some characters (such as emoji or | ||
* Chinese characters) are rendered differently in different browsers, | ||
* terminals, and editors. | ||
* You can pass your own | ||
* [`stringLength`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionsstringlength) | ||
* function to customize how cells are aligned. | ||
* In that case, this rule must be turned off. | ||
* There are no options. | ||
* | ||
* See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
* on how to automatically fix warnings for this rule. | ||
* ## Recommendation | ||
* | ||
* While aligning table dividers improves their legibility, it is somewhat | ||
* hard to maintain manually, especially for tables with many rows. | ||
* | ||
* ## Fix | ||
* | ||
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm) | ||
* aligns table dividers by default. | ||
* Pass | ||
* [`tablePipeAlign: false`](https://github.com/remarkjs/remark-gfm#optionstablepipealign) | ||
* to use a more compact style. | ||
* | ||
* Aligning characters is impossible because whether they look aligned or not | ||
* depends on where the markup is shown: some characters (such as emoji or | ||
* Chinese characters) show smaller or bigger in different places. | ||
* You can pass your own | ||
* [`stringLength`](https://github.com/remarkjs/remark-gfm#optionsstringlength) | ||
* to `remark-gfm`, in which case this rule must be turned off. | ||
* | ||
* @module table-pipe-alignment | ||
* @summary | ||
* remark-lint rule to warn when table cells are inconsistently padded. | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @example | ||
@@ -51,4 +61,2 @@ * {"name": "ok.md", "gfm": true} | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {'-'|'*'|'+'} Marker | ||
* @typedef {'consistent'|Marker} Options | ||
*/ | ||
@@ -70,3 +78,3 @@ | ||
visit(tree, 'table', (node) => { | ||
/** @type {number[]} */ | ||
/** @type {Array<number>} */ | ||
const indices = [] | ||
@@ -73,0 +81,0 @@ let index = -1 |
{ | ||
"name": "remark-lint-table-pipe-alignment", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "remark-lint rule to warn when table pipes are not aligned", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
213
readme.md
@@ -13,23 +13,32 @@ <!--This file is generated--> | ||
Warn when table pipes are not aligned. | ||
[`remark-lint`][mono] rule to warn when table cells are inconsistently padded. | ||
## Fix | ||
## Contents | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify) | ||
tries to align tables by default. | ||
Pass | ||
[`paddedTable: false`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionspaddedtable) | ||
to not align cells. | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Presets](#presets) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`unified().use(remarkLintTablePipeAlignment[, config])`](#unifieduseremarklinttablepipealignment-config) | ||
* [Recommendation](#recommendation) | ||
* [Fix](#fix) | ||
* [Examples](#examples) | ||
* [Compatibility](#compatibility) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
Aligning cells perfectly is impossible as some characters (such as emoji or | ||
Chinese characters) are rendered differently in different browsers, | ||
terminals, and editors. | ||
You can pass your own | ||
[`stringLength`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionsstringlength) | ||
function to customize how cells are aligned. | ||
In that case, this rule must be turned off. | ||
## What is this? | ||
See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
on how to automatically fix warnings for this rule. | ||
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint` | ||
rule. | ||
Lint rules check markdown code style. | ||
## When should I use this? | ||
You can use this package to check that table cell dividers are aligned. | ||
Tables are a GFM feature enabled with | ||
[`remark-gfm`](https://github.com/remarkjs/remark-gfm). | ||
## Presets | ||
@@ -43,57 +52,56 @@ | ||
## Example | ||
## Install | ||
##### `ok.md` | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
###### In | ||
```sh | ||
npm install remark-lint-table-pipe-alignment | ||
``` | ||
Note: this example uses [GFM][]. | ||
In Deno with [Skypack][]: | ||
```markdown | ||
| A | B | | ||
| ----- | ----- | | ||
| Alpha | Bravo | | ||
```js | ||
import remarkLintTablePipeAlignment from 'https://cdn.skypack.dev/remark-lint-table-pipe-alignment@3?dts' | ||
``` | ||
###### Out | ||
In browsers with [Skypack][]: | ||
No messages. | ||
```html | ||
<script type="module"> | ||
import remarkLintTablePipeAlignment from 'https://cdn.skypack.dev/remark-lint-table-pipe-alignment@3?min' | ||
</script> | ||
``` | ||
##### `not-ok.md` | ||
## Use | ||
###### In | ||
On the API: | ||
Note: this example uses [GFM][]. | ||
```js | ||
import {read} from 'to-vfile' | ||
import {reporter} from 'vfile-reporter' | ||
import {remark} from 'remark' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintTablePipeAlignment from 'remark-lint-table-pipe-alignment' | ||
```markdown | ||
| A | B | | ||
| -- | -- | | ||
| Alpha | Bravo | | ||
``` | ||
main() | ||
###### Out | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintTablePipeAlignment) | ||
.process(await read('example.md')) | ||
```text | ||
3:9-3:10: Misaligned table fence | ||
3:17-3:18: Misaligned table fence | ||
console.error(reporter(file)) | ||
} | ||
``` | ||
## Install | ||
On the CLI: | ||
This package is [ESM only][esm]: | ||
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
[npm][]: | ||
```sh | ||
npm install remark-lint-table-pipe-alignment | ||
remark --use remark-lint --use remark-lint-table-pipe-alignment example.md | ||
``` | ||
This package exports no identifiers. | ||
The default export is `remarkLintTablePipeAlignment`. | ||
On the CLI in a config file (here a `package.json`): | ||
## Use | ||
You probably want to use it on the CLI through a config file: | ||
```diff | ||
@@ -104,4 +112,4 @@ … | ||
… | ||
"lint", | ||
+ "lint-table-pipe-alignment", | ||
"remark-lint", | ||
+ "remark-lint-table-pipe-alignment", | ||
… | ||
@@ -113,25 +121,78 @@ ] | ||
Or use it on the CLI directly | ||
## API | ||
```sh | ||
remark -u lint -u lint-table-pipe-alignment readme.md | ||
This package exports no identifiers. | ||
The default export is `remarkLintTablePipeAlignment`. | ||
### `unified().use(remarkLintTablePipeAlignment[, config])` | ||
This rule supports standard configuration that all remark lint rules accept | ||
(such as `false` to turn it off or `[1, options]` to configure it). | ||
There are no options. | ||
## Recommendation | ||
While aligning table dividers improves their legibility, it is somewhat | ||
hard to maintain manually, especially for tables with many rows. | ||
## Fix | ||
[`remark-gfm`](https://github.com/remarkjs/remark-gfm) | ||
aligns table dividers by default. | ||
Pass | ||
[`tablePipeAlign: false`](https://github.com/remarkjs/remark-gfm#optionstablepipealign) | ||
to use a more compact style. | ||
Aligning characters is impossible because whether they look aligned or not | ||
depends on where the markup is shown: some characters (such as emoji or | ||
Chinese characters) show smaller or bigger in different places. | ||
You can pass your own | ||
[`stringLength`](https://github.com/remarkjs/remark-gfm#optionsstringlength) | ||
to `remark-gfm`, in which case this rule must be turned off. | ||
## Examples | ||
##### `ok.md` | ||
###### In | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
```markdown | ||
| A | B | | ||
| ----- | ----- | | ||
| Alpha | Bravo | | ||
``` | ||
Or use this on the API: | ||
###### Out | ||
```diff | ||
import {remark} from 'remark' | ||
import {reporter} from 'vfile-reporter' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintTablePipeAlignment from 'remark-lint-table-pipe-alignment' | ||
No messages. | ||
remark() | ||
.use(remarkLint) | ||
+ .use(remarkLintTablePipeAlignment) | ||
.process('_Emphasis_ and **importance**') | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
##### `not-ok.md` | ||
###### In | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
```markdown | ||
| A | B | | ||
| -- | -- | | ||
| Alpha | Bravo | | ||
``` | ||
###### Out | ||
```text | ||
3:9-3:10: Misaligned table fence | ||
3:17-3:18: Misaligned table fence | ||
``` | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
## Contribute | ||
@@ -177,4 +238,12 @@ | ||
[unified]: https://github.com/unifiedjs/unified | ||
[remark]: https://github.com/remarkjs/remark | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[skypack]: https://www.skypack.dev | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -184,7 +253,7 @@ | ||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
@@ -191,0 +260,0 @@ [license]: https://github.com/remarkjs/remark-lint/blob/main/license |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11699
124
259