unified-lint-rule
Advanced tools
Comparing version
@@ -6,4 +6,16 @@ import type {Node} from 'unist' | ||
export interface RuleMeta { | ||
/** | ||
* Name of the lint rule | ||
*/ | ||
origin: string | ||
/** | ||
* Link to documentation | ||
*/ | ||
url?: string | undefined | ||
} | ||
export function lintRule<Tree extends Node = Node, Settings = unknown>( | ||
name: string, | ||
name: string | RuleMeta, | ||
rule: Rule<Tree, Settings> | ||
@@ -10,0 +22,0 @@ ): Plugin< |
/** | ||
* @param {string} id | ||
* @param {string|RuleMeta} meta | ||
* @param {Rule} rule | ||
*/ | ||
export function lintRule( | ||
id: string, | ||
meta: string | RuleMeta, | ||
rule: Rule | ||
@@ -22,2 +22,12 @@ ): { | ||
export type SeverityTuple = [Severity, ...unknown[]] | ||
export type RuleMeta = { | ||
/** | ||
* name of the lint rule | ||
*/ | ||
origin: string | ||
/** | ||
* link to documentation | ||
*/ | ||
url?: string | undefined | ||
} | ||
export type Rule = (tree: Node, file: VFile, options: unknown) => void |
@@ -9,2 +9,6 @@ /** | ||
* | ||
* @typedef RuleMeta | ||
* @property {string} origin name of the lint rule | ||
* @property {string} [url] link to documentation | ||
* | ||
* @callback Rule | ||
@@ -22,6 +26,8 @@ * @param {Node} tree | ||
/** | ||
* @param {string} id | ||
* @param {string|RuleMeta} meta | ||
* @param {Rule} rule | ||
*/ | ||
export function lintRule(id, rule) { | ||
export function lintRule(meta, rule) { | ||
const id = typeof meta === 'string' ? meta : meta.origin | ||
const url = typeof meta === 'string' ? undefined : meta.url | ||
const parts = id.split(':') | ||
@@ -62,3 +68,3 @@ // Possibly useful if externalised later. | ||
while (++index < messages.length) { | ||
Object.assign(messages[index], {ruleId, source, fatal}) | ||
Object.assign(messages[index], {ruleId, source, fatal, url}) | ||
} | ||
@@ -65,0 +71,0 @@ |
{ | ||
"name": "unified-lint-rule", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "unified plugin to make it a bit easier to create linting rules", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
8761
7.38%177
17.22%