mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add markdownlint "version" property to custom rule "params" object in case it is ever necessary for a rule to specialize its behavior.
This commit is contained in:
parent
ee50519e00
commit
d3819c4e75
6 changed files with 39 additions and 5 deletions
|
@ -1657,7 +1657,7 @@ module.exports = {
|
|||
const path = __webpack_require__(/*! node:path */ "?9a52");
|
||||
const { promisify } = __webpack_require__(/*! node:util */ "?39e5");
|
||||
const micromark = __webpack_require__(/*! ../helpers/micromark-parse.cjs */ "../helpers/micromark-parse.cjs");
|
||||
// const { deprecatedRuleNames } = require("./constants");
|
||||
const { version } = __webpack_require__(/*! ./constants */ "../lib/constants.js");
|
||||
const rules = __webpack_require__(/*! ./rules */ "../lib/rules.js");
|
||||
const helpers = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const cache = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||
|
@ -2177,6 +2177,7 @@ function lintContent(
|
|||
const parsersNone = Object.freeze({});
|
||||
const paramsBase = {
|
||||
name,
|
||||
version,
|
||||
"lines": Object.freeze(lines),
|
||||
"frontMatterLines": Object.freeze(frontMatterLines)
|
||||
};
|
||||
|
@ -2861,7 +2862,7 @@ function readConfigSync(file, parsers, fs) {
|
|||
* @returns {string} SemVer string.
|
||||
*/
|
||||
function getVersion() {
|
||||
return (__webpack_require__(/*! ./constants */ "../lib/constants.js").version);
|
||||
return version;
|
||||
}
|
||||
|
||||
// Export a/synchronous/Promise APIs
|
||||
|
@ -2898,6 +2899,7 @@ module.exports = markdownlint;
|
|||
* @property {readonly string[]} lines File/string lines.
|
||||
* @property {readonly string[]} frontMatterLines Front matter lines.
|
||||
* @property {RuleConfiguration} config Rule configuration.
|
||||
* @property {string} version Version of the markdownlint library.
|
||||
*/
|
||||
|
||||
/* eslint-enable jsdoc/valid-types */
|
||||
|
|
|
@ -85,6 +85,7 @@ A rule is implemented as an `Object`:
|
|||
front matter (not present in `lines`).
|
||||
- `config` is an `Object` corresponding to the rule's entry in
|
||||
`options.config` (if present).
|
||||
- `version` is a `String` that corresponds to the version of `markdownlint`
|
||||
- `onError` is a function that takes a single `Object` parameter with one
|
||||
required and four optional properties:
|
||||
- `lineNumber` is a required `Number` specifying the 1-based line number of
|
||||
|
|
|
@ -136,7 +136,8 @@ const testRule: markdownlint.Rule = {
|
|||
"frontMatterLines": [
|
||||
"three"
|
||||
],
|
||||
"config": options.config
|
||||
"config": options.config,
|
||||
"version": "1.2.3"
|
||||
};
|
||||
assert(ruleParams);
|
||||
let ruleOnErrorInfo: markdownlint.RuleOnErrorInfo;
|
||||
|
|
4
lib/markdownlint.d.ts
vendored
4
lib/markdownlint.d.ts
vendored
|
@ -77,6 +77,10 @@ type RuleParams = {
|
|||
* Rule configuration.
|
||||
*/
|
||||
config: RuleConfiguration;
|
||||
/**
|
||||
* Version of the markdownlint library.
|
||||
*/
|
||||
version: string;
|
||||
};
|
||||
/**
|
||||
* Markdown parser data.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
const path = require("node:path");
|
||||
const { promisify } = require("node:util");
|
||||
const micromark = require("../helpers/micromark-parse.cjs");
|
||||
// const { deprecatedRuleNames } = require("./constants");
|
||||
const { version } = require("./constants");
|
||||
const rules = require("./rules");
|
||||
const helpers = require("../helpers");
|
||||
const cache = require("./cache");
|
||||
|
@ -525,6 +525,7 @@ function lintContent(
|
|||
const parsersNone = Object.freeze({});
|
||||
const paramsBase = {
|
||||
name,
|
||||
version,
|
||||
"lines": Object.freeze(lines),
|
||||
"frontMatterLines": Object.freeze(frontMatterLines)
|
||||
};
|
||||
|
@ -1209,7 +1210,7 @@ function readConfigSync(file, parsers, fs) {
|
|||
* @returns {string} SemVer string.
|
||||
*/
|
||||
function getVersion() {
|
||||
return require("./constants").version;
|
||||
return version;
|
||||
}
|
||||
|
||||
// Export a/synchronous/Promise APIs
|
||||
|
@ -1246,6 +1247,7 @@ module.exports = markdownlint;
|
|||
* @property {readonly string[]} lines File/string lines.
|
||||
* @property {readonly string[]} frontMatterLines Front matter lines.
|
||||
* @property {RuleConfiguration} config Rule configuration.
|
||||
* @property {string} version Version of the markdownlint library.
|
||||
*/
|
||||
|
||||
/* eslint-enable jsdoc/valid-types */
|
||||
|
|
|
@ -1338,6 +1338,30 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
|
|||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
});
|
||||
|
||||
test("customRulesVersion", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
"description": "description",
|
||||
"tags": [ "tag" ],
|
||||
"parser": "none",
|
||||
"function": function stringName(params) {
|
||||
t.is(params.version, version, "Incorrect version");
|
||||
}
|
||||
}
|
||||
],
|
||||
"files": "doc/CustomRules.md"
|
||||
};
|
||||
markdownlint(options, function callback(err) {
|
||||
t.falsy(err);
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
test("customRulesFileName", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue