Skip to content

Commit

Permalink
Give rules access to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Feb 20, 2022
1 parent 773e561 commit 8b57de8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/remark-lint-emphasis-marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Root, Options>} */
(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 `' +
Expand Down
7 changes: 6 additions & 1 deletion packages/remark-lint-strong-marker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Root, Options>} */
(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 `' +
Expand Down
1 change: 1 addition & 0 deletions packages/unified-lint-rule/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function lintRule<Tree extends Node = Node, Settings = unknown>(
>

export type Rule<Tree extends Node = Node, Settings = unknown> = (
this: Processor,
node: Tree,
file: VFile,
settings: Settings
Expand Down
4 changes: 2 additions & 2 deletions packages/unified-lint-rule/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function lintRule(meta, rule) {
return plugin

/** @type {import('unified').Plugin<[unknown]|Array<void>>} */
function plugin(raw) {
function plugin(raw, fileSet) {
const [severity, options] = coerce(ruleId, raw)

if (!severity) return
Expand Down Expand Up @@ -67,7 +67,7 @@ export function lintRule(meta, rule) {
}

next()
})(tree, file, options)
}).call(this, tree, file, options, fileSet)
}
}
}
Expand Down

0 comments on commit 8b57de8

Please sign in to comment.