mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-08 00:48:50 +01:00
Add optional "information" property to custom rules to provide a link to more information.
This commit is contained in:
parent
b77dd5ccd3
commit
ff86e1d7f1
14 changed files with 201 additions and 6 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { URL } = require("url");
|
||||
const md = require("markdown-it")({ "html": true });
|
||||
const rules = require("./rules");
|
||||
const shared = require("./shared");
|
||||
|
|
@ -41,6 +42,11 @@ function validateRuleList(ruleList) {
|
|||
result = newError(property);
|
||||
}
|
||||
});
|
||||
if (!result && rule.information) {
|
||||
if (Object.getPrototypeOf(rule.information) !== URL.prototype) {
|
||||
result = newError("information");
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
rule.names.forEach(function forName(name) {
|
||||
const nameUpper = name.toUpperCase();
|
||||
|
|
@ -373,6 +379,8 @@ function lintContent(
|
|||
errorObject.ruleNames = rule.names;
|
||||
}
|
||||
errorObject.ruleDescription = rule.description;
|
||||
errorObject.ruleInformation =
|
||||
rule.information ? rule.information.href : null;
|
||||
errorObject.errorDetail = error.detail;
|
||||
errorObject.errorContext = error.context;
|
||||
errorObject.errorRange = error.range;
|
||||
|
|
|
|||
13
lib/rules.js
13
lib/rules.js
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
module.exports = [
|
||||
const { URL } = require("url");
|
||||
const packageJson = require("../package.json");
|
||||
const homepage = packageJson.homepage;
|
||||
const version = packageJson.version;
|
||||
|
||||
const rules = [
|
||||
require("./md001"),
|
||||
require("./md002"),
|
||||
require("./md003"),
|
||||
|
|
@ -45,3 +50,9 @@ module.exports = [
|
|||
require("./md044"),
|
||||
require("./md045")
|
||||
];
|
||||
rules.forEach((rule) => {
|
||||
const name = rule.names[0].toLowerCase();
|
||||
rule.information =
|
||||
new URL(`${homepage}/blob/v${version}/doc/Rules.md#${name}`);
|
||||
});
|
||||
module.exports = rules;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue