remark-lint-table-pipe-alignment
Advanced tools
Comparing version 4.0.0 to 4.1.0
export default remarkLintTablePipeAlignment; | ||
export type Align = import('mdast').AlignType; | ||
export type Nodes = import('mdast').Nodes; | ||
export type Root = import('mdast').Root; | ||
export type Point = import('unist').Point; | ||
declare const remarkLintTablePipeAlignment: { | ||
(config?: unknown): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined; | ||
readonly name: string; | ||
/** | ||
* Configuration. | ||
*/ | ||
export type Options = { | ||
/** | ||
* Function to detect cell size (optional). | ||
*/ | ||
stringLength?: ((value: string) => number) | null | undefined; | ||
}; | ||
declare const remarkLintTablePipeAlignment: import("unified-lint-rule").Plugin<Root, Options | null | undefined>; | ||
import type { Root } from 'mdast'; | ||
//# sourceMappingURL=index.d.ts.map |
68
index.js
@@ -15,3 +15,3 @@ /** | ||
* | ||
* ### `unified().use(remarkLintTablePipeAlignment)` | ||
* ### `unified().use(remarkLintTablePipeAlignment[, options])` | ||
* | ||
@@ -22,3 +22,4 @@ * Warn when GFM table cells are aligned inconsistently. | ||
* | ||
* There are no options. | ||
* * `options` ([`Options`][api-options], optional) | ||
* — configuration | ||
* | ||
@@ -29,2 +30,11 @@ * ###### Returns | ||
* | ||
* ### `Options` | ||
* | ||
* Configuration (TypeScript type). | ||
* | ||
* ###### Properties | ||
* | ||
* * `stringLength` (`(value: string) => number`, optional) | ||
* — function to detect cell size | ||
* | ||
* ## Recommendation | ||
@@ -48,5 +58,6 @@ * | ||
* to align better for your use case, | ||
* in which case this rule must be turned off. | ||
* in which case this rule must be configured with the same `stringLength`. | ||
* | ||
* [api-remark-lint-table-pipe-alignment]: #unifieduseremarklinttablepipealignment | ||
* [api-options]: #options | ||
* [api-remark-lint-table-pipe-alignment]: #unifieduseremarklinttablepipealignment-options | ||
* [github-remark-gfm]: https://github.com/remarkjs/remark-gfm | ||
@@ -58,3 +69,3 @@ * [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @copyright Titus Wormer | ||
* @license MIT | ||
@@ -212,12 +223,32 @@ * | ||
* 3:8: Unexpected unaligned cell, expected aligned pipes, add `2` spaces | ||
* | ||
* @example | ||
* {"gfm": true, "name": "string-length-default.md"} | ||
* | ||
* | Alpha | Bravo | | ||
* | ----- | ------- | | ||
* | 冥王星 | Charlie | | ||
* | 🪐 | Delta | | ||
* | ||
* @example | ||
* {"config": {"stringLength": "__STRING_WIDTH__"}, "gfm": true, "name": "string-length-custom.md"} | ||
* | ||
* | Alpha | Bravo | | ||
* | ------ | ------- | | ||
* | 冥王星 | Charlie | | ||
* | 🪐 | Delta | | ||
*/ | ||
/** | ||
* @typedef {import('mdast').AlignType} Align | ||
* @typedef {import('mdast').Nodes} Nodes | ||
* @typedef {import('mdast').Root} Root | ||
* | ||
* @typedef {import('unist').Point} Point | ||
* @import {AlignType, Nodes, Root} from 'mdast' | ||
* @import {Point} from 'unist' | ||
*/ | ||
/** | ||
* @typedef Options | ||
* Configuration. | ||
* @property {((value: string) => number) | null | undefined} [stringLength] | ||
* Function to detect cell size (optional). | ||
*/ | ||
import {ok as assert} from 'devlop' | ||
@@ -238,9 +269,11 @@ import {phrasing} from 'mdast-util-phrasing' | ||
* Tree. | ||
* @param {Options | null | undefined} [options] | ||
* Configuration (optional). | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function (tree, file) { | ||
function (tree, file, options) { | ||
/** | ||
* @typedef Entry | ||
* @property {Align} align | ||
* @property {AlignType} align | ||
* @property {Array<Nodes>} ancestors | ||
@@ -259,2 +292,3 @@ * @property {number} column | ||
const stringLength = options ? options.stringLength : undefined | ||
const value = String(file) | ||
@@ -350,3 +384,3 @@ | ||
// Note: this code is also in `remark-lint-table-pipe-alignment`. | ||
// Note: this code is also in `remark-lint-table-cell-padding`. | ||
/** | ||
@@ -402,3 +436,3 @@ * Get info about cells in a table. | ||
* @param {Array<Nodes>} ancestors | ||
* @param {Array<Align>} align | ||
* @param {Array<AlignType>} align | ||
* @returns {Array<Entry> | undefined} | ||
@@ -579,2 +613,6 @@ */ | ||
const middle = stringLength | ||
? stringLength(value.slice(leftIndex, rightIndex)) | ||
: rightIndex - leftIndex | ||
return { | ||
@@ -587,3 +625,3 @@ left, | ||
}, | ||
middle: rightIndex - leftIndex, | ||
middle, | ||
right, | ||
@@ -590,0 +628,0 @@ rightPoint: { |
{ | ||
"name": "remark-lint-table-pipe-alignment", | ||
"version": "4.0.0", | ||
"description": "remark-lint rule to warn when table pipes are not aligned", | ||
"license": "MIT", | ||
"keywords": [ | ||
"align", | ||
"cell", | ||
"lint", | ||
"pipe", | ||
"remark", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule", | ||
"table" | ||
], | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-pipe-alignment", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com>" | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.d.ts", | ||
"index.d.ts.map", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
@@ -45,9 +17,35 @@ "@types/mdast": "^4.0.0", | ||
}, | ||
"description": "remark-lint rule to warn when table pipes are not aligned", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.d.ts", | ||
"index.d.ts.map", | ||
"index.js" | ||
], | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"keywords": [ | ||
"align", | ||
"cell", | ||
"lint", | ||
"pipe", | ||
"remark", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule", | ||
"table" | ||
], | ||
"license": "MIT", | ||
"name": "remark-lint-table-pipe-alignment", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-pipe-alignment", | ||
"scripts": {}, | ||
"sideEffects": false, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"type": "module", | ||
"version": "4.1.0", | ||
"xo": { | ||
@@ -54,0 +52,0 @@ "prettier": true, |
@@ -23,3 +23,4 @@ <!--This file is generated--> | ||
* [API](#api) | ||
* [`unified().use(remarkLintTablePipeAlignment)`](#unifieduseremarklinttablepipealignment) | ||
* [`unified().use(remarkLintTablePipeAlignment[, options])`](#unifieduseremarklinttablepipealignment-options) | ||
* [`Options`](#options) | ||
* [Recommendation](#recommendation) | ||
@@ -122,7 +123,8 @@ * [Fix](#fix) | ||
This package exports no identifiers. | ||
It exports no additional [TypeScript][typescript] types. | ||
It exports the [TypeScript][typescript] type | ||
[`Options`][api-options]. | ||
The default export is | ||
[`remarkLintTablePipeAlignment`][api-remark-lint-table-pipe-alignment]. | ||
### `unified().use(remarkLintTablePipeAlignment)` | ||
### `unified().use(remarkLintTablePipeAlignment[, options])` | ||
@@ -133,3 +135,4 @@ Warn when GFM table cells are aligned inconsistently. | ||
There are no options. | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
@@ -140,2 +143,11 @@ ###### Returns | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Properties | ||
* `stringLength` (`(value: string) => number`, optional) | ||
— function to detect cell size | ||
## Recommendation | ||
@@ -159,3 +171,3 @@ | ||
to align better for your use case, | ||
in which case this rule must be turned off. | ||
in which case this rule must be configured with the same `stringLength`. | ||
@@ -418,2 +430,40 @@ ## Examples | ||
##### `string-length-default.md` | ||
###### In | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
```markdown | ||
| Alpha | Bravo | | ||
| ----- | ------- | | ||
| 冥王星 | Charlie | | ||
| 🪐 | Delta | | ||
``` | ||
###### Out | ||
No messages. | ||
##### `string-length-custom.md` | ||
When configured with `{ stringLength: [Function: stringWidth] }`. | ||
###### In | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
```markdown | ||
| Alpha | Bravo | | ||
| ------ | ------- | | ||
| 冥王星 | Charlie | | ||
| 🪐 | Delta | | ||
``` | ||
###### Out | ||
No messages. | ||
## Compatibility | ||
@@ -444,4 +494,6 @@ | ||
[api-remark-lint-table-pipe-alignment]: #unifieduseremarklinttablepipealignment | ||
[api-options]: #options | ||
[api-remark-lint-table-pipe-alignment]: #unifieduseremarklinttablepipealignment-options | ||
[author]: https://wooorm.com | ||
@@ -448,0 +500,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34324
585
545
0