From 07140bd9056e915743117f507522899fba15143f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 17 Dec 2023 12:02:21 +0100 Subject: [PATCH] list-item-indent: rename `space` to `one`, `tab-size` to `tab` This aligns with `remark-stringify` / `mdast-util-to-markdown` --- .../remark-lint-list-item-indent/index.js | 61 +++++++++++-------- .../remark-lint-list-item-indent/readme.md | 30 +++++---- .../remark-preset-lint-recommended/index.js | 2 +- .../remark-preset-lint-recommended/readme.md | 2 +- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/packages/remark-lint-list-item-indent/index.js b/packages/remark-lint-list-item-indent/index.js index 907aec76..d83251f4 100644 --- a/packages/remark-lint-list-item-indent/index.js +++ b/packages/remark-lint-list-item-indent/index.js @@ -19,7 +19,7 @@ * * ###### Parameters * - * * `options` ([`Options`][api-options], default: `'tab-size'`) + * * `options` ([`Options`][api-options], default: `'tab'`) * — preferred style * * ###### Returns @@ -30,17 +30,17 @@ * * Configuration (TypeScript type). * - * * `'space'` + * * `'one'` * — prefer a single space - * * `'tab-size'` + * * `'tab'` * — prefer spaces the size of the next tab stop * * `'mixed'` - * — prefer `'space'` for tight lists and `'tab-size'` for loose lists + * — prefer `'one'` for tight lists and `'tab'` for loose lists * * ###### Type * * ```ts - * type Options = 'mixed' | 'space' | 'tab-size' + * type Options = 'mixed' | 'one' | 'tab' * ``` * * ## Recommendation @@ -70,20 +70,18 @@ * CommonMark made that a *lot* better, * but there remain (documented but complex) edge cases and some behavior * intuitive. - * Due to this, the default of this list is `'tab-size'`, which worked the best + * Due to this, the default of this list is `'tab'`, which worked the best * in most markdown parsers *and* in CommonMark. * Currently the situation between markdown parsers is better, - * so choosing `'space'`, which seems to be the most common style used by + * so choosing `'one'`, which seems to be the most common style used by * authors, * is okay. * * ## Fix * - * [`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'`, - * for `'space'`, + * [`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'` * by default. - * `listItemIndent: 'mixed'` or `listItemIndent: 'tab'` (for `'tab-size'`) is - * also supported. + * `listItemIndent: 'mixed'` or `listItemIndent: 'tab'` is also supported. * * [api-options]: #options * [api-remark-lint-list-item-indent]: #unifieduseremarklintlistitemindent-options @@ -131,7 +129,7 @@ * ␠␠␠␠item. * * @example - * {"name": "ok.md", "config": "space"} + * {"name": "ok.md", "config": "one"} * * *␠List item. * @@ -148,24 +146,24 @@ * ␠␠item. * * @example - * {"name": "not-ok.md", "config": "space", "label": "input"} + * {"name": "not-ok.md", "config": "one", "label": "input"} * * *␠␠␠List * ␠␠␠␠item. * * @example - * {"name": "not-ok.md", "config": "space", "label": "output"} + * {"name": "not-ok.md", "config": "one", "label": "output"} * * 1:5: Incorrect list-item indent: remove 2 spaces * * @example - * {"name": "not-ok.md", "config": "tab-size", "label": "input"} + * {"name": "not-ok.md", "config": "tab", "label": "input"} * * *␠List * ␠␠item. * * @example - * {"name": "not-ok.md", "config": "tab-size", "label": "output"} + * {"name": "not-ok.md", "config": "tab", "label": "output"} * * 1:3: Incorrect list-item indent: add 2 spaces * @@ -182,7 +180,7 @@ * @example * {"name": "not-ok.md", "config": "💩", "label": "output", "positionless": true} * - * 1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` + * 1:1: Incorrect list-item indent style `💩`: use either `'mixed'`, `'one'`, or `'tab'` */ /** @@ -190,7 +188,7 @@ */ /** - * @typedef {'mixed' | 'space' | 'tab-size'} Options + * @typedef {'mixed' | 'one' | 'tab'} Options * Configuration. */ @@ -207,20 +205,35 @@ const remarkLintListItemIndent = lintRule( /** * @param {Root} tree * Tree. - * @param {Options | null | undefined} [options='tab-size'] - * Configuration (default: `'tab-size'`). + * @param {Options | null | undefined} [options='tab'] + * Configuration (default: `'tab'`). * @returns {undefined} * Nothing. */ function (tree, file, options) { const value = String(file) - const option = options || 'tab-size' + const option = options || 'tab' - if (option !== 'mixed' && option !== 'space' && option !== 'tab-size') { + /* c8 ignore next 13 -- previous names. */ + // @ts-expect-error: old name. + if (option === 'space') { + file.fail( + 'Incorrect list-item indent style `' + option + "`: use `'one'` instead" + ) + } + + // @ts-expect-error: old name. + if (option === 'tab-size') { + file.fail( + 'Incorrect list-item indent style `' + option + "`: use `'tab'` instead" + ) + } + + if (option !== 'mixed' && option !== 'one' && option !== 'tab') { file.fail( 'Incorrect list-item indent style `' + option + - "`: use either `'tab-size'`, `'space'`, or `'mixed'`" + "`: use either `'mixed'`, `'one'`, or `'tab'`" ) } @@ -247,7 +260,7 @@ const remarkLintListItemIndent = lintRule( const bulletSize = marker.replace(/\s+$/, '').length const style = - option === 'tab-size' || (option === 'mixed' && spread) + option === 'tab' || (option === 'mixed' && spread) ? Math.ceil(bulletSize / 4) * 4 : bulletSize + 1 diff --git a/packages/remark-lint-list-item-indent/readme.md b/packages/remark-lint-list-item-indent/readme.md index a311be78..120061e4 100644 --- a/packages/remark-lint-list-item-indent/readme.md +++ b/packages/remark-lint-list-item-indent/readme.md @@ -46,7 +46,7 @@ This plugin is included in the following presets: | Preset | Options | | - | - | | [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'mixed'` | -| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | `'tab-size'` | +| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | `'tab'` | ## Install @@ -132,7 +132,7 @@ Warn when the whitespace after list item markers violate a given style. ###### Parameters -* `options` ([`Options`][api-options], default: `'tab-size'`) +* `options` ([`Options`][api-options], default: `'tab'`) — preferred style ###### Returns @@ -143,17 +143,17 @@ Transform ([`Transformer` from `unified`][github-unified-transformer]). Configuration (TypeScript type). -* `'space'` +* `'one'` — prefer a single space -* `'tab-size'` +* `'tab'` — prefer spaces the size of the next tab stop * `'mixed'` - — prefer `'space'` for tight lists and `'tab-size'` for loose lists + — prefer `'one'` for tight lists and `'tab'` for loose lists ###### Type ```ts -type Options = 'mixed' | 'space' | 'tab-size' +type Options = 'mixed' | 'one' | 'tab' ``` ## Recommendation @@ -183,20 +183,18 @@ especially with how they interact with indented code. CommonMark made that a *lot* better, but there remain (documented but complex) edge cases and some behavior intuitive. -Due to this, the default of this list is `'tab-size'`, which worked the best +Due to this, the default of this list is `'tab'`, which worked the best in most markdown parsers *and* in CommonMark. Currently the situation between markdown parsers is better, -so choosing `'space'`, which seems to be the most common style used by +so choosing `'one'`, which seems to be the most common style used by authors, is okay. ## Fix -[`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'`, -for `'space'`, +[`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'` by default. -`listItemIndent: 'mixed'` or `listItemIndent: 'tab'` (for `'tab-size'`) is -also supported. +`listItemIndent: 'mixed'` or `listItemIndent: 'tab'` is also supported. ## Examples @@ -254,7 +252,7 @@ No messages. ##### `ok.md` -When configured with `'space'`. +When configured with `'one'`. ###### In @@ -280,7 +278,7 @@ No messages. ##### `not-ok.md` -When configured with `'space'`. +When configured with `'one'`. ###### In @@ -297,7 +295,7 @@ When configured with `'space'`. ##### `not-ok.md` -When configured with `'tab-size'`. +When configured with `'tab'`. ###### In @@ -335,7 +333,7 @@ When configured with `'💩'`. ###### Out ```text -1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` +1:1: Incorrect list-item indent style `💩`: use either `'mixed'`, `'one'`, or `'tab'` ``` ## Compatibility diff --git a/packages/remark-preset-lint-recommended/index.js b/packages/remark-preset-lint-recommended/index.js index ddf35d08..ce7475ed 100644 --- a/packages/remark-preset-lint-recommended/index.js +++ b/packages/remark-preset-lint-recommended/index.js @@ -49,7 +49,7 @@ const remarkPresetLintRecommended = { remarkLintFinalNewline, // Rendering across vendors differs greatly if using other styles. remarkLintListItemBulletIndent, - [remarkLintListItemIndent, 'tab-size'], + [remarkLintListItemIndent, 'tab'], remarkLintNoBlockquoteWithoutMarker, remarkLintNoLiteralUrls, [remarkLintOrderedListMarkerStyle, '.'], diff --git a/packages/remark-preset-lint-recommended/readme.md b/packages/remark-preset-lint-recommended/readme.md index e82c5ed4..0d0aec74 100644 --- a/packages/remark-preset-lint-recommended/readme.md +++ b/packages/remark-preset-lint-recommended/readme.md @@ -44,7 +44,7 @@ This preset includes the following plugins: | [`remark-lint-final-newline`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-final-newline) | | | [`remark-lint-hard-break-spaces`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-hard-break-spaces) | | | [`remark-lint-list-item-bullet-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-bullet-indent) | | -| [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) | `'tab-size'` | +| [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) | `'tab'` | | [`remark-lint-no-blockquote-without-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-blockquote-without-marker) | | | [`remark-lint-no-duplicate-definitions`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-duplicate-definitions) | | | [`remark-lint-no-heading-content-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-heading-content-indent) | |