From 3f7b39f64693307f1bc1e6ff63187edd20359537 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 24 Mar 2022 10:39:52 -0700 Subject: [PATCH] Revert "Harmonize list item indent literals" This reverts commit 7d24ed255d5359bbf4124dd73b1425970793fba9. --- .../remark-lint-list-item-indent/index.js | 55 ++++++++----------- .../remark-lint-list-item-indent/readme.md | 20 +++---- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/packages/remark-lint-list-item-indent/index.js b/packages/remark-lint-list-item-indent/index.js index 81a3af41..9c641b66 100644 --- a/packages/remark-lint-list-item-indent/index.js +++ b/packages/remark-lint-list-item-indent/index.js @@ -6,14 +6,14 @@ * * ## API * - * The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab'`) are accepted: + * The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab-size'`) are accepted: * - * * `'one'` + * * `'space'` * — prefer a single space - * * `'tab'` + * * `'tab-size'` * — prefer spaces the size of the next tab stop * * `'mixed'` - * — prefer `'one'` for tight lists and `'tab'` for loose lists + * — prefer `'space'` for tight lists and `'tab-size'` for loose lists * * ## Recommendation * @@ -39,17 +39,17 @@ * 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'`, which worked the best + * Due to this, the default of this list is `'tab-size'`, which worked the best * in most markdown parsers. * Currently, the situation between markdown parsers is better, so choosing - * `'one'` (which seems to be the most common style used by authors) should + * `'space'` (which seems to be the most common style used by authors) should * be okay. * * ## Fix * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) - * uses `'tab'` by default. - * [`settings.listItemIndent: 'one'` or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) + * uses `'tab-size'` (named `'tab'` there) by default. + * [`settings.listItemIndent: '1'` (for `'space'`) or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) * is supported. * * @module list-item-indent @@ -130,7 +130,7 @@ * ··item. * * @example - * {"name": "ok.md", "rawOptions": "one"} + * {"name": "ok.md", "rawOptions": "space"} * * *·List item. * @@ -158,13 +158,13 @@ * 1:5: Incorrect list-item indent: remove 2 spaces * * @example - * {"name": "not-ok.md", "rawOptions": "one", "label": "input"} + * {"name": "not-ok.md", "rawOptions": "space", "label": "input"} * * *···List * ····item. * * @example - * {"name": "not-ok.md", "rawOptions": "one", "label": "output"} + * {"name": "not-ok.md", "rawOptions": "space", "label": "output"} * * 1:5: Incorrect list-item indent: remove 2 spaces * @@ -180,13 +180,13 @@ * 1:3: Incorrect list-item indent: add 2 spaces * * @example - * {"name": "not-ok.md", "rawOptions": "tab", "label": "input"} + * {"name": "not-ok.md", "rawOptions": "tab-size", "label": "input"} * * *·List * ··item. * * @example - * {"name": "not-ok.md", "rawOptions": "tab", "label": "output"} + * {"name": "not-ok.md", "rawOptions": "tab-size", "label": "output"} * * 1:3: Incorrect list-item indent: add 2 spaces * @@ -211,19 +211,14 @@ * 1:5: Incorrect list-item indent: remove 2 spaces * * @example - * {"name": "not-ok.md", "settings": {"listItemIndent": "💩"}, "label": "output", "positionless": true} - * - * 1:1: Incorrect list-item indent style `💩`: use either `'tab'`, `'one'`, or `'mixed'` - * - * @example * {"name": "not-ok.md", "rawOptions": "💩", "label": "output", "positionless": true} * - * 1:1: Incorrect list-item indent style `💩`: use either `'tab'`, `'one'`, or `'mixed'` + * 1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` */ /** * @typedef {import('mdast').Root} Root - * @typedef {'tab'|'one'|'mixed'} Options + * @typedef {'tab-size'|'space'|'mixed'} Options */ import {lintRule} from 'unified-lint-rule' @@ -240,25 +235,23 @@ const remarkLintListItemIndent = lintRule( /** @type {import('unified-lint-rule').Rule} */ function (tree, file, option) { const value = String(file) - // TODO(next major): Remove legacy fallbacks. - option = - /** @type {unknown} */ (option) === 'tab-size' - ? /* c8 ignore next */ 'tab' - : /** @type {unknown} */ (option) === 'space' - ? /* c8 ignore next */ 'one' - : option if (!option) { /** @type {import('remark-stringify').Options} */ const settings = this.data().settings || {} - option = settings.listItemIndent || 'tab' + option = + settings.listItemIndent === 'one' + ? 'space' + : settings.listItemIndent === 'mixed' + ? 'mixed' + : 'tab-size' } - if (option !== 'tab' && option !== 'one' && option !== 'mixed') { + if (option !== 'tab-size' && option !== 'space' && option !== 'mixed') { file.fail( 'Incorrect list-item indent style `' + option + - "`: use either `'tab'`, `'one'`, or `'mixed'`" + "`: use either `'tab-size'`, `'space'`, or `'mixed'`" ) } @@ -280,7 +273,7 @@ const remarkLintListItemIndent = lintRule( const bulletSize = marker.replace(/\s+$/, '').length const style = - option === 'tab' || (option === 'mixed' && spread) + option === 'tab-size' || (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 5e8c72e3..b2291c0b 100644 --- a/packages/remark-lint-list-item-indent/readme.md +++ b/packages/remark-lint-list-item-indent/readme.md @@ -126,14 +126,14 @@ The default export is `remarkLintListItemIndent`. This rule supports standard configuration that all remark lint rules accept (such as `false` to turn it off or `[1, options]` to configure it). -The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab'`) are accepted: +The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab-size'`) are accepted: -* `'one'` +* `'space'` — prefer a single space -* `'tab'` +* `'tab-size'` — prefer spaces the size of the next tab stop * `'mixed'` - — prefer `'one'` for tight lists and `'tab'` for loose lists + — prefer `'space'` for tight lists and `'tab-size'` for loose lists ## Recommendation @@ -159,17 +159,17 @@ Historically, how indentation of lists works in markdown has been a mess, 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'`, which worked the best +Due to this, the default of this list is `'tab-size'`, which worked the best in most markdown parsers. Currently, the situation between markdown parsers is better, so choosing -`'one'` (which seems to be the most common style used by authors) should +`'space'` (which seems to be the most common style used by authors) should be okay. ## Fix [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) -uses `'tab'` by default. -[`settings.listItemIndent: 'one'` or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) +uses `'tab-size'` (named `'tab'` there) by default. +[`settings.listItemIndent: '1'` (for `'space'`) or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) is supported. ## Examples @@ -316,12 +316,12 @@ When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configu ##### `not-ok.md` -When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. +When configured with `'💩'`. ###### Out ```text -1:1: Incorrect list-item indent style `💩`: use either `'tab'`, `'one'`, or `'mixed'` +1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` ``` ## Compatibility