From 8b57de8fab406242e3327a7c34cf9b168e5fe5f3 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 17 Feb 2022 13:30:40 -0700 Subject: [PATCH] Give rules access to settings --- packages/remark-lint-emphasis-marker/index.js | 7 ++++++- packages/remark-lint-strong-marker/index.js | 7 ++++++- packages/unified-lint-rule/index.d.ts | 1 + packages/unified-lint-rule/lib/index.js | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/remark-lint-emphasis-marker/index.js b/packages/remark-lint-emphasis-marker/index.js index 2a9671e0..064d2289 100644 --- a/packages/remark-lint-emphasis-marker/index.js +++ b/packages/remark-lint-emphasis-marker/index.js @@ -102,9 +102,14 @@ 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) { + const settings = this.data('settings') + option = (settings && settings.emphasis) || 'consistent' + } + if (option !== '*' && option !== '_' && option !== 'consistent') { file.fail( 'Incorrect emphasis marker `' + diff --git a/packages/remark-lint-strong-marker/index.js b/packages/remark-lint-strong-marker/index.js index 2dc5fe64..bfd3b575 100644 --- a/packages/remark-lint-strong-marker/index.js +++ b/packages/remark-lint-strong-marker/index.js @@ -91,9 +91,14 @@ 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) { + const settings = this.data('settings') + option = (settings && settings.strong) || 'consistent' + } + if (option !== '*' && option !== '_' && option !== 'consistent') { file.fail( 'Incorrect strong marker `' + diff --git a/packages/unified-lint-rule/index.d.ts b/packages/unified-lint-rule/index.d.ts index 543953bb..f60d5713 100644 --- a/packages/unified-lint-rule/index.d.ts +++ b/packages/unified-lint-rule/index.d.ts @@ -26,6 +26,7 @@ export function lintRule( > export type Rule = ( + this: Processor, node: Tree, file: VFile, settings: Settings diff --git a/packages/unified-lint-rule/lib/index.js b/packages/unified-lint-rule/lib/index.js index ac57a60d..5f028c72 100644 --- a/packages/unified-lint-rule/lib/index.js +++ b/packages/unified-lint-rule/lib/index.js @@ -39,7 +39,7 @@ export function lintRule(meta, rule) { return plugin /** @type {import('unified').Plugin<[unknown]|Array>} */ - function plugin(raw) { + function plugin(raw, fileSet) { const [severity, options] = coerce(ruleId, raw) if (!severity) return @@ -67,7 +67,7 @@ export function lintRule(meta, rule) { } next() - })(tree, file, options) + }).call(this, tree, file, options, fileSet) } } }