Skip to content

Commit

Permalink
list-item-indent: rename space to one, tab-size to tab
Browse files Browse the repository at this point in the history
This aligns with `remark-stringify` / `mdast-util-to-markdown`
  • Loading branch information
wooorm committed Dec 17, 2023
1 parent 18e669f commit 07140bd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
61 changes: 37 additions & 24 deletions packages/remark-lint-list-item-indent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* ###### Parameters
*
* * `options` ([`Options`][api-options], default: `'tab-size'`)
* * `options` ([`Options`][api-options], default: `'tab'`)
* — preferred style
*
* ###### Returns
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +129,7 @@
* ␠␠␠␠item.
*
* @example
* {"name": "ok.md", "config": "space"}
* {"name": "ok.md", "config": "one"}
*
* *␠List item.
*
Expand All @@ -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
*
Expand All @@ -182,15 +180,15 @@
* @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'`
*/

/**
* @typedef {import('mdast').Root} Root
*/

/**
* @typedef {'mixed' | 'space' | 'tab-size'} Options
* @typedef {'mixed' | 'one' | 'tab'} Options
* Configuration.
*/

Expand All @@ -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'`"
)
}

Expand All @@ -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

Expand Down
30 changes: 14 additions & 16 deletions packages/remark-lint-list-item-indent/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -254,7 +252,7 @@ No messages.

##### `ok.md`

When configured with `'space'`.
When configured with `'one'`.

###### In

Expand All @@ -280,7 +278,7 @@ No messages.

##### `not-ok.md`

When configured with `'space'`.
When configured with `'one'`.

###### In

Expand All @@ -297,7 +295,7 @@ When configured with `'space'`.

##### `not-ok.md`

When configured with `'tab-size'`.
When configured with `'tab'`.

###### In

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-preset-lint-recommended/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '.'],
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-preset-lint-recommended/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | |
Expand Down

0 comments on commit 07140bd

Please sign in to comment.