Skip to content

Commit

Permalink
Make rule options default to respective settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Feb 22, 2022
1 parent 72ef7ef commit 20685cf
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 71 deletions.
15 changes: 10 additions & 5 deletions packages/remark-lint-code-block-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* ## API
*
* The following options (default: `'consistent'`) are accepted:
* The following options (default: `'fenced'` if [`settings.fences`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences), `'consistent'` otherwise) are accepted:
*
* * `'fenced'`
* — prefer fenced code blocks:
Expand Down Expand Up @@ -77,7 +77,7 @@
* 7:1-9:4: Code blocks should be indented
*
* @example
* {"setting": "fenced", "name": "ok.md"}
* {"settings": {"fences": true}, "name": "ok.md"}
*
* ```
* alpha()
Expand All @@ -90,7 +90,7 @@
* ```
*
* @example
* {"setting": "fenced", "name": "not-ok-fenced.md", "label": "input"}
* {"settings": {"fences": true}, "name": "not-ok-fenced.md", "label": "input"}
*
* alpha()
*
Expand All @@ -99,7 +99,7 @@
* bravo()
*
* @example
* {"setting": "fenced", "name": "not-ok-fenced.md", "label": "output"}
* {"settings": {"fences": true}, "name": "not-ok-fenced.md", "label": "output"}
*
* 1:1-1:12: Code blocks should be fenced
* 5:1-5:12: Code blocks should be fenced
Expand Down Expand Up @@ -143,9 +143,14 @@ const remarkLintCodeBlockStyle = lintRule(
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-code-block-style#readme'
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
function (tree, file, option) {
const value = String(file)

if (!option) {
const {settings} = this.data()
option = settings && settings.fences ? 'fenced' : 'consistent'
}

if (
option !== 'consistent' &&
option !== 'fenced' &&
Expand Down
6 changes: 3 additions & 3 deletions packages/remark-lint-code-block-style/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The default export is `remarkLintCodeBlockStyle`.
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: `'consistent'`) are accepted:
The following options (default: `'fenced'` if [`settings.fences`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences), `'consistent'` otherwise) are accepted:

* `'fenced'`
— prefer fenced code blocks:
Expand Down Expand Up @@ -207,7 +207,7 @@ bravo()

##### `ok.md`

When configured with `'fenced'`.
When configured with `settings.fences: true`.

###### In

Expand All @@ -229,7 +229,7 @@ No messages.

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

When configured with `'fenced'`.
When configured with `settings.fences: true`.

###### In

Expand Down
18 changes: 14 additions & 4 deletions packages/remark-lint-heading-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* ## API
*
* The following options (default: `'consistent'`) are accepted:
* The following options (default: `'setext'` if [`settings.setext`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext), `'atx-closed'` if [`settings.closeAtx`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx), `'consistent'` otherwise) are accepted:
*
* * `'atx'`
* — prefer ATX headings:
Expand Down Expand Up @@ -71,7 +71,7 @@
* ### Charlie
*
* @example
* {"name": "ok.md", "setting": "atx-closed"}
* {"name": "ok.md", "settings": {"closeAtx": true}}
*
* # Delta ##
*
Expand All @@ -80,7 +80,7 @@
* ### Foxtrot ###
*
* @example
* {"name": "ok.md", "setting": "setext"}
* {"name": "ok.md", "settings": {"setext": true}}
*
* Golf
* ====
Expand Down Expand Up @@ -129,7 +129,17 @@ const remarkLintHeadingStyle = lintRule(
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style#readme'
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
function (tree, file, option) {
if (!option) {
const {settings} = this.data()
option =
settings && settings.setext
? 'setext'
: settings && settings.closeAtx
? 'atx-closed'
: 'consistent'
}

if (
option !== 'consistent' &&
option !== 'atx' &&
Expand Down
6 changes: 3 additions & 3 deletions packages/remark-lint-heading-style/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The default export is `remarkLintHeadingStyle`.
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: `'consistent'`) are accepted:
The following options (default: `'setext'` if [`settings.setext`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext), `'atx-closed'` if [`settings.closeAtx`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx), `'consistent'` otherwise) are accepted:

* `'atx'`
— prefer ATX headings:
Expand Down Expand Up @@ -196,7 +196,7 @@ No messages.

##### `ok.md`

When configured with `'atx-closed'`.
When configured with `settings.closeAtx: true`.

###### In

Expand All @@ -214,7 +214,7 @@ No messages.

##### `ok.md`

When configured with `'setext'`.
When configured with `settings.setext: true`.

###### In

Expand Down
22 changes: 14 additions & 8 deletions packages/remark-lint-link-title-style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* ## API
*
* The following options (default: `'consistent'`) are accepted:
* The following options (default: [`settings.quote`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) or `'consistent'`) are accepted:
*
* * `'"'`
* — prefer double quotes
Expand Down Expand Up @@ -44,7 +44,7 @@
* @copyright 2015 Titus Wormer
* @license MIT
* @example
* {"name": "ok.md", "setting": "\""}
* {"name": "ok.md", "settings": {"quote": "\""}}
*
* [Example](http://example.com#without-title)
* [Example](http://example.com "Example Domain")
Expand All @@ -57,17 +57,17 @@
* [Example](#Heading-(optional))
*
* @example
* {"name": "not-ok.md", "label": "input", "setting": "\""}
* {"name": "not-ok.md", "label": "input", "settings": {"quote": "\""}}
*
* [Example]: http://example.com 'Example Domain'
*
* @example
* {"name": "not-ok.md", "label": "output", "setting": "\""}
* {"name": "not-ok.md", "label": "output", "settings": {"quote": "\""}}
*
* 1:31-1:47: Titles should use `"` as a quote
*
* @example
* {"name": "ok.md", "setting": "'"}
* {"name": "ok.md", "settings": {"quote": "'"}}
*
* [Example](http://example.com#without-title)
* [Example](http://example.com 'Example Domain')
Expand All @@ -76,12 +76,12 @@
* [Example]: http://example.com 'Example Domain'
*
* @example
* {"name": "not-ok.md", "label": "input", "setting": "'"}
* {"name": "not-ok.md", "label": "input", "settings": {"quote": "'"}}
*
* [Example]: http://example.com "Example Domain"
*
* @example
* {"name": "not-ok.md", "label": "output", "setting": "'"}
* {"name": "not-ok.md", "label": "output", "settings": {"quote": "'"}}
*
* 1:31-1:47: Titles should use `'` as a quote
*
Expand Down Expand Up @@ -146,9 +146,15 @@ const remarkLintLinkTitleStyle = lintRule(
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-link-title-style#readme'
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
function (tree, file, option) {
const value = String(file)
const loc = location(file)

if (!option) {
const {settings} = this.data()
option = (settings && settings.quote) || 'consistent'
}

// @ts-expect-error: allow other paren combos.
let look = option === '()' || option === '(' ? ')' : option

Expand Down
10 changes: 5 additions & 5 deletions packages/remark-lint-link-title-style/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The default export is `remarkLintLinkTitleStyle`.
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: `'consistent'`) are accepted:
The following options (default: [`settings.quote`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) or `'consistent'`) are accepted:

* `'"'`
— prefer double quotes
Expand Down Expand Up @@ -160,7 +160,7 @@ There is no option to use parens.

##### `ok.md`

When configured with `'"'`.
When configured with `settings.quote: '"'`.

###### In

Expand All @@ -182,7 +182,7 @@ No messages.

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

When configured with `'"'`.
When configured with `settings.quote: '"'`.

###### In

Expand All @@ -198,7 +198,7 @@ When configured with `'"'`.

##### `ok.md`

When configured with `"'"`.
When configured with `settings.quote: "'"`.

###### In

Expand All @@ -216,7 +216,7 @@ No messages.

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

When configured with `"'"`.
When configured with `settings.quote: "'"`.

###### In

Expand Down
27 changes: 16 additions & 11 deletions packages/remark-lint-list-item-indent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* ## API
*
* The following options (default: `'tab'`) are accepted:
* The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent) or `'tab'`) are accepted:
*
* * `'one'`
* — prefer a single space
Expand Down Expand Up @@ -79,7 +79,7 @@
* ····item.
*
* @example
* {"name": "ok.md", "setting": "mixed"}
* {"name": "ok.md", "settings": {"listItemIndent": "mixed"}}
*
* *·List item.
*
Expand All @@ -96,7 +96,7 @@
* ····item.
*
* @example
* {"name": "ok.md", "setting": "one"}
* {"name": "ok.md", "settings": {"listItemIndent": "one"}}
*
* *·List item.
*
Expand All @@ -113,39 +113,39 @@
* ··item.
*
* @example
* {"name": "not-ok.md", "setting": "one", "label": "input"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "one"}, "label": "input"}
*
* *···List
* ····item.
*
* @example
* {"name": "not-ok.md", "setting": "one", "label": "output"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "one"}, "label": "output"}
*
* 1:5: Incorrect list-item indent: remove 2 spaces
*
* @example
* {"name": "not-ok.md", "setting": "tab", "label": "input"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "tab"}, "label": "input"}
*
* *·List
* ··item.
*
* @example
* {"name": "not-ok.md", "setting": "tab", "label": "output"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "tab"}, "label": "output"}
*
* 1:3: Incorrect list-item indent: add 2 spaces
*
* @example
* {"name": "not-ok.md", "setting": "mixed", "label": "input"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "mixed"}, "label": "input"}
*
* *···List item.
*
* @example
* {"name": "not-ok.md", "setting": "mixed", "label": "output"}
* {"name": "not-ok.md", "settings": {"listItemIndent": "mixed"}, "label": "output"}
*
* 1:5: Incorrect list-item indent: remove 2 spaces
*
* @example
* {"name": "not-ok.md", "setting": "💩", "label": "output", "positionless": true}
* {"name": "not-ok.md", "settings": {"listItemIndent": "💩"}, "label": "output", "positionless": true}
*
* 1:1: Incorrect list-item indent style `💩`: use either `'tab'`, `'one'`, or `'mixed'`
*/
Expand All @@ -169,10 +169,15 @@ const remarkLintListItemIndent = lintRule(
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent#readme'
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'tab') => {
function (tree, file, option) {
const value = String(file)
option = compat[/** @type {never} */ (option)] || option

if (!option) {
const {settings} = this.data()
option = (settings && settings.listItemIndent) || 'tab'
}

if (option !== 'tab' && option !== 'one' && option !== 'mixed') {
file.fail(
'Incorrect list-item indent style `' +
Expand Down
Loading

0 comments on commit 20685cf

Please sign in to comment.