diff --git a/.remarkrc.js b/.remarkrc.js index f1635aac..07cd9b59 100644 --- a/.remarkrc.js +++ b/.remarkrc.js @@ -7,6 +7,7 @@ import remarkGithub from 'remark-github' import remarkValidateLinks from 'remark-validate-links' import listOfPresets from './script/plugin/list-of-presets.js' import listOfRules from './script/plugin/list-of-rules.js' +import listOfSettings from './script/plugin/list-of-settings.js' const plugins = [ remarkPresetLintRecommended, @@ -17,7 +18,8 @@ const plugins = [ remarkGithub, remarkValidateLinks, listOfPresets, - listOfRules + listOfRules, + listOfSettings ] const preset = {plugins} diff --git a/packages/remark-lint-code-block-style/index.js b/packages/remark-lint-code-block-style/index.js index c41db83b..8c64e318 100644 --- a/packages/remark-lint-code-block-style/index.js +++ b/packages/remark-lint-code-block-style/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'fenced'` * — prefer fenced code blocks: @@ -37,8 +37,8 @@ * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats code blocks as fenced code when they have a language flag and as * indented code otherwise. - * Pass - * [`fences: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences) + * Change + * [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) to `true` * to always use fenced code. * * @module code-block-style @@ -58,6 +58,15 @@ * bravo() * * @example + * {"settings": {"fences": false}, "name": "ok.md"} + * + * alpha() + * + * Paragraph. + * + * bravo() + * + * @example * {"config": "indented", "name": "not-ok.md", "label": "input"} * * ``` @@ -77,6 +86,25 @@ * 7:1-9:4: Code blocks should be indented * * @example + * {"settings": {"fences": false}, "name": "not-ok.md", "label": "input"} + * + * ``` + * alpha() + * ``` + * + * Paragraph. + * + * ``` + * bravo() + * ``` + * + * @example + * {"settings": {"fences": false}, "name": "not-ok.md", "label": "output"} + * + * 1:1-3:4: Code blocks should be indented + * 7:1-9:4: Code blocks should be indented + * + * @example * {"config": "fenced", "name": "ok.md"} * * ``` @@ -90,6 +118,19 @@ * ``` * * @example + * {"settings": {"fences": true}, "name": "ok.md"} + * + * ``` + * alpha() + * ``` + * + * Paragraph. + * + * ``` + * bravo() + * ``` + * + * @example * {"config": "fenced", "name": "not-ok-fenced.md", "label": "input"} * * alpha() @@ -105,6 +146,21 @@ * 5:1-5:12: Code blocks should be fenced * * @example + * {"settings": {"fences": true}, "name": "not-ok-fenced.md", "label": "input"} + * + * alpha() + * + * Paragraph. + * + * bravo() + * + * @example + * {"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 + * + * @example * {"name": "not-ok-consistent.md", "label": "input"} * * alpha() @@ -143,9 +199,20 @@ 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} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = + settings.fences === true + ? 'fenced' + : settings.fences === false + ? 'indented' + : 'consistent' + } + if ( option !== 'consistent' && option !== 'fenced' && diff --git a/packages/remark-lint-code-block-style/readme.md b/packages/remark-lint-code-block-style/readme.md index 56c3fd3a..eb0cba0b 100644 --- a/packages/remark-lint-code-block-style/readme.md +++ b/packages/remark-lint-code-block-style/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'fenced'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `true` | ## Install @@ -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: [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * `'fenced'` — prefer fenced code blocks: @@ -156,15 +156,15 @@ Due to this, it’s recommended to configure this rule with `'fenced'`. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats code blocks as fenced code when they have a language flag and as indented code otherwise. -Pass -[`fences: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences) +Change +[`settings.fences`](https://github.com/remarkjs/remark-lint#configure) to `true` to always use fenced code. ## Examples ##### `ok.md` -When configured with `'indented'`. +When [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `false` and the rule is not configured. ###### In @@ -182,7 +182,7 @@ No messages. ##### `not-ok.md` -When configured with `'indented'`. +When [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `false` and the rule is not configured. ###### In @@ -207,7 +207,7 @@ bravo() ##### `ok.md` -When configured with `'fenced'`. +When [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In @@ -229,7 +229,7 @@ No messages. ##### `not-ok-fenced.md` -When configured with `'fenced'`. +When [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In diff --git a/packages/remark-lint-emphasis-marker/index.js b/packages/remark-lint-emphasis-marker/index.js index 8463709f..e8caf70b 100644 --- a/packages/remark-lint-emphasis-marker/index.js +++ b/packages/remark-lint-emphasis-marker/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'*'` * — prefer asterisks @@ -29,8 +29,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats emphasis with asterisks by default. - * Pass - * [`emphasis: '_'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsemphasis) + * Change + * [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) to `'_'` * to always use underscores. * * @module emphasis-marker @@ -45,6 +45,11 @@ * *foo* * * @example + * {"settings": {"emphasis": "*"}, "name": "ok.md"} + * + * *foo* + * + * @example * {"config": "*", "name": "not-ok.md", "label": "input"} * * _foo_ @@ -55,11 +60,26 @@ * 1:1-1:6: Emphasis should use `*` as a marker * * @example + * {"settings": {"emphasis": "*"}, "name": "not-ok.md", "label": "input"} + * + * _foo_ + * + * @example + * {"settings": {"emphasis": "*"}, "name": "not-ok.md", "label": "output"} + * + * 1:1-1:6: Emphasis should use `*` as a marker + * + * @example * {"config": "_", "name": "ok.md"} * * _foo_ * * @example + * {"settings": {"emphasis": "_"}, "name": "ok.md"} + * + * _foo_ + * + * @example * {"config": "_", "name": "not-ok.md", "label": "input"} * * *foo* @@ -70,6 +90,16 @@ * 1:1-1:6: Emphasis should use `_` as a marker * * @example + * {"settings": {"emphasis": "_"}, "name": "not-ok.md", "label": "input"} + * + * *foo* + * + * @example + * {"settings": {"emphasis": "_"}, "name": "not-ok.md", "label": "output"} + * + * 1:1-1:6: Emphasis should use `_` as a marker + * + * @example * {"name": "not-ok.md", "label": "input"} * * *foo* @@ -84,6 +114,11 @@ * {"config": "💩", "name": "not-ok.md", "label": "output", "positionless": true} * * 1:1: Incorrect emphasis marker `💩`: use either `'consistent'`, `'*'`, or `'_'` + * + * @example + * {"settings": {"emphasis": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true} + * + * 1:1: Incorrect emphasis marker `💩`: use either `'consistent'`, `'*'`, or `'_'` */ /** @@ -102,9 +137,15 @@ const remarkLintEmphasisMarker = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-emphasis-marker#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.emphasis || 'consistent' + } + if (option !== '*' && option !== '_' && option !== 'consistent') { file.fail( 'Incorrect emphasis marker `' + diff --git a/packages/remark-lint-emphasis-marker/readme.md b/packages/remark-lint-emphasis-marker/readme.md index 28ee7272..fbbf0eb9 100644 --- a/packages/remark-lint-emphasis-marker/readme.md +++ b/packages/remark-lint-emphasis-marker/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'*'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'*'` | ## Install @@ -124,7 +124,7 @@ The default export is `remarkLintEmphasisMarker`. 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.emphasis`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * `'*'` — prefer asterisks @@ -148,15 +148,15 @@ can be used for more constructs, it’s recommended to prefer asterisks. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats emphasis with asterisks by default. -Pass -[`emphasis: '_'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsemphasis) +Change +[`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) to `'_'` to always use underscores. ## Examples ##### `ok.md` -When configured with `'*'`. +When [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'*'` and the rule is not configured. ###### In @@ -170,7 +170,7 @@ No messages. ##### `not-ok.md` -When configured with `'*'`. +When [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'*'` and the rule is not configured. ###### In @@ -186,7 +186,7 @@ _foo_ ##### `ok.md` -When configured with `'_'`. +When [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'_'` and the rule is not configured. ###### In @@ -200,7 +200,7 @@ No messages. ##### `not-ok.md` -When configured with `'_'`. +When [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'_'` and the rule is not configured. ###### In @@ -231,7 +231,7 @@ _bar_ ##### `not-ok.md` -When configured with `'💩'`. +When [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-lint-fenced-code-flag/readme.md b/packages/remark-lint-fenced-code-flag/readme.md index 346e1be5..ab504f96 100644 --- a/packages/remark-lint-fenced-code-flag/readme.md +++ b/packages/remark-lint-fenced-code-flag/readme.md @@ -208,22 +208,6 @@ alpha() ##### `ok.md` -When configured with `[ 'alpha' ]`. - -###### In - -````markdown -```alpha -bravo() -``` -```` - -###### Out - -No messages. - -##### `ok.md` - When configured with `{ flags: [ 'alpha' ] }`. ###### In diff --git a/packages/remark-lint-fenced-code-marker/index.js b/packages/remark-lint-fenced-code-marker/index.js index e52b8086..35053038 100644 --- a/packages/remark-lint-fenced-code-marker/index.js +++ b/packages/remark-lint-fenced-code-marker/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * ``'`'`` * — prefer grave accents @@ -23,8 +23,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats fenced code with grave accents by default. - * Pass - * [`fence: '~'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfence) + * Change + * [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) to `'~'` * to always use tildes. * * @module fenced-code-marker @@ -52,6 +52,17 @@ * ``` * * @example + * {"name": "ok.md", "settings": {"fence": "`"}} + * + * ```alpha + * bravo() + * ``` + * + * ``` + * charlie() + * ``` + * + * @example * {"name": "ok.md", "config": "~"} * * ~~~alpha @@ -63,6 +74,17 @@ * ~~~ * * @example + * {"name": "ok.md", "settings": {"fence": "~"}} + * + * ~~~alpha + * bravo() + * ~~~ + * + * ~~~ + * charlie() + * ~~~ + * + * @example * {"name": "not-ok-consistent-tick.md", "label": "input"} * * ```alpha @@ -98,6 +120,11 @@ * {"name": "not-ok-incorrect.md", "config": "💩", "label": "output", "positionless": true} * * 1:1: Incorrect fenced code marker `💩`: use either `'consistent'`, `` '`' ``, or `'~'` + * + * @example + * {"name": "not-ok-incorrect.md", "settings": {"fence": "💩"}, "label": "output", "positionless": true} + * + * 1:1: Incorrect fenced code marker `💩`: use either `'consistent'`, `` '`' ``, or `'~'` */ /** @@ -116,9 +143,15 @@ const remarkLintFencedCodeMarker = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-marker#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const contents = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.fence || 'consistent' + } + if (option !== 'consistent' && option !== '~' && option !== '`') { file.fail( 'Incorrect fenced code marker `' + diff --git a/packages/remark-lint-fenced-code-marker/readme.md b/packages/remark-lint-fenced-code-marker/readme.md index 981fa45f..80e981ef 100644 --- a/packages/remark-lint-fenced-code-marker/readme.md +++ b/packages/remark-lint-fenced-code-marker/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | ``'`'`` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) is ``'`'`` | ## Install @@ -124,7 +124,7 @@ The default export is `remarkLintFencedCodeMarker`. 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.fence`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * ``'`'`` — prefer grave accents @@ -142,8 +142,8 @@ Due to this, it’s recommended to configure this rule with ``'`'``. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats fenced code with grave accents by default. -Pass -[`fence: '~'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfence) +Change +[`settings.fence`](https://github.com/remarkjs/remark-lint#configure) to `'~'` to always use tildes. ## Examples @@ -204,7 +204,7 @@ charlie() ##### `ok.md` -When configured with ``'`'``. +When [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) is ``'`'`` and the rule is not configured. ###### In @@ -224,7 +224,7 @@ No messages. ##### `ok.md` -When configured with `'~'`. +When [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) is `'~'` and the rule is not configured. ###### In @@ -244,7 +244,7 @@ No messages. ##### `not-ok-incorrect.md` -When configured with `'💩'`. +When [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-lint-heading-style/index.js b/packages/remark-lint-heading-style/index.js index 4ed605ec..6a75cba9 100644 --- a/packages/remark-lint-heading-style/index.js +++ b/packages/remark-lint-heading-style/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.setext`](https://github.com/remarkjs/remark-lint#configure), [`settings.closeAtx`](https://github.com/remarkjs/remark-lint#configure), or `'consistent'`) are accepted: * * * `'atx'` * — prefer ATX headings: @@ -51,9 +51,9 @@ * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats headings as ATX by default. * The other styles can be configured with - * [`setext: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext) + * [`settings.setext: true`](https://github.com/remarkjs/remark-lint#configure) * or - * [`closeAtx: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx). + * [`settings.closeAtx: true`](https://github.com/remarkjs/remark-lint#configure). * * @module heading-style * @summary @@ -71,6 +71,15 @@ * ### Charlie * * @example + * {"name": "ok.md", "settings": {"setext": false}} + * + * # Alpha + * + * ## Bravo + * + * ### Charlie + * + * @example * {"name": "ok.md", "config": "atx-closed"} * * # Delta ## @@ -80,6 +89,15 @@ * ### Foxtrot ### * * @example + * {"name": "ok.md", "settings": {"closeAtx": true}} + * + * # Delta ## + * + * ## Echo ## + * + * ### Foxtrot ### + * + * @example * {"name": "ok.md", "config": "setext"} * * Golf @@ -91,6 +109,17 @@ * ### India * * @example + * {"name": "ok.md", "settings": {"setext": true}} + * + * Golf + * ==== + * + * Hotel + * ----- + * + * ### India + * + * @example * {"name": "not-ok.md", "label": "input"} * * Juliett @@ -129,7 +158,20 @@ const remarkLintHeadingStyle = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = + settings.setext === true + ? 'setext' + : settings.closeAtx === true + ? 'atx-closed' + : settings.setext === false || settings.closeAtx === false + ? 'atx' + : 'consistent' + } + if ( option !== 'consistent' && option !== 'atx' && diff --git a/packages/remark-lint-heading-style/readme.md b/packages/remark-lint-heading-style/readme.md index 1eaa2549..912f65a6 100644 --- a/packages/remark-lint-heading-style/readme.md +++ b/packages/remark-lint-heading-style/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'atx'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) is `false` | ## Install @@ -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: [`settings.setext`](https://github.com/remarkjs/remark-lint#configure), [`settings.closeAtx`](https://github.com/remarkjs/remark-lint#configure), or `'consistent'`) are accepted: * `'atx'` — prefer ATX headings: @@ -170,15 +170,15 @@ Due to this, it’s recommended to prefer ATX headings. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats headings as ATX by default. The other styles can be configured with -[`setext: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext) +[`settings.setext: true`](https://github.com/remarkjs/remark-lint#configure) or -[`closeAtx: true`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx). +[`settings.closeAtx: true`](https://github.com/remarkjs/remark-lint#configure). ## Examples ##### `ok.md` -When configured with `'atx'`. +When [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) is `false` and the rule is not configured. ###### In @@ -196,7 +196,7 @@ No messages. ##### `ok.md` -When configured with `'atx-closed'`. +When [`settings.closeAtx`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In @@ -214,7 +214,7 @@ No messages. ##### `ok.md` -When configured with `'setext'`. +When [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In diff --git a/packages/remark-lint-link-title-style/index.js b/packages/remark-lint-link-title-style/index.js index 9e639aaa..2a5ae4ec 100644 --- a/packages/remark-lint-link-title-style/index.js +++ b/packages/remark-lint-link-title-style/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'"'` * — prefer double quotes @@ -32,8 +32,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats titles with double quotes by default. - * Pass - * [`quote: "'"`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) + * Change + * [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) to `"'"` * to use single quotes. * There is no option to use parens. * @@ -57,6 +57,19 @@ * [Example](#Heading-(optional)) * * @example + * {"name": "ok.md", "settings": {"quote": "\""}} + * + * [Example](http://example.com#without-title) + * [Example](http://example.com "Example Domain") + * ![Example](http://example.com "Example Domain") + * + * [Example]: http://example.com "Example Domain" + * + * You can use parens in URLs if they’re not a title (see GH-166): + * + * [Example](#Heading-(optional)) + * + * @example * {"name": "not-ok.md", "label": "input", "config": "\""} * * [Example]: http://example.com 'Example Domain' @@ -67,6 +80,16 @@ * 1:31-1:47: Titles should use `"` as a quote * * @example + * {"name": "not-ok.md", "label": "input", "settings": {"quote": "\""}} + * + * [Example]: http://example.com 'Example Domain' + * + * @example + * {"name": "not-ok.md", "label": "output", "settings": {"quote": "\""}} + * + * 1:31-1:47: Titles should use `"` as a quote + * + * @example * {"name": "ok.md", "config": "'"} * * [Example](http://example.com#without-title) @@ -76,6 +99,15 @@ * [Example]: http://example.com 'Example Domain' * * @example + * {"name": "ok.md", "settings": {"quote": "'"}} + * + * [Example](http://example.com#without-title) + * [Example](http://example.com 'Example Domain') + * ![Example](http://example.com 'Example Domain') + * + * [Example]: http://example.com 'Example Domain' + * + * @example * {"name": "not-ok.md", "label": "input", "config": "'"} * * [Example]: http://example.com "Example Domain" @@ -86,6 +118,16 @@ * 1:31-1:47: Titles should use `'` as a quote * * @example + * {"name": "not-ok.md", "label": "input", "settings": {"quote": "'"}} + * + * [Example]: http://example.com "Example Domain" + * + * @example + * {"name": "not-ok.md", "label": "output", "settings": {"quote": "'"}} + * + * 1:31-1:47: Titles should use `'` as a quote + * + * @example * {"name": "ok.md", "config": "()"} * * [Example](http://example.com#without-title) @@ -119,6 +161,11 @@ * {"name": "not-ok.md", "config": "💩", "label": "output", "positionless": true} * * 1:1: Incorrect link title style marker `💩`: use either `'consistent'`, `'"'`, `'\''`, or `'()'` + * + * @example + * {"name": "not-ok.md", "settings": {"quote": "💩"}, "label": "output", "positionless": true} + * + * 1:1: Incorrect link title style marker `💩`: use either `'consistent'`, `'"'`, `'\''`, or `'()'` */ /** @@ -146,9 +193,16 @@ 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} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) const loc = location(file) + + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.quote || 'consistent' + } + // @ts-expect-error: allow other paren combos. let look = option === '()' || option === '(' ? ')' : option diff --git a/packages/remark-lint-link-title-style/readme.md b/packages/remark-lint-link-title-style/readme.md index 66cfec9a..ccedfe8a 100644 --- a/packages/remark-lint-link-title-style/readme.md +++ b/packages/remark-lint-link-title-style/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'"'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `'"'` | ## Install @@ -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-lint#configure) or `'consistent'`) are accepted: * `'"'` — prefer double quotes @@ -151,8 +151,8 @@ markdown, so it’s recommended to configure this rule with `'"'`. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats titles with double quotes by default. -Pass -[`quote: "'"`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) +Change +[`settings.quote`](https://github.com/remarkjs/remark-lint#configure) to `"'"` to use single quotes. There is no option to use parens. @@ -160,7 +160,7 @@ There is no option to use parens. ##### `ok.md` -When configured with `'"'`. +When [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `'"'` and the rule is not configured. ###### In @@ -182,7 +182,7 @@ No messages. ##### `not-ok.md` -When configured with `'"'`. +When [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `'"'` and the rule is not configured. ###### In @@ -198,7 +198,7 @@ When configured with `'"'`. ##### `ok.md` -When configured with `"'"`. +When [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `"'"` and the rule is not configured. ###### In @@ -216,7 +216,7 @@ No messages. ##### `not-ok.md` -When configured with `"'"`. +When [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `"'"` and the rule is not configured. ###### In @@ -281,7 +281,7 @@ When configured with `'()'`. ##### `not-ok.md` -When configured with `'💩'`. +When [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-lint-list-item-indent/index.js b/packages/remark-lint-list-item-indent/index.js index 753b56dd..a0726bad 100644 --- a/packages/remark-lint-list-item-indent/index.js +++ b/packages/remark-lint-list-item-indent/index.js @@ -6,7 +6,7 @@ * * ## API * - * The following options (default: `'tab-size'`) are accepted: + * The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab-size'`) are accepted: * * * `'space'` * — prefer a single space @@ -49,7 +49,7 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * uses `'tab-size'` (named `'tab'` there) by default. - * [`listItemIndent: '1'` (for `'space'`) or `listItemIndent: 'mixed'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent) + * [`settings.listItemIndent: '1'` (for `'space'`) or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) * is supported. * * @module list-item-indent @@ -96,6 +96,23 @@ * ····item. * * @example + * {"name": "ok.md", "settings": {"listItemIndent": "mixed"}} + * + * *·List item. + * + * Paragraph. + * + * 11.·List item + * + * Paragraph. + * + * *···List + * ····item. + * + * *···List + * ····item. + * + * @example * {"name": "ok.md", "config": "space"} * * *·List item. @@ -113,6 +130,23 @@ * ··item. * * @example + * {"name": "ok.md", "settings": {"listItemIndent": "one"}} + * + * *·List item. + * + * Paragraph. + * + * 11.·List item + * + * Paragraph. + * + * *·List + * ··item. + * + * *·List + * ··item. + * + * @example * {"name": "not-ok.md", "config": "space", "label": "input"} * * *···List @@ -124,6 +158,17 @@ * 1:5: Incorrect list-item indent: remove 2 spaces * * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "one"}, "label": "input"} + * + * *···List + * ····item. + * + * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "one"}, "label": "output"} + * + * 1:5: Incorrect list-item indent: remove 2 spaces + * + * @example * {"name": "not-ok.md", "config": "tab-size", "label": "input"} * * *·List @@ -135,6 +180,17 @@ * 1:3: Incorrect list-item indent: add 2 spaces * * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "tab"}, "label": "input"} + * + * *·List + * ··item. + * + * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "tab"}, "label": "output"} + * + * 1:3: Incorrect list-item indent: add 2 spaces + * + * @example * {"name": "not-ok.md", "config": "mixed", "label": "input"} * * *···List item. @@ -145,6 +201,16 @@ * 1:5: Incorrect list-item indent: remove 2 spaces * * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "mixed"}, "label": "input"} + * + * *···List item. + * + * @example + * {"name": "not-ok.md", "settings": {"listItemIndent": "mixed"}, "label": "output"} + * + * 1:5: Incorrect list-item indent: remove 2 spaces + * + * @example * {"name": "not-ok.md", "config": "💩", "label": "output", "positionless": true} * * 1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` @@ -167,9 +233,20 @@ 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} */ - (tree, file, option = 'tab-size') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = + settings.listItemIndent === 'one' + ? 'space' + : settings.listItemIndent === 'mixed' + ? 'mixed' + : 'tab-size' + } + if (option !== 'tab-size' && option !== 'space' && option !== 'mixed') { file.fail( 'Incorrect list-item indent style `' + diff --git a/packages/remark-lint-list-item-indent/readme.md b/packages/remark-lint-list-item-indent/readme.md index cf15e419..b2291c0b 100644 --- a/packages/remark-lint-list-item-indent/readme.md +++ b/packages/remark-lint-list-item-indent/readme.md @@ -46,8 +46,8 @@ This rule is included in the following presets: | Preset | Setting | | - | - | -| [`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-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'mixed'` | +| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'tab'` | ## Install @@ -126,7 +126,7 @@ 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: `'tab-size'`) are accepted: +The following options (default: [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) or `'tab-size'`) are accepted: * `'space'` — prefer a single space @@ -169,7 +169,7 @@ be okay. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) uses `'tab-size'` (named `'tab'` there) by default. -[`listItemIndent: '1'` (for `'space'`) or `listItemIndent: 'mixed'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent) +[`settings.listItemIndent: '1'` (for `'space'`) or `settings.listItemIndent: 'mixed'`](https://github.com/remarkjs/remark-lint#configure) is supported. ## Examples @@ -204,7 +204,7 @@ No messages. ##### `ok.md` -When configured with `'mixed'`. +When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'mixed'` and the rule is not configured. ###### In @@ -232,7 +232,7 @@ No messages. ##### `not-ok.md` -When configured with `'mixed'`. +When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'mixed'` and the rule is not configured. ###### In @@ -250,7 +250,7 @@ When configured with `'mixed'`. ##### `ok.md` -When configured with `'space'`. +When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'one'` and the rule is not configured. ###### In @@ -278,7 +278,7 @@ No messages. ##### `not-ok.md` -When configured with `'space'`. +When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'one'` and the rule is not configured. ###### In @@ -297,7 +297,7 @@ When configured with `'space'`. ##### `not-ok.md` -When configured with `'tab-size'`. +When [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'tab'` and the rule is not configured. ###### In diff --git a/packages/remark-lint-ordered-list-marker-style/index.js b/packages/remark-lint-ordered-list-marker-style/index.js index 4715e0c1..265dc737 100644 --- a/packages/remark-lint-ordered-list-marker-style/index.js +++ b/packages/remark-lint-ordered-list-marker-style/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'.'` * — prefer dots @@ -25,8 +25,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats ordered lists with dots by default. - * Pass - * [`bulletOrdered: ')'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbulletordered) + * Change + * [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) to `')'` * to always use parens. * * @module ordered-list-marker-style @@ -55,6 +55,13 @@ * 2. Bar * * @example + * {"name": "ok.md", "settings": {"bulletOrdered": "."}} + * + * 1. Foo + * + * 2. Bar + * + * @example * {"name": "ok.md", "config": ")"} * * 1) Foo @@ -62,6 +69,13 @@ * 2) Bar * * @example + * {"name": "ok.md", "settings": {"bulletOrdered": ")"}} + * + * 1) Foo + * + * 2) Bar + * + * @example * {"name": "not-ok.md", "label": "input"} * * 1. Foo @@ -77,6 +91,11 @@ * {"name": "not-ok.md", "label": "output", "config": "💩", "positionless": true} * * 1:1: Incorrect ordered list item marker style `💩`: use either `'.'` or `')'` + * + * @example + * {"name": "not-ok.md", "label": "output", "settings": {"bulletOrdered": "💩"}, "positionless": true} + * + * 1:1: Incorrect ordered list item marker style `💩`: use either `'.'` or `')'` */ /** @@ -96,9 +115,15 @@ const remarkLintOrderedListMarkerStyle = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.bulletOrdered || 'consistent' + } + if (option !== 'consistent' && option !== '.' && option !== ')') { file.fail( 'Incorrect ordered list item marker style `' + diff --git a/packages/remark-lint-ordered-list-marker-style/readme.md b/packages/remark-lint-ordered-list-marker-style/readme.md index e790e9ca..ac036db7 100644 --- a/packages/remark-lint-ordered-list-marker-style/readme.md +++ b/packages/remark-lint-ordered-list-marker-style/readme.md @@ -45,8 +45,8 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'.'` | -| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | `'.'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'.'` | +| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'.'` | ## Install @@ -125,7 +125,7 @@ The default export is `remarkLintOrderedListMarkerStyle`. 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.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * `'.'` — prefer dots @@ -145,8 +145,8 @@ Due to this, it’s recommended to prefer dots. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats ordered lists with dots by default. -Pass -[`bulletOrdered: ')'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbulletordered) +Change +[`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) to `')'` to always use parens. ## Examples @@ -188,7 +188,7 @@ No messages. ##### `ok.md` -When configured with `'.'`. +When [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'.'` and the rule is not configured. ###### In @@ -204,7 +204,7 @@ No messages. ##### `ok.md` -When configured with `')'`. +When [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `')'` and the rule is not configured. ###### In @@ -220,7 +220,7 @@ No messages. ##### `not-ok.md` -When configured with `'💩'`. +When [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-lint-ordered-list-marker-value/index.js b/packages/remark-lint-ordered-list-marker-value/index.js index f95160d4..a6fbec5f 100644 --- a/packages/remark-lint-ordered-list-marker-value/index.js +++ b/packages/remark-lint-ordered-list-marker-value/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'ordered'`) are accepted: + * The following options (default: [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) or `'ordered'`) are accepted: * * * `'ordered'` * — values should increment by one from the first item @@ -29,8 +29,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * retains the value of the first item and increments further items by default. - * Pass - * [`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker) + * Change + * [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) to `false` * to not increment further items. * * @module ordered-list-marker-value @@ -92,6 +92,25 @@ * 0. Foxtrot * * @example + * {"name": "ok.md", "settings": {"incrementListMarker": false}} + * + * 1. Foo + * 1. Bar + * 1. Baz + * + * Paragraph. + * + * 3. Alpha + * 3. Bravo + * 3. Charlie + * + * Paragraph. + * + * 0. Delta + * 0. Echo + * 0. Foxtrot + * + * @example * {"name": "ok.md", "config": "ordered"} * * 1. Foo @@ -111,6 +130,25 @@ * 2. Foxtrot * * @example + * {"name": "ok.md", "settings": {"incrementListMarker": true}} + * + * 1. Foo + * 2. Bar + * 3. Baz + * + * Paragraph. + * + * 3. Alpha + * 4. Bravo + * 5. Charlie + * + * Paragraph. + * + * 0. Delta + * 1. Echo + * 2. Foxtrot + * + * @example * {"name": "not-ok.md", "config": "one", "label": "input"} * * 1. Foo @@ -144,6 +182,17 @@ * 2:1-2:8: Marker should be `2`, was `1` * * @example + * {"name": "not-ok.md", "settings": {"incrementListMarker": true}, "label": "input"} + * + * 1. Foo + * 1. Bar + * + * @example + * {"name": "not-ok.md", "settings": {"incrementListMarker": true}, "label": "output"} + * + * 2:1-2:8: Marker should be `2`, was `1` + * + * @example * {"name": "not-ok.md", "config": "💩", "label": "output", "positionless": true} * * 1:1: Incorrect ordered list item marker value `💩`: use either `'ordered'`, `'one'`, or `'single'` @@ -165,9 +214,15 @@ const remarkLintOrderedListMarkerValue = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'ordered') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.incrementListMarker === false ? 'single' : 'ordered' + } + if (option !== 'ordered' && option !== 'one' && option !== 'single') { file.fail( 'Incorrect ordered list item marker value `' + diff --git a/packages/remark-lint-ordered-list-marker-value/readme.md b/packages/remark-lint-ordered-list-marker-value/readme.md index c16ee8c4..9837636c 100644 --- a/packages/remark-lint-ordered-list-marker-value/readme.md +++ b/packages/remark-lint-ordered-list-marker-value/readme.md @@ -123,7 +123,7 @@ The default export is `remarkLintOrderedListMarkerValue`. 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: `'ordered'`) are accepted: +The following options (default: [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) or `'ordered'`) are accepted: * `'ordered'` — values should increment by one from the first item @@ -147,8 +147,8 @@ choice. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) retains the value of the first item and increments further items by default. -Pass -[`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker) +Change +[`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) to `false` to not increment further items. ## Examples @@ -238,7 +238,7 @@ When configured with `'one'`. ##### `ok.md` -When configured with `'single'`. +When [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) is `false` and the rule is not configured. ###### In @@ -266,7 +266,7 @@ No messages. ##### `ok.md` -When configured with `'ordered'`. +When [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In @@ -294,7 +294,7 @@ No messages. ##### `not-ok.md` -When configured with `'ordered'`. +When [`settings.incrementListMarker`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In diff --git a/packages/remark-lint-rule-style/index.js b/packages/remark-lint-rule-style/index.js index 760f5b49..41de2110 100644 --- a/packages/remark-lint-rule-style/index.js +++ b/packages/remark-lint-rule-style/index.js @@ -6,7 +6,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.rule`](https://github.com/remarkjs/remark-lint#configure), [`settings.ruleRepetition`](https://github.com/remarkjs/remark-lint#configure), [`settings.ruleSpaces`](https://github.com/remarkjs/remark-lint#configure), or `'consistent'`) are accepted: * * * `string` (example: `'** * **'`, `'___'`) * — thematic break to prefer @@ -29,11 +29,11 @@ * formats rules with `***` by default. * There are three settings to control rules: * - * * [`rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule) + * * [`settings.rule`](https://github.com/remarkjs/remark-lint#configure) * (default: `'*'`) — marker - * * [`ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition) + * * [`settings.ruleRepetition`](https://github.com/remarkjs/remark-lint#configure) * (default: `3`) — repetitions - * * [`ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces) + * * [`settings.ruleSpaces`](https://github.com/remarkjs/remark-lint#configure) * (default: `false`) — use spaces between markers * * @module rule-style @@ -50,6 +50,13 @@ * * * * * * @example + * {"name": "ok.md", "settings": {"ruleSpaces": true}} + * + * * * * + * + * * * * + * + * @example * {"name": "ok.md", "config": "_______"} * * _______ @@ -57,6 +64,13 @@ * _______ * * @example + * {"name": "ok.md", "settings": {"rule": "_", "ruleRepetition": 7}} + * + * _______ + * + * _______ + * + * @example * {"name": "not-ok.md", "label": "input"} * * *** @@ -79,6 +93,7 @@ * @typedef {string} Options */ +import {toMarkdown} from 'mdast-util-to-markdown' import {lintRule} from 'unified-lint-rule' import {visit} from 'unist-util-visit' import {pointStart, pointEnd} from 'unist-util-position' @@ -89,9 +104,20 @@ const remarkLintRuleStyle = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = + settings.rule !== undefined || + settings.ruleRepetition !== undefined || + typeof settings.ruleSpaces === 'boolean' + ? toMarkdown({type: 'thematicBreak'}, settings).slice(0, -1) + : 'consistent' + } + if (option !== 'consistent' && /[^-_* ]/.test(option)) { file.fail( "Incorrect preferred rule style: provide a correct markdown rule or `'consistent'`" diff --git a/packages/remark-lint-rule-style/readme.md b/packages/remark-lint-rule-style/readme.md index 90039838..b08793df 100644 --- a/packages/remark-lint-rule-style/readme.md +++ b/packages/remark-lint-rule-style/readme.md @@ -46,7 +46,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'---'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.rule`](https://github.com/remarkjs/remark-lint#configure) is `'-'` | ## Install @@ -125,7 +125,7 @@ The default export is `remarkLintRuleStyle`. 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.rule`](https://github.com/remarkjs/remark-lint#configure), [`settings.ruleRepetition`](https://github.com/remarkjs/remark-lint#configure), [`settings.ruleSpaces`](https://github.com/remarkjs/remark-lint#configure), or `'consistent'`) are accepted: * `string` (example: `'** * **'`, `'___'`) — thematic break to prefer @@ -148,18 +148,18 @@ Due to this, it’s recommended to pass `'***'`. formats rules with `***` by default. There are three settings to control rules: -* [`rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule) +* [`settings.rule`](https://github.com/remarkjs/remark-lint#configure) (default: `'*'`) — marker -* [`ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition) +* [`settings.ruleRepetition`](https://github.com/remarkjs/remark-lint#configure) (default: `3`) — repetitions -* [`ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces) +* [`settings.ruleSpaces`](https://github.com/remarkjs/remark-lint#configure) (default: `false`) — use spaces between markers ## Examples ##### `ok.md` -When configured with `'* * *'`. +When [`settings.ruleSpaces`](https://github.com/remarkjs/remark-lint#configure) is `true` and the rule is not configured. ###### In @@ -175,7 +175,7 @@ No messages. ##### `ok.md` -When configured with `'_______'`. +When [`settings`](https://github.com/remarkjs/remark-lint#configure) includes `{ rule: '_', ruleRepetition: 7 }` and the rule is not configured. ###### In diff --git a/packages/remark-lint-strong-marker/index.js b/packages/remark-lint-strong-marker/index.js index 99d0c655..80d0d64a 100644 --- a/packages/remark-lint-strong-marker/index.js +++ b/packages/remark-lint-strong-marker/index.js @@ -5,7 +5,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'*'` * — prefer asterisks @@ -29,8 +29,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats strong with asterisks by default. - * Pass - * [`strong: '_'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsstrong) + * Change + * [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) to `'_'` * to always use underscores. * * @module strong-marker @@ -55,11 +55,21 @@ * **foo**. * * @example + * {"name": "ok.md", "settings": {"strong": "*"}} + * + * **foo**. + * + * @example * {"name": "ok.md", "config": "_"} * * __foo__. * * @example + * {"name": "ok.md", "settings": {"strong": "_"}} + * + * __foo__. + * + * @example * {"name": "not-ok.md", "label": "input"} * * **foo** and __bar__. @@ -73,6 +83,11 @@ * {"name": "not-ok.md", "label": "output", "config": "💩", "positionless": true} * * 1:1: Incorrect strong marker `💩`: use either `'consistent'`, `'*'`, or `'_'` + * + * @example + * {"name": "not-ok.md", "label": "output", "settings": {"strong": "💩"}, "positionless": true} + * + * 1:1: Incorrect strong marker `💩`: use either `'consistent'`, `'*'`, or `'_'` */ /** @@ -91,9 +106,15 @@ const remarkLintStrongMarker = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.strong || 'consistent' + } + if (option !== '*' && option !== '_' && option !== 'consistent') { file.fail( 'Incorrect strong marker `' + diff --git a/packages/remark-lint-strong-marker/readme.md b/packages/remark-lint-strong-marker/readme.md index ad5ea611..032ee6e7 100644 --- a/packages/remark-lint-strong-marker/readme.md +++ b/packages/remark-lint-strong-marker/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'*'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) is `'*'` | ## Install @@ -124,7 +124,7 @@ The default export is `remarkLintStrongMarker`. 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.strong`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * `'*'` — prefer asterisks @@ -148,8 +148,8 @@ can be used for more constructs, it’s recommended to prefer asterisks. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats strong with asterisks by default. -Pass -[`strong: '_'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsstrong) +Change +[`settings.strong`](https://github.com/remarkjs/remark-lint#configure) to `'_'` to always use underscores. ## Examples @@ -194,7 +194,7 @@ No messages. ##### `ok.md` -When configured with `'*'`. +When [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) is `'*'` and the rule is not configured. ###### In @@ -208,7 +208,7 @@ No messages. ##### `ok.md` -When configured with `'_'`. +When [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) is `'_'` and the rule is not configured. ###### In @@ -222,7 +222,7 @@ No messages. ##### `not-ok.md` -When configured with `'💩'`. +When [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-lint-unordered-list-marker-style/index.js b/packages/remark-lint-unordered-list-marker-style/index.js index ed1714c1..16ccf3a2 100644 --- a/packages/remark-lint-unordered-list-marker-style/index.js +++ b/packages/remark-lint-unordered-list-marker-style/index.js @@ -6,7 +6,7 @@ * * ## API * - * The following options (default: `'consistent'`) are accepted: + * The following options (default: [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * * * `'*'` * — prefer asterisks @@ -27,8 +27,8 @@ * * [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) * formats ordered lists with asterisks by default. - * Pass - * [`bullet: '+'` or `bullet: '-'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbullet) + * Change + * [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) to `'+'` or `'-'` * to always use plusses or dashes. * * @module unordered-list-marker-style @@ -59,16 +59,31 @@ * * Foo * * @example + * {"name": "ok.md", "settings": {"bullet": "*"}} + * + * * Foo + * + * @example * {"name": "ok.md", "config": "-"} * * - Foo * * @example + * {"name": "ok.md", "settings": {"bullet": "-"}} + * + * - Foo + * + * @example * {"name": "ok.md", "config": "+"} * * + Foo * * @example + * {"name": "ok.md", "settings": {"bullet": "+"}} + * + * + Foo + * + * @example * {"name": "not-ok.md", "label": "input"} * * * Foo @@ -85,6 +100,11 @@ * {"name": "not-ok.md", "label": "output", "config": "💩", "positionless": true} * * 1:1: Incorrect unordered list item marker style `💩`: use either `'-'`, `'*'`, or `'+'` + * + * @example + * {"name": "not-ok.md", "label": "output", "settings": {"bullet": "💩"}, "positionless": true} + * + * 1:1: Incorrect unordered list item marker style `💩`: use either `'-'`, `'*'`, or `'+'` */ /** @@ -106,9 +126,15 @@ const remarkLintUnorderedListMarkerStyle = lintRule( url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-unordered-list-marker-style#readme' }, /** @type {import('unified-lint-rule').Rule} */ - (tree, file, option = 'consistent') => { + function (tree, file, option) { const value = String(file) + if (!option) { + /** @type {import('remark-stringify').Options} */ + const settings = this.data().settings || {} + option = settings.bullet || 'consistent' + } + if (option !== 'consistent' && !markers.has(option)) { file.fail( 'Incorrect unordered list item marker style `' + diff --git a/packages/remark-lint-unordered-list-marker-style/readme.md b/packages/remark-lint-unordered-list-marker-style/readme.md index 8ce6077d..ddd3d562 100644 --- a/packages/remark-lint-unordered-list-marker-style/readme.md +++ b/packages/remark-lint-unordered-list-marker-style/readme.md @@ -45,7 +45,7 @@ This rule is included in the following presets: | Preset | Setting | | - | - | -| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'-'` | +| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'-'` | ## Install @@ -124,7 +124,7 @@ The default export is `remarkLintUnorderedListMarkerStyle`. 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.bullet`](https://github.com/remarkjs/remark-lint#configure) or `'consistent'`) are accepted: * `'*'` — prefer asterisks @@ -145,8 +145,8 @@ strong) too. [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) formats ordered lists with asterisks by default. -Pass -[`bullet: '+'` or `bullet: '-'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbullet) +Change +[`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) to `'+'` or `'-'` to always use plusses or dashes. ## Examples @@ -193,7 +193,7 @@ No messages. ##### `ok.md` -When configured with `'*'`. +When [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'*'` and the rule is not configured. ###### In @@ -207,7 +207,7 @@ No messages. ##### `ok.md` -When configured with `'-'`. +When [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'-'` and the rule is not configured. ###### In @@ -221,7 +221,7 @@ No messages. ##### `ok.md` -When configured with `'+'`. +When [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'+'` and the rule is not configured. ###### In @@ -235,7 +235,7 @@ No messages. ##### `not-ok.md` -When configured with `'💩'`. +When [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'💩'` and the rule is not configured. ###### Out diff --git a/packages/remark-preset-lint-consistent/readme.md b/packages/remark-preset-lint-consistent/readme.md index aecc50e1..d24162fa 100644 --- a/packages/remark-preset-lint-consistent/readme.md +++ b/packages/remark-preset-lint-consistent/readme.md @@ -17,6 +17,7 @@ Preset of [`remark-lint`][mono] rules to warn for inconsistencies. * [What is this?](#what-is-this) * [When should I use this?](#when-should-i-use-this) * [Rules](#rules) +* [Settings](#settings) * [Install](#install) * [Use](#use) * [API](#api) @@ -54,6 +55,10 @@ This preset configures [`remark-lint`][mono] with the following rules: | [`remark-lint-strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) | `'consistent'` | | [`remark-lint-table-cell-padding`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-cell-padding) | `'consistent'` | +## Settings + +It doesn't set any remark [settings][configure]. + ## Install This package is [ESM only][esm]. @@ -183,6 +188,8 @@ abide by its terms. [mono]: https://github.com/remarkjs/remark-lint +[configure]: https://github.com/remarkjs/remark-lint#configure + [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c [skypack]: https://www.skypack.dev diff --git a/packages/remark-preset-lint-markdown-style-guide/index.js b/packages/remark-preset-lint-markdown-style-guide/index.js index adb0ad29..2d4a6efb 100644 --- a/packages/remark-preset-lint-markdown-style-guide/index.js +++ b/packages/remark-preset-lint-markdown-style-guide/index.js @@ -36,14 +36,13 @@ * ###### `header` * * The default is `header:atx`. - * To use `header:setext`, change the setting for `remark-lint-heading-style` + * To use `header:setext`, change [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) * like so: * * ```diff - * "plugins": [ + * "settings": [ * … - * "remark-preset-lint-markdown-style-guide", - * + ["remark-lint-heading-style", "setext"], + * + "setext": true, * … * ] * ``` @@ -51,14 +50,13 @@ * ###### `list-marker` * * The default is `list-marker:hyphen`. - * For `list-marker:asterisk` or `list-marker:plus`, change the setting for - * `remark-lint-unordered-list-marker-style` like so: + * For `list-marker:asterisk` or `list-marker:plus`, change [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) + * like so: * * ```diff - * "plugins": [ + * "settings": [ * … - * "remark-preset-lint-markdown-style-guide", - * + ["remark-lint-unordered-list-marker-style", "*"], + * + "bullet": "*", * … * ] * ``` @@ -66,14 +64,13 @@ * ###### `list-space` * * The default is `list-space:mixed`. - * For `list-space:1`, change the setting for `remark-lint-list-item-indent` + * For `list-space:1`, change [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) * like so: * * ```diff - * "plugins": [ + * "settings": [ * … - * "remark-preset-lint-markdown-style-guide", - * + ["remark-lint-list-item-indent", "space"], + * + "listItemIndent": "one", * … * ] * ``` @@ -81,14 +78,13 @@ * ###### `code` * * The default is `code:fenced`. - * For `code:indented`, change the setting for `remark-lint-code-block-style` + * For `code:indented`, change [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) * like so: * * ```diff - * "plugins": [ + * "settings": [ * … - * "remark-preset-lint-markdown-style-guide", - * + ["remark-lint-code-block-style", "indented"], + * + "fences": false, * … * ] * ``` @@ -187,7 +183,7 @@ const remarkPresetLintMarkdownStyleGuide = { remarkLintHardBreakSpaces, // https://cirosantilli.com/markdown-style-guide/#headers - [remarkLintHeadingStyle, 'atx'], + remarkLintHeadingStyle, remarkLintHeadingIncrement, remarkLintNoDuplicateHeadings, @@ -214,14 +210,14 @@ const remarkPresetLintMarkdownStyleGuide = { remarkLintNoBlockquoteWithoutMarker, // https://cirosantilli.com/markdown-style-guide/#unordered - [remarkLintUnorderedListMarkerStyle, '-'], + remarkLintUnorderedListMarkerStyle, // https://cirosantilli.com/markdown-style-guide/#ordered - [remarkLintOrderedListMarkerStyle, '.'], + remarkLintOrderedListMarkerStyle, [remarkLintOrderedListMarkerValue, 'one'], // https://cirosantilli.com/markdown-style-guide/#spaces-after-list-marker - [remarkLintListItemIndent, 'mixed'], + remarkLintListItemIndent, // https://cirosantilli.com/markdown-style-guide/#indentation-of-content-inside-lists remarkLintListItemContentIndent, @@ -239,12 +235,12 @@ const remarkPresetLintMarkdownStyleGuide = { // Not checked. // https://cirosantilli.com/markdown-style-guide/#code-blocks - [remarkLintCodeBlockStyle, 'fenced'], + remarkLintCodeBlockStyle, [remarkLintFencedCodeFlag, {allowEmpty: false}], - [remarkLintFencedCodeMarker, '`'], + remarkLintFencedCodeMarker, // https://cirosantilli.com/markdown-style-guide/#horizontal-rules - [remarkLintRuleStyle, '---'], + remarkLintRuleStyle, // https://cirosantilli.com/markdown-style-guide/#tables remarkLintNoTableIndentation, @@ -266,13 +262,13 @@ const remarkPresetLintMarkdownStyleGuide = { remarkLintDefinitionSpacing, // https://cirosantilli.com/markdown-style-guide/#single-or-double-quote-titles - [remarkLintLinkTitleStyle, '"'], + remarkLintLinkTitleStyle, // https://cirosantilli.com/markdown-style-guide/#bold - [remarkLintStrongMarker, '*'], + remarkLintStrongMarker, // https://cirosantilli.com/markdown-style-guide/#italic - [remarkLintEmphasisMarker, '*'], + remarkLintEmphasisMarker, // https://cirosantilli.com/markdown-style-guide/#uppercase-for-emphasis. // Not checked. @@ -285,7 +281,20 @@ const remarkPresetLintMarkdownStyleGuide = { // https://cirosantilli.com/markdown-style-guide/#email-automatic-links. // Not checked. - ] + ], + settings: { + bullet: '-', + bulletOrdered: '.', + emphasis: '*', + fence: '`', + fences: true, + incrementListMarker: false, + listItemIndent: 'mixed', + quote: '"', + rule: '-', + setext: false, + strong: '*' + } } export default remarkPresetLintMarkdownStyleGuide diff --git a/packages/remark-preset-lint-markdown-style-guide/readme.md b/packages/remark-preset-lint-markdown-style-guide/readme.md index bf0751e4..06a80f38 100644 --- a/packages/remark-preset-lint-markdown-style-guide/readme.md +++ b/packages/remark-preset-lint-markdown-style-guide/readme.md @@ -17,6 +17,7 @@ Preset of [`remark-lint`][mono] rules that follow an opinionated style guide. * [What is this?](#what-is-this) * [When should I use this?](#when-should-i-use-this) * [Rules](#rules) +* [Settings](#settings) * [Install](#install) * [Use](#use) * [API](#api) @@ -68,14 +69,13 @@ To use `wrap:no`, turn off `remark-lint-maximum-line-length` like so: ###### `header` The default is `header:atx`. -To use `header:setext`, change the setting for `remark-lint-heading-style` +To use `header:setext`, change [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) like so: ```diff - "plugins": [ + "settings": [ … - "remark-preset-lint-markdown-style-guide", -+ ["remark-lint-heading-style", "setext"], ++ "setext": true, … ] ``` @@ -83,14 +83,13 @@ like so: ###### `list-marker` The default is `list-marker:hyphen`. -For `list-marker:asterisk` or `list-marker:plus`, change the setting for -`remark-lint-unordered-list-marker-style` like so: +For `list-marker:asterisk` or `list-marker:plus`, change [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) +like so: ```diff - "plugins": [ + "settings": [ … - "remark-preset-lint-markdown-style-guide", -+ ["remark-lint-unordered-list-marker-style", "*"], ++ "bullet": "*", … ] ``` @@ -98,14 +97,13 @@ For `list-marker:asterisk` or `list-marker:plus`, change the setting for ###### `list-space` The default is `list-space:mixed`. -For `list-space:1`, change the setting for `remark-lint-list-item-indent` +For `list-space:1`, change [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) like so: ```diff - "plugins": [ + "settings": [ … - "remark-preset-lint-markdown-style-guide", -+ ["remark-lint-list-item-indent", "space"], ++ "listItemIndent": "one", … ] ``` @@ -113,14 +111,13 @@ like so: ###### `code` The default is `code:fenced`. -For `code:indented`, change the setting for `remark-lint-code-block-style` +For `code:indented`, change [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) like so: ```diff - "plugins": [ + "settings": [ … - "remark-preset-lint-markdown-style-guide", -+ ["remark-lint-code-block-style", "indented"], ++ "fences": false, … ] ``` @@ -141,7 +138,7 @@ This preset configures [`remark-lint`][mono] with the following rules: | [`remark-lint-maximum-line-length`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-maximum-line-length) | `80` | | [`remark-lint-no-shell-dollars`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-shell-dollars) | | | [`remark-lint-hard-break-spaces`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-hard-break-spaces) | | -| [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | `'atx'` | +| [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | [`settings.setext`](https://github.com/remarkjs/remark-lint#configure) is `false` | | [`remark-lint-heading-increment`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-increment) | | | [`remark-lint-no-duplicate-headings`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-duplicate-headings) | | | [`remark-lint-no-multiple-toplevel-headings`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-multiple-toplevel-headings) | | @@ -149,16 +146,16 @@ This preset configures [`remark-lint`][mono] with the following rules: | [`remark-lint-no-heading-punctuation`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-heading-punctuation) | `':.'` | | [`remark-lint-blockquote-indentation`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-blockquote-indentation) | `2` | | [`remark-lint-no-blockquote-without-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-blockquote-without-marker) | | -| [`remark-lint-unordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-unordered-list-marker-style) | `'-'` | -| [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) | `'.'` | +| [`remark-lint-unordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-unordered-list-marker-style) | [`settings.bullet`](https://github.com/remarkjs/remark-lint#configure) is `'-'` | +| [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) | [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'.'` | | [`remark-lint-ordered-list-marker-value`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value) | `'one'` | -| [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) | `'mixed'` | +| [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) | [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'mixed'` | | [`remark-lint-list-item-content-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-content-indent) | | | [`remark-lint-list-item-spacing`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-spacing) | | -| [`remark-lint-code-block-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-code-block-style) | `'fenced'` | +| [`remark-lint-code-block-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-code-block-style) | [`settings.fences`](https://github.com/remarkjs/remark-lint#configure) is `true` | | [`remark-lint-fenced-code-flag`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-flag) | `{ allowEmpty: false }` | -| [`remark-lint-fenced-code-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-marker) | ``'`'`` | -| [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) | `'---'` | +| [`remark-lint-fenced-code-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-marker) | [`settings.fence`](https://github.com/remarkjs/remark-lint#configure) is ``'`'`` | +| [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) | [`settings.rule`](https://github.com/remarkjs/remark-lint#configure) is `'-'` | | [`remark-lint-no-table-indentation`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-table-indentation) | | | [`remark-lint-table-pipes`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-pipes) | | | [`remark-lint-table-pipe-alignment`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-pipe-alignment) | | @@ -169,12 +166,31 @@ This preset configures [`remark-lint`][mono] with the following rules: | [`remark-lint-final-definition`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-final-definition) | | | [`remark-lint-definition-case`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-definition-case) | | | [`remark-lint-definition-spacing`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-definition-spacing) | | -| [`remark-lint-link-title-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-link-title-style) | `'"'` | -| [`remark-lint-strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) | `'*'` | -| [`remark-lint-emphasis-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-emphasis-marker) | `'*'` | +| [`remark-lint-link-title-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-link-title-style) | [`settings.quote`](https://github.com/remarkjs/remark-lint#configure) is `'"'` | +| [`remark-lint-strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) | [`settings.strong`](https://github.com/remarkjs/remark-lint#configure) is `'*'` | +| [`remark-lint-emphasis-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-emphasis-marker) | [`settings.emphasis`](https://github.com/remarkjs/remark-lint#configure) is `'*'` | | [`remark-lint-no-emphasis-as-heading`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-emphasis-as-heading) | | | [`remark-lint-no-literal-urls`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-literal-urls) | | +## Settings + +It sets the following remark [settings][configure]. +Settings are shared among all plugins --- particularly the corresponding rules and [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options): + +| Name | Value | +| - | - | +| `settings.bullet` | `'-'` | +| `settings.bulletOrdered` | `'.'` | +| `settings.emphasis` | `'*'` | +| `settings.fence` | ``'`'`` | +| `settings.fences` | `true` | +| `settings.incrementListMarker` | `false` | +| `settings.listItemIndent` | `'mixed'` | +| `settings.quote` | `'"'` | +| `settings.rule` | `'-'` | +| `settings.setext` | `false` | +| `settings.strong` | `'*'` | + ## Install This package is [ESM only][esm]. @@ -304,6 +320,8 @@ abide by its terms. [mono]: https://github.com/remarkjs/remark-lint +[configure]: https://github.com/remarkjs/remark-lint#configure + [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c [skypack]: https://www.skypack.dev diff --git a/packages/remark-preset-lint-recommended/index.js b/packages/remark-preset-lint-recommended/index.js index dae28742..98360087 100644 --- a/packages/remark-preset-lint-recommended/index.js +++ b/packages/remark-preset-lint-recommended/index.js @@ -35,10 +35,10 @@ const remarkPresetLintRecommended = { remarkLintFinalNewline, // Rendering across vendors differs greatly if using other styles. remarkLintListItemBulletIndent, - [remarkLintListItemIndent, 'tab-size'], + remarkLintListItemIndent, remarkLintNoBlockquoteWithoutMarker, remarkLintNoLiteralUrls, - [remarkLintOrderedListMarkerStyle, '.'], + remarkLintOrderedListMarkerStyle, // Mistakes. remarkLintHardBreakSpaces, remarkLintNoDuplicateDefinitions, @@ -48,7 +48,11 @@ const remarkPresetLintRecommended = { remarkLintNoShortcutReferenceLink, remarkLintNoUndefinedReferences, remarkLintNoUnusedDefinitions - ] + ], + settings: { + bulletOrdered: '.', + listItemIndent: 'tab' + } } export default remarkPresetLintRecommended diff --git a/packages/remark-preset-lint-recommended/readme.md b/packages/remark-preset-lint-recommended/readme.md index f0c46678..b65830e1 100644 --- a/packages/remark-preset-lint-recommended/readme.md +++ b/packages/remark-preset-lint-recommended/readme.md @@ -17,6 +17,7 @@ Preset of [`remark-lint`][mono] rules to warn for some likely problems. * [What is this?](#what-is-this) * [When should I use this?](#when-should-i-use-this) * [Rules](#rules) +* [Settings](#settings) * [Install](#install) * [Use](#use) * [API](#api) @@ -43,10 +44,10 @@ This preset configures [`remark-lint`][mono] with the following rules: | - | - | | [`remark-lint-final-newline`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-final-newline) | | | [`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) | [`settings.listItemIndent`](https://github.com/remarkjs/remark-lint#configure) is `'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-literal-urls`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-literal-urls) | | -| [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) | `'.'` | +| [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) | [`settings.bulletOrdered`](https://github.com/remarkjs/remark-lint#configure) is `'.'` | | [`remark-lint-hard-break-spaces`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-hard-break-spaces) | | | [`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) | | @@ -56,6 +57,16 @@ This preset configures [`remark-lint`][mono] with the following rules: | [`remark-lint-no-undefined-references`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-undefined-references) | | | [`remark-lint-no-unused-definitions`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-unused-definitions) | | +## Settings + +It sets the following remark [settings][configure]. +Settings are shared among all plugins --- particularly the corresponding rules and [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options): + +| Name | Value | +| - | - | +| `settings.bulletOrdered` | `'.'` | +| `settings.listItemIndent` | `'tab'` | + ## Install This package is [ESM only][esm]. @@ -185,6 +196,8 @@ abide by its terms. [mono]: https://github.com/remarkjs/remark-lint +[configure]: https://github.com/remarkjs/remark-lint#configure + [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c [skypack]: https://www.skypack.dev diff --git a/packages/unified-lint-rule/index.d.ts b/packages/unified-lint-rule/index.d.ts index 7ee1944b..99819003 100644 --- a/packages/unified-lint-rule/index.d.ts +++ b/packages/unified-lint-rule/index.d.ts @@ -24,6 +24,7 @@ export function lintRule( > export type Rule = ( + this: Processor, node: Tree, file: VFile, options: Options diff --git a/packages/unified-lint-rule/lib/index.js b/packages/unified-lint-rule/lib/index.js index f86eea68..0562fffd 100644 --- a/packages/unified-lint-rule/lib/index.js +++ b/packages/unified-lint-rule/lib/index.js @@ -67,7 +67,7 @@ export function lintRule(meta, rule) { } next() - })(tree, file, options) + }).call(this, tree, file, options) } } } diff --git a/readme.md b/readme.md index f7df9b3c..0f22b97c 100644 --- a/readme.md +++ b/readme.md @@ -238,7 +238,13 @@ For help creating your own rule, it’s suggested to look at existing rules and -All rules can be configured in one standard way: +Just like other remark plugins, there are a couple ways to configure rules. +They all follow a standard approach: + +* Pass a severity, options, or both to the rules themselves. + This affects each rule individually and takes highest precedence. +* Some rules correspond to settings that are shared among all remark plugins --- particularly [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options). +* Using presets, you can change any combination of rules' severity, rules' options, or shared settings. ```js import {remark} from 'remark' @@ -274,9 +280,48 @@ remark() .use(remarkLintMaximumLineLength, [1, 72]) ``` -See [`use()` in `unified`s readme][unified-use] for more info on how to use +See [`use()` in `unified`'s readme][unified-use] for more info on how to use plugins. +Use the following remark settings to configure both the corresponding rules and [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options): + + + +| Setting | Rule | +| - | - | +| [`settings.bullet`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbullet) | [`remark-lint-unordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-unordered-list-marker-style) | +| [`settings.bulletOrdered`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsbulletordered) | [`remark-lint-ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) | +| [`settings.closeAtx`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionscloseatx) | [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | +| [`settings.emphasis`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsemphasis) | [`remark-lint-emphasis-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-emphasis-marker) | +| [`settings.fence`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfence) | [`remark-lint-fenced-code-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-fenced-code-marker) | +| [`settings.fences`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsfences) | [`remark-lint-code-block-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-code-block-style) | +| [`settings.incrementListMarker`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker) | [`remark-lint-ordered-list-marker-value`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value) | +| [`settings.listItemIndent`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent) | [`remark-lint-list-item-indent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent) | +| [`settings.quote`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsquote) | [`remark-lint-link-title-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-link-title-style) | +| [`settings.rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) | +| [`settings.ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) | +| [`settings.ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces) | [`remark-lint-rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) | +| [`settings.setext`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionssetext) | [`remark-lint-heading-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-heading-style) | +| [`settings.strong`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsstrong) | [`remark-lint-strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) | + + + +```js +import {remark} from 'remark' +import remarkLintUnorderedListMarkerStyle from 'remark-lint-unordered-list-marker-style' + +remark() + .use(remarkLintUnorderedListMarkerStyle) + .use({settings: {bullet: '*'}}) +``` + +See [remark][] for how to configure plugins and settings on the API, and [`remark-cli`][remark-cli] for the places the CLI looks for configuration. + +> 🧑‍🏫 **Info**: remark lint rules *check* markdown. +> [`remark-stringify`][remark-stringify] *formats* markdown. +> They behave consistently when you change shared settings that they both understand, but not if you pass options to rules individually. +> Passing options to rules individually doesn't affect [`remark-stringify`][remark-stringify] or vice versa. + > 🧑‍🏫 **Info**: messages in `remark-lint` are warnings instead of errors. > Other linters (such as ESLint) almost always use errors. > Why? @@ -364,7 +409,6 @@ import {reporter} from 'vfile-reporter' import {remark} from 'remark' import remarkPresetLintConsistent from 'remark-preset-lint-consistent' import remarkPresetLintRecommended from 'remark-preset-lint-recommended' -import remarkLintListItemIndent from 'remark-lint-list-item-indent' main() @@ -374,10 +418,12 @@ async function main() { .use(remarkPresetLintConsistent) // Few recommended rules. .use(remarkPresetLintRecommended) - // `remark-lint-list-item-indent` is configured with `tab-size` in the - // recommended preset, but if we’d prefer something else, it can be - // reconfigured: - .use(remarkLintListItemIndent, 'space') + .use({ + // `settings.listItemIndent` is set to `tab` in the + // recommended preset, but you can + // change it if you’d prefer something else: + settings: {listItemIndent: 'one'} + }) .process('1) Hello, _Jupiter_ and *Neptune*!') console.error(reporter(file)) @@ -398,8 +444,6 @@ Running that with `node example.js` yields: remark lint rules *check* markdown. [`remark-stringify`][remark-stringify] (used in remark) *formats* markdown. -When you configure lint rules and use remark to format markdown, you must -manually synchronize their configuration: ```js import {reporter} from 'vfile-reporter' @@ -411,10 +455,11 @@ main() async function main() { const file = await remark() - .use(remarkLintEmphasisMarker, '*') - .use(remarkLintStrongMarker, '*') + .use(remarkLintEmphasisMarker) + .use(remarkLintStrongMarker) .use({ - settings: {emphasis: '*', strong: '*'} // `remark-stringify` settings. + // Configure both the rules and `remark-stringify`. + settings: {emphasis: '*', strong: '*'} }) .process('_Hello_, __world__!') @@ -475,16 +520,15 @@ Now add a `remarkConfig` to your `package.json` to configure remark: ```js /* … */ "remarkConfig": { + "settings": { + // `settings.listItemIndent` is set to `tab` in the + // recommended preset, but you can + // change it if you’d prefer something else: + "listItemIndent": "one" + }, "plugins": [ "remark-preset-lint-consistent", // Check that markdown is consistent. - "remark-preset-lint-recommended", // Few recommended rules. - // `remark-lint-list-item-indent` is configured with `tab-size` in the - // recommended preset, but if we’d prefer something else, it can be - // reconfigured: - [ - "remark-lint-list-item-indent", - "space" - ] + "remark-preset-lint-recommended" // Few recommended rules. ] }, /* … */ @@ -503,8 +547,6 @@ npm run check remark lint rules *check* markdown. The CLI can *format* markdown. -You can combine these features but have to manually synchronize their -configuration. Please first follow the previous example (checking markdown on the CLI) and then change the npm script: @@ -533,17 +575,14 @@ Update `remarkConfig`: }, "plugins": [ "remark-preset-lint-consistent", - "remark-preset-lint-recommended", - ["remark-lint-list-item-indent", "space"] - ["remark-lint-emphasis-marker", "*"], - ["remark-lint-strong-marker", "*"] + "remark-preset-lint-recommended" ] }, /* … */ ``` -This now includes `settings`, which configures -[`remark-stringify`][remark-stringify], and explicitly prefers asterisks +`settings` configures both the rules and +[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options), and explicitly prefers asterisks for emphasis and strong. Install the new dependencies: diff --git a/script/build-presets.js b/script/build-presets.js index 46e815d0..7a1d5829 100644 --- a/script/build-presets.js +++ b/script/build-presets.js @@ -29,7 +29,7 @@ presets(root).then((presetObjects) => { let index = -1 while (++index < presetObjects.length) { - const {name, packages} = presetObjects[index] + const {name, packages, settings} = presetObjects[index] const base = path.resolve(root, name) /** @type {PackageJson} */ const pack = JSON.parse( @@ -112,8 +112,6 @@ presets(root).then((presetObjects) => { const url = remote + '/tree/main/packages/' + rule const option = packages[rule] - if (rule === 'remark-lint') continue - rows.push({ type: 'tableRow', children: [ @@ -130,9 +128,7 @@ presets(root).then((presetObjects) => { }, { type: 'tableCell', - children: option - ? [{type: 'inlineCode', value: inspect(option)}] - : [] + children: option || [] } ] }) @@ -311,6 +307,89 @@ presets(root).then((presetObjects) => { ] }, {type: 'table', align: [], children: rows}, + { + type: 'heading', + depth: 2, + children: [{type: 'text', value: 'Settings'}] + }, + .../** @type {Array} */ ( + settings + ? [ + { + type: 'paragraph', + children: [ + {type: 'text', value: 'It sets the following remark '}, + { + type: 'linkReference', + identifier: 'configure', + referenceType: 'full', + children: [{type: 'text', value: 'settings'}] + }, + { + type: 'text', + value: + '.\nSettings are shared among all plugins --- particularly the corresponding rules and ' + }, + { + type: 'link', + url: 'https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options', + title: null, + children: [{type: 'inlineCode', value: 'remark-stringify'}] + }, + {type: 'text', value: ':'} + ] + }, + { + type: 'table', + align: [], + children: [ + { + type: 'tableRow', + children: [ + { + type: 'tableCell', + children: [{type: 'text', value: 'Name'}] + }, + { + type: 'tableCell', + children: [{type: 'text', value: 'Value'}] + } + ] + }, + ...Object.entries(settings).map(([name, value]) => ({ + type: 'tableRow', + children: [ + { + type: 'tableCell', + children: [ + {type: 'inlineCode', value: `settings.${name}`} + ] + }, + { + type: 'tableCell', + children: [{type: 'inlineCode', value: inspect(value)}] + } + ] + })) + ] + } + ] + : [ + { + type: 'paragraph', + children: [ + {type: 'text', value: "It doesn't set any remark "}, + { + type: 'linkReference', + identifier: 'configure', + referenceType: 'full', + children: [{type: 'text', value: 'settings'}] + }, + {type: 'text', value: '.'} + ] + } + ] + ), { type: 'heading', depth: 2, @@ -664,6 +743,11 @@ presets(root).then((presetObjects) => { identifier: 'mono', url: 'https://github.com/' + slug }, + { + type: 'definition', + identifier: 'configure', + url: `https://github.com/${slug}#configure` + }, { type: 'definition', identifier: 'esm', diff --git a/script/build-rules.js b/script/build-rules.js index 4e6f0d85..8d645aeb 100644 --- a/script/build-rules.js +++ b/script/build-rules.js @@ -2,6 +2,7 @@ * @typedef {import('type-fest').PackageJson} PackageJson * @typedef {import('mdast').BlockContent|import('mdast').DefinitionContent} BlockContent * @typedef {import('mdast').TableContent} TableContent + * @typedef {import('mdast').PhrasingContent} PhrasingContent */ import fs from 'node:fs' @@ -18,12 +19,10 @@ import GitHubSlugger from 'github-slugger' import parseAuthor from 'parse-author' import {rules} from './util/rules.js' import {rule} from './util/rule.js' -import {presets} from './util/presets.js' +import {formatSettings, presets} from './util/presets.js' import {repoUrl} from './util/repo-url.js' import {characters} from './characters.js' -const own = {}.hasOwnProperty - const remote = repoUrl('package.json') const root = path.join(process.cwd(), 'packages') @@ -341,9 +340,7 @@ presets(root).then((presetObjects) => { }, { type: 'tableCell', - children: option - ? [{type: 'inlineCode', value: inspect(option)}] - : [] + children: option || [] } ] } @@ -565,148 +562,158 @@ presets(root).then((presetObjects) => { ...(categories.example || []) ) + // Don't show the same test for both shared settings and rules' options. + const inverted = Object.fromEntries( + Object.entries(tests).map(([key, value]) => [ + JSON.stringify(value), + key + ]) + ) let first = true - /** @type {string} */ - let configuration - for (configuration in tests) { - if (own.call(tests, configuration)) { - const fixtures = tests[configuration] + for (const [fixtures, configuration] of Object.entries(inverted)) { + if (first) { + children.push({ + type: 'heading', + depth: 2, + children: [{type: 'text', value: 'Examples'}] + }) + first = false + } + + for (const [fileName, fixture] of Object.entries( + /** @type {tests[keyof tests]} */ (JSON.parse(fixtures)) + )) { + /** @type {{settings: Record, config: unknown}} */ + const {settings, config} = JSON.parse(configuration) + let clean = fixture.input + + children.push({ + type: 'heading', + depth: 5, + children: [{type: 'inlineCode', value: fileName}] + }) - if (first) { + if (settings || config !== true) { children.push({ - type: 'heading', - depth: 2, - children: [{type: 'text', value: 'Examples'}] + type: 'paragraph', + children: [ + {type: 'text', value: 'When '}, + .../** @type {Array} */ ( + settings + ? [ + ...formatSettings(settings), + {type: 'text', value: ' and '} + ] + : [] + ), + .../** @type {Array} */ ( + config === true + ? [{type: 'text', value: 'the rule is not configured'}] + : [ + {type: 'text', value: 'configured with '}, + {type: 'inlineCode', value: inspect(config)} + ] + ), + {type: 'text', value: '.'} + ] }) - first = false } - /** @type {string} */ - let fileName - - for (fileName in fixtures) { - if (own.call(fixtures, fileName)) { - const fixture = fixtures[fileName] - /** @type {{config: unknown}} */ - const {config} = JSON.parse(configuration) - let clean = fixture.input + if ( + fixture.input !== null && + fixture.input !== undefined && + fixture.input.trim() !== '' + ) { + children.push({ + type: 'heading', + depth: 6, + children: [{type: 'text', value: 'In'}] + }) + if (fixture.gfm) { + hasGfm = true children.push({ - type: 'heading', - depth: 5, - children: [{type: 'inlineCode', value: fileName}] - }) - - if (config !== true) { - children.push({ - type: 'paragraph', - children: [ - {type: 'text', value: 'When configured with '}, - {type: 'inlineCode', value: inspect(config)}, - {type: 'text', value: '.'} - ] - }) - } - - if ( - fixture.input !== null && - fixture.input !== undefined && - fixture.input.trim() !== '' - ) { - children.push({ - type: 'heading', - depth: 6, - children: [{type: 'text', value: 'In'}] - }) - - if (fixture.gfm) { - hasGfm = true - children.push({ - type: 'blockquote', + type: 'blockquote', + children: [ + { + type: 'paragraph', children: [ + {type: 'text', value: '👉 '}, + { + type: 'strong', + children: [{type: 'text', value: 'Note'}] + }, + {type: 'text', value: ': this example uses GFM ('}, { - type: 'paragraph', - children: [ - {type: 'text', value: '👉 '}, - { - type: 'strong', - children: [{type: 'text', value: 'Note'}] - }, - {type: 'text', value: ': this example uses GFM ('}, - { - type: 'linkReference', - identifier: 'gfm', - referenceType: 'full', - children: [ - {type: 'inlineCode', value: 'remark-gfm'} - ] - }, - {type: 'text', value: ').'} - ] - } + type: 'linkReference', + identifier: 'gfm', + referenceType: 'full', + children: [{type: 'inlineCode', value: 'remark-gfm'}] + }, + {type: 'text', value: ').'} ] - }) - } + } + ] + }) + } - let index = -1 - while (++index < characters.length) { - const char = characters[index] - const next = clean.replace(char.in, char.out) + let index = -1 + while (++index < characters.length) { + const char = characters[index] + const next = clean.replace(char.in, char.out) - if (clean !== next) { - children.push({ - type: 'blockquote', + if (clean !== next) { + children.push({ + type: 'blockquote', + children: [ + { + type: 'paragraph', children: [ + {type: 'text', value: '👉 '}, + { + type: 'strong', + children: [{type: 'text', value: 'Note'}] + }, + {type: 'text', value: ': '}, + {type: 'inlineCode', value: char.char}, { - type: 'paragraph', - children: [ - {type: 'text', value: '👉 '}, - { - type: 'strong', - children: [{type: 'text', value: 'Note'}] - }, - {type: 'text', value: ': '}, - {type: 'inlineCode', value: char.char}, - { - type: 'text', - value: ' represents ' + char.name + '.' - } - ] + type: 'text', + value: ' represents ' + char.name + '.' } ] - }) - - clean = next - } - } - - children.push({ - type: 'code', - lang: 'markdown', - value: fixture.input + } + ] }) - } - - children.push({ - type: 'heading', - depth: 6, - children: [{type: 'text', value: 'Out'}] - }) - if (fixture.output.length === 0) { - children.push({ - type: 'paragraph', - children: [{type: 'text', value: 'No messages.'}] - }) - } else { - children.push({ - type: 'code', - lang: 'text', - value: fixture.output.join('\n') - }) + clean = next } } + + children.push({ + type: 'code', + lang: 'markdown', + value: fixture.input + }) + } + + children.push({ + type: 'heading', + depth: 6, + children: [{type: 'text', value: 'Out'}] + }) + + if (fixture.output.length === 0) { + children.push({ + type: 'paragraph', + children: [{type: 'text', value: 'No messages.'}] + }) + } else { + children.push({ + type: 'code', + lang: 'text', + value: fixture.output.join('\n') + }) } } } diff --git a/script/plugin/list-of-settings.js b/script/plugin/list-of-settings.js new file mode 100644 index 00000000..0d2a56ba --- /dev/null +++ b/script/plugin/list-of-settings.js @@ -0,0 +1,71 @@ +import path from 'node:path' +import process from 'node:process' +import {zone} from 'mdast-zone' +import {repoUrl} from '../util/repo-url.js' +import {rule} from '../util/rule.js' +import {rules} from '../util/rules.js' + +const root = path.join(process.cwd(), 'packages') + +/** @type {import('unified').Plugin, import('mdast').Root>} */ +export default function listOfSettings() { + const rows = rules(root).flatMap((basename) => + Array.from( + new Set( + Object.keys(rule(path.join(root, basename)).tests).flatMap( + (configuration) => { + /** @type {{settings: Record}} */ + const {settings} = JSON.parse(configuration) + return Object.keys(settings || {}) + } + ) + ), + (name) => [name, basename] + ) + ) + rows.sort() + /** @type {import('mdast').Table} */ + const table = { + type: 'table', + children: [ + { + type: 'tableRow', + children: [ + {type: 'tableCell', children: [{type: 'text', value: 'Setting'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'Rule'}]} + ] + }, + .../** @type {Array} */ ( + rows.map(([name, basename]) => ({ + type: 'tableRow', + children: [ + { + type: 'tableCell', + children: [ + { + type: 'link', + url: `https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options${name.toLowerCase()}`, + children: [{type: 'inlineCode', value: `settings.${name}`}] + } + ] + }, + { + type: 'tableCell', + children: [ + { + type: 'link', + url: repoUrl(path.join(root, basename, 'package.json')), + children: [{type: 'inlineCode', value: basename}] + } + ] + } + ] + })) + ) + ] + } + + return (tree) => { + zone(tree, 'settings', (start, _, end) => [start, table, end]) + } +} diff --git a/script/util/presets.js b/script/util/presets.js index 64795492..9961cb66 100644 --- a/script/util/presets.js +++ b/script/util/presets.js @@ -1,4 +1,5 @@ /** + * @typedef {import('mdast').PhrasingContent} PhrasingContent * @typedef {import('unified').Preset} Preset * @typedef {import('unified').Plugin} Plugin */ @@ -6,10 +7,13 @@ import {promises as fs} from 'node:fs' import path from 'node:path' import url from 'node:url' +import {inspect} from 'node:util' +import remarkLint from 'remark-lint' +import {rule} from './rule.js' /** * @param {string} base - * @returns {Promise}>>} + * @returns {Promise|undefined>, settings: Record|undefined}>>} */ export async function presets(base) { const allFiles = await fs.readdir(base) @@ -26,7 +30,8 @@ export async function presets(base) { // type-coverage:ignore-next-line const preset = presetMod.default const plugins = preset.plugins || [] - /** @type {Record} */ + const settings = preset.settings || {} + /** @type {Record|undefined>} */ const packages = {} let index = -1 @@ -34,7 +39,7 @@ export async function presets(base) { const plugin = plugins[index] /** @type {Plugin} */ let fn - /** @type {unknown} */ + /** @type {Array|undefined} */ let option if (typeof plugin === 'function') { @@ -45,32 +50,100 @@ export async function presets(base) { fn = plugin[0] // Fine: // type-coverage:ignore-next-line - option = plugin[1] + option = [{type: 'inlineCode', value: inspect(plugin[1])}] } else { throw new TypeError( 'Expected plugin, plugin tuple, not `' + plugin + '`' ) } - /** @type {string} */ - // @ts-expect-error: `displayName`s are fine. - const name = fn.displayName || fn.name + if (fn === remarkLint) continue - packages[ - name - .replace( - /[:-](\w)/g, - (/** @type {string} */ _, /** @type {string} */ $1) => - $1.toUpperCase() - ) - .replace( - /[A-Z]/g, - (/** @type {string} */ $0) => '-' + $0.toLowerCase() - ) - ] = option + const name = (fn.displayName || fn.name) + .replace( + /[:-](\w)/g, + (/** @type {string} */ _, /** @type {string} */ $1) => + $1.toUpperCase() + ) + .replace( + /[A-Z]/g, + (/** @type {string} */ $0) => '-' + $0.toLowerCase() + ) + + /** @type {Record} */ + const filtered = Object.assign( + {}, + ...Array.from( + new Set( + Object.keys(rule(path.join(base, name)).tests).flatMap( + (configuration) => { + /** @type {{settings: Record}} */ + const {settings} = JSON.parse(configuration) + return Object.keys(settings || {}) + } + ) + ), + (name) => + settings[name] === undefined ? {} : {[name]: settings[name]} + ) + ) + + packages[name] = + option || + (Object.entries(filtered).length > 0 + ? formatSettings(filtered) + : undefined) } - return {name, packages} + return {name, packages, settings: preset.settings} }) ) } + +/** + * @param {Record} settings + * @returns {Array} + */ +export function formatSettings(settings) { + const entries = Object.entries(settings) + if (entries.length === 1) { + const [[name, value]] = entries + return [ + { + type: 'link', + url: 'https://github.com/remarkjs/remark-lint#configure', + title: null, + children: [ + { + type: 'inlineCode', + value: `settings.${name}` + } + ] + }, + {type: 'text', value: ' is '}, + { + type: 'inlineCode', + value: inspect(value) + } + ] + } + + return [ + { + type: 'link', + url: 'https://github.com/remarkjs/remark-lint#configure', + title: null, + children: [ + { + type: 'inlineCode', + value: 'settings' + } + ] + }, + {type: 'text', value: ' includes '}, + { + type: 'inlineCode', + value: inspect(settings) + } + ] +} diff --git a/script/util/rule.js b/script/util/rule.js index 0f605ab2..d88a42f9 100755 --- a/script/util/rule.js +++ b/script/util/rule.js @@ -76,7 +76,7 @@ export function rule(filePath) { while (++index < examples.length) { const lines = examples[index].split('\n') - /** @type {{name: string, label?: 'input'|'output', config?: unknown, positionless?: boolean, gfm?: boolean}} */ + /** @type {{name: string, label?: 'input'|'output', settings?: Record, config?: unknown, positionless?: boolean, gfm?: boolean}} */ let info try { @@ -91,7 +91,10 @@ export function rule(filePath) { } const exampleValue = strip(lines.join('\n').replace(/^\r?\n/g, '')) - const configuration = JSON.stringify({config: info.config || true}) + const configuration = JSON.stringify({ + settings: info.settings, + config: info.config || true + }) const name = info.name const context = configuration in tests diff --git a/test.js b/test.js index a2501a3a..819b4cef 100644 --- a/test.js +++ b/test.js @@ -301,8 +301,8 @@ function assertRule(t, rule, info) { for (configuration in tests) { if (own.call(tests, configuration)) { const checks = tests[configuration] - /** @type {{config: unknown}} */ - const {config} = JSON.parse(configuration) + /** @type {{settings: Record, config: unknown}} */ + const {settings, config} = JSON.parse(configuration) t.test(configuration, (t) => { /** @type {string} */ @@ -314,7 +314,7 @@ function assertRule(t, rule, info) { const check = checks[name] t.test(name, (t) => { - assertFixture(t, rule, info, check, basename, config) + assertFixture(t, rule, info, check, basename, settings, config) }) } } @@ -331,15 +331,16 @@ function assertRule(t, rule, info) { * @param {Rule} info * @param {Check} fixture * @param {string} basename + * @param {Record} settings * @param {unknown} config */ /* eslint-disable-next-line max-params */ -function assertFixture(t, rule, info, fixture, basename, config) { +function assertFixture(t, rule, info, fixture, basename, settings, config) { const ruleId = info.ruleId const file = toVFile(basename) const expected = fixture.output const positionless = fixture.positionless - let proc = remark().use(rule, config) + let proc = remark().use(rule, config).use({settings}) if (fixture.gfm) proc.use(remarkGfm) @@ -393,6 +394,7 @@ function assertFixture(t, rule, info, fixture, basename, config) { proc = remark() .use(() => (tree) => removePosition(tree)) .use(rule, config) + .use({settings}) if (fixture.gfm) proc.use(remarkGfm) proc.processSync(file) diff --git a/tsconfig.json b/tsconfig.json index 3c7623ba..30c03bad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["script/**/*.js", "test.js"], + "include": ["script/**/*.js", "test.js", "types.d.ts"], "compilerOptions": { "target": "ES2020", "lib": ["ES2020"], diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 00000000..baa3f3a8 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,3 @@ +interface Function { + displayName: string +}