remark-lint-maximum-line-length
Advanced tools
Comparing version 4.0.1 to 4.1.0
export default remarkLintMaximumLineLength; | ||
export type Root = import('mdast').Root; | ||
declare const remarkLintMaximumLineLength: { | ||
(config?: number | "error" | "on" | "off" | "warn" | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: number | null | undefined] | null | undefined): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined; | ||
readonly name: string; | ||
/** | ||
* Configuration. | ||
*/ | ||
export type Options = { | ||
/** | ||
* Preferred max size (default: `80`). | ||
*/ | ||
size?: number | null | undefined; | ||
/** | ||
* Function to detect text size (optional). | ||
*/ | ||
stringLength?: ((value: string) => number) | null | undefined; | ||
}; | ||
declare const remarkLintMaximumLineLength: import("unified-lint-rule").Plugin<Root, number | Options | null | undefined>; | ||
import type { Root } from 'mdast'; | ||
//# sourceMappingURL=index.d.ts.map |
125
index.js
@@ -18,4 +18,4 @@ /** | ||
* | ||
* Nodes that cannot be wrapped are ignored, such as JSX, HTML, code (flow), | ||
* definitions, headings, and tables. | ||
* Nodes that cannot be wrapped are ignored, | ||
* such as JSX, HTML, code (flow), definitions, headings, and tables. | ||
* | ||
@@ -29,4 +29,4 @@ * When code (phrasing), images, and links start before the wrap, | ||
* | ||
* * `options` (`number`, default: `80`) | ||
* — preferred max size | ||
* * `options` ([`Options`][api-options] or `number`, optional) | ||
* — configuration | ||
* | ||
@@ -37,2 +37,13 @@ * ###### Returns | ||
* | ||
* ### `Options` | ||
* | ||
* Configuration (TypeScript type). | ||
* | ||
* ###### Properties | ||
* | ||
* * `size` (`number`, default: `60`) | ||
* — preferred max size | ||
* * `stringLength` (`(value: string) => number`, optional) | ||
* — function to detect text size | ||
* | ||
* ## Recommendation | ||
@@ -42,2 +53,6 @@ * | ||
* | ||
* To better represent how long lines “look”, | ||
* you can pass a `stringLength` function. | ||
* | ||
* [api-options]: #options | ||
* [api-remark-lint-maximum-line-length]: #unifieduseremarklintmaximumlinelength-options | ||
@@ -48,3 +63,3 @@ * [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @copyright Titus Wormer | ||
* @license MIT | ||
@@ -60,11 +75,11 @@ * | ||
* | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury <http://localhost>. | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury <https://localhost>. | ||
* | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury [mercury](http://localhost). | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury [mercury](https://localhost). | ||
* | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury ![mercury](http://localhost). | ||
* Mercury mercury mercury mercury mercury mercury mercury mercury mercury ![mercury](https://localhost). | ||
* | ||
* <div>Mercury mercury mercury mercury mercury mercury mercury mercury mercury</div> | ||
* | ||
* [foo]: http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury | ||
* [foo]: https://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury | ||
* | ||
@@ -79,3 +94,3 @@ * @example | ||
* | ||
* Mercury mercury mercury <http://localhost>. | ||
* Mercury mercury mercury <https://localhost>. | ||
* | ||
@@ -88,3 +103,3 @@ * Mercury mercury mercury [m](example.com). | ||
* | ||
* <http://localhost> mercury. | ||
* <https://localhost> mercury. | ||
* | ||
@@ -96,3 +111,2 @@ * [m](example.com) mercury. | ||
* Mercury mercury ![m](example.com) mercury. | ||
* | ||
* @example | ||
@@ -103,7 +117,7 @@ * {"config": 20, "label": "output", "name": "not-ok.md", "positionless": true} | ||
* 4:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
* 6:44: Unexpected `43` character line, expected at most `20` characters, remove `23` characters | ||
* 6:45: Unexpected `44` character line, expected at most `20` characters, remove `24` characters | ||
* 8:42: Unexpected `41` character line, expected at most `20` characters, remove `21` characters | ||
* 10:43: Unexpected `42` character line, expected at most `20` characters, remove `22` characters | ||
* 12:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
* 14:28: Unexpected `27` character line, expected at most `20` characters, remove `7` characters | ||
* 14:29: Unexpected `28` character line, expected at most `20` characters, remove `8` characters | ||
* 16:26: Unexpected `25` character line, expected at most `20` characters, remove `5` characters | ||
@@ -114,22 +128,36 @@ * 18:27: Unexpected `26` character line, expected at most `20` characters, remove `6` characters | ||
* @example | ||
* {"config": 40, "name": "string-length-default.md"} | ||
* | ||
* 水星是太陽系的八大行星中最小和最靠近太陽的行星。 | ||
* | ||
* @example | ||
* {"config": {"size": 40, "stringLength": "__STRING_WIDTH__"}, "label": "input", "name": "string-length-custom.md", "positionless": true} | ||
* | ||
* 水星是太陽系的八大行星中最小和最靠近太陽的行星。 | ||
* @example | ||
* {"config": {"size": 40, "stringLength": "__STRING_WIDTH__"}, "label": "output", "name": "string-length-custom.md", "positionless": true} | ||
* | ||
* 1:25: Unexpected `48` character line, expected at most `40` characters, remove `8` characters | ||
* | ||
* @example | ||
* {"config": 20, "name": "long-autolinks-ok.md", "positionless": true} | ||
* | ||
* <http://localhost/mercury/> | ||
* <https://localhost/mercury/> | ||
* | ||
* <http://localhost/mercury/> | ||
* <https://localhost/mercury/> | ||
* mercury. | ||
* | ||
* Mercury | ||
* <http://localhost/mercury/>. | ||
* <https://localhost/mercury/>. | ||
* | ||
* Mercury | ||
* <http://localhost/mercury/> | ||
* <https://localhost/mercury/> | ||
* mercury. | ||
* | ||
* Mercury | ||
* <http://localhost/mercury/> | ||
* <https://localhost/mercury/> | ||
* mercury mercury. | ||
* | ||
* Mercury mercury | ||
* <http://localhost/mercury/> | ||
* <https://localhost/mercury/> | ||
* mercury mercury. | ||
@@ -140,10 +168,10 @@ * | ||
* | ||
* <http://localhost/mercury/> mercury. | ||
* <https://localhost/mercury/> mercury. | ||
* | ||
* Mercury <http://localhost/mercury/>. | ||
* Mercury <https://localhost/mercury/>. | ||
* | ||
* Mercury | ||
* <http://localhost/mercury/> mercury. | ||
* <https://localhost/mercury/> mercury. | ||
* | ||
* Mercury <http://localhost/mercury/> | ||
* Mercury <https://localhost/mercury/> | ||
* mercury. | ||
@@ -153,4 +181,4 @@ * @example | ||
* | ||
* 1:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
* 6:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
* 1:38: Unexpected `37` character line, expected at most `20` characters, remove `17` characters | ||
* 6:38: Unexpected `37` character line, expected at most `20` characters, remove `17` characters | ||
* | ||
@@ -205,10 +233,18 @@ * @example | ||
* | ||
* 1:1: Unexpected value `🌍` for `options`, expected `number` | ||
* 1:1: Unexpected value `🌍` for `size`, expected `number` | ||
*/ | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @import {Root} from 'mdast' | ||
* @import {} from 'mdast-util-mdx' | ||
*/ | ||
/// <reference types="mdast-util-mdx" /> | ||
/** | ||
* @typedef Options | ||
* Configuration. | ||
* @property {number | null | undefined} [size=80] | ||
* Preferred max size (default: `80`). | ||
* @property {((value: string) => number) | null | undefined} [stringLength] | ||
* Function to detect text size (optional). | ||
*/ | ||
@@ -228,3 +264,3 @@ import pluralize from 'pluralize' | ||
* Tree. | ||
* @param {number | null | undefined} [options=80] | ||
* @param {Options | number | null | undefined} [options=80] | ||
* Configuration (default: `80`). | ||
@@ -239,10 +275,20 @@ * @returns {undefined} | ||
if (options === null || options === undefined) { | ||
/** @type {Options['size']} */ | ||
let size | ||
/** @type {Options['stringLength']} */ | ||
let stringLength | ||
if (options && typeof options === 'object') { | ||
size = options.size | ||
stringLength = options.stringLength | ||
} else { | ||
size = options | ||
} | ||
if (size === null || size === undefined) { | ||
// Empty. | ||
} else if (typeof options === 'number') { | ||
expected = options | ||
} else if (typeof size === 'number') { | ||
expected = size | ||
} else { | ||
file.fail( | ||
'Unexpected value `' + options + '` for `options`, expected `number`' | ||
) | ||
file.fail('Unexpected value `' + size + '` for `size`, expected `number`') | ||
} | ||
@@ -325,4 +371,7 @@ | ||
while (++index < lines.length) { | ||
const actualBytes = lines[index].length | ||
const actualCharacters = Array.from(lines[index]).length | ||
const line = lines[index] | ||
const actualBytes = line.length | ||
const actualCharacters = stringLength | ||
? stringLength(line) | ||
: Array.from(line).length | ||
const difference = actualCharacters - expected | ||
@@ -329,0 +378,0 @@ |
{ | ||
"name": "remark-lint-maximum-line-length", | ||
"version": "4.0.1", | ||
"description": "remark-lint rule to warn when lines are too long", | ||
"license": "MIT", | ||
"keywords": [ | ||
"length", | ||
"line", | ||
"lint", | ||
"remark", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule" | ||
], | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-maximum-line-length", | ||
"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": { | ||
@@ -41,9 +15,33 @@ "@types/mdast": "^4.0.0", | ||
}, | ||
"description": "remark-lint rule to warn when lines are too long", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.d.ts", | ||
"index.d.ts.map", | ||
"index.js" | ||
], | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"keywords": [ | ||
"length", | ||
"line", | ||
"lint", | ||
"remark", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule" | ||
], | ||
"license": "MIT", | ||
"name": "remark-lint-maximum-line-length", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-maximum-line-length", | ||
"scripts": {}, | ||
"sideEffects": false, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"type": "module", | ||
"version": "4.1.0", | ||
"xo": { | ||
@@ -50,0 +48,0 @@ "prettier": true, |
100
readme.md
@@ -24,2 +24,3 @@ <!--This file is generated--> | ||
* [`unified().use(remarkLintMaximumLineLength[, options])`](#unifieduseremarklintmaximumlinelength-options) | ||
* [`Options`](#options) | ||
* [Recommendation](#recommendation) | ||
@@ -120,3 +121,4 @@ * [Examples](#examples) | ||
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 | ||
@@ -129,4 +131,4 @@ [`remarkLintMaximumLineLength`][api-remark-lint-maximum-line-length]. | ||
Nodes that cannot be wrapped are ignored, such as JSX, HTML, code (flow), | ||
definitions, headings, and tables. | ||
Nodes that cannot be wrapped are ignored, | ||
such as JSX, HTML, code (flow), definitions, headings, and tables. | ||
@@ -140,4 +142,4 @@ When code (phrasing), images, and links start before the wrap, | ||
* `options` (`number`, default: `80`) | ||
— preferred max size | ||
* `options` ([`Options`][api-options] or `number`, optional) | ||
— configuration | ||
@@ -148,2 +150,13 @@ ###### Returns | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Properties | ||
* `size` (`number`, default: `60`) | ||
— preferred max size | ||
* `stringLength` (`(value: string) => number`, optional) | ||
— function to detect text size | ||
## Recommendation | ||
@@ -153,2 +166,5 @@ | ||
To better represent how long lines “look”, | ||
you can pass a `stringLength` function. | ||
## Examples | ||
@@ -166,11 +182,11 @@ | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury <http://localhost>. | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury <https://localhost>. | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury [mercury](http://localhost). | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury [mercury](https://localhost). | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury ![mercury](http://localhost). | ||
Mercury mercury mercury mercury mercury mercury mercury mercury mercury ![mercury](https://localhost). | ||
<div>Mercury mercury mercury mercury mercury mercury mercury mercury mercury</div> | ||
[foo]: http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury | ||
[foo]: https://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury | ||
``` | ||
@@ -194,3 +210,3 @@ | ||
Mercury mercury mercury <http://localhost>. | ||
Mercury mercury mercury <https://localhost>. | ||
@@ -203,3 +219,3 @@ Mercury mercury mercury [m](example.com). | ||
<http://localhost> mercury. | ||
<https://localhost> mercury. | ||
@@ -218,7 +234,7 @@ [m](example.com) mercury. | ||
4:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
6:44: Unexpected `43` character line, expected at most `20` characters, remove `23` characters | ||
6:45: Unexpected `44` character line, expected at most `20` characters, remove `24` characters | ||
8:42: Unexpected `41` character line, expected at most `20` characters, remove `21` characters | ||
10:43: Unexpected `42` character line, expected at most `20` characters, remove `22` characters | ||
12:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
14:28: Unexpected `27` character line, expected at most `20` characters, remove `7` characters | ||
14:29: Unexpected `28` character line, expected at most `20` characters, remove `8` characters | ||
16:26: Unexpected `25` character line, expected at most `20` characters, remove `5` characters | ||
@@ -229,2 +245,32 @@ 18:27: Unexpected `26` character line, expected at most `20` characters, remove `6` characters | ||
##### `string-length-default.md` | ||
When configured with `40`. | ||
###### In | ||
```markdown | ||
水星是太陽系的八大行星中最小和最靠近太陽的行星。 | ||
``` | ||
###### Out | ||
No messages. | ||
##### `string-length-custom.md` | ||
When configured with `{ size: 40, stringLength: [Function: stringWidth] }`. | ||
###### In | ||
```markdown | ||
水星是太陽系的八大行星中最小和最靠近太陽的行星。 | ||
``` | ||
###### Out | ||
```text | ||
1:25: Unexpected `48` character line, expected at most `40` characters, remove `8` characters | ||
``` | ||
##### `long-autolinks-ok.md` | ||
@@ -237,20 +283,20 @@ | ||
```markdown | ||
<http://localhost/mercury/> | ||
<https://localhost/mercury/> | ||
<http://localhost/mercury/> | ||
<https://localhost/mercury/> | ||
mercury. | ||
Mercury | ||
<http://localhost/mercury/>. | ||
<https://localhost/mercury/>. | ||
Mercury | ||
<http://localhost/mercury/> | ||
<https://localhost/mercury/> | ||
mercury. | ||
Mercury | ||
<http://localhost/mercury/> | ||
<https://localhost/mercury/> | ||
mercury mercury. | ||
Mercury mercury | ||
<http://localhost/mercury/> | ||
<https://localhost/mercury/> | ||
mercury mercury. | ||
@@ -270,10 +316,10 @@ ``` | ||
```markdown | ||
<http://localhost/mercury/> mercury. | ||
<https://localhost/mercury/> mercury. | ||
Mercury <http://localhost/mercury/>. | ||
Mercury <https://localhost/mercury/>. | ||
Mercury | ||
<http://localhost/mercury/> mercury. | ||
<https://localhost/mercury/> mercury. | ||
Mercury <http://localhost/mercury/> | ||
Mercury <https://localhost/mercury/> | ||
mercury. | ||
@@ -285,4 +331,4 @@ ``` | ||
```text | ||
1:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
6:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters | ||
1:38: Unexpected `37` character line, expected at most `20` characters, remove `17` characters | ||
6:38: Unexpected `37` character line, expected at most `20` characters, remove `17` characters | ||
``` | ||
@@ -405,3 +451,3 @@ | ||
```text | ||
1:1: Unexpected value `🌍` for `options`, expected `number` | ||
1:1: Unexpected value `🌍` for `size`, expected `number` | ||
``` | ||
@@ -434,2 +480,4 @@ | ||
[api-options]: #options | ||
[api-remark-lint-maximum-line-length]: #unifieduseremarklintmaximumlinelength-options | ||
@@ -436,0 +484,0 @@ |
Sorry, the diff of this file is not supported yet
25824
378
526