mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-18 06:50:12 +01:00
Add Promise-based APIs for markdownlint and readConfig, update declaration file.
This commit is contained in:
parent
1f6a2cdc96
commit
e9d63a6284
5 changed files with 201 additions and 45 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const markdownIt = require("markdown-it");
|
||||
const rules = require("./rules");
|
||||
const helpers = require("../helpers");
|
||||
|
|
@ -11,7 +12,6 @@ const cache = require("./cache");
|
|||
|
||||
const deprecatedRuleNames = [ "MD002", "MD006" ];
|
||||
|
||||
|
||||
/**
|
||||
* Validate the list of rules for structure and reuse.
|
||||
*
|
||||
|
|
@ -834,6 +834,18 @@ function markdownlint(options, callback) {
|
|||
return lintInput(options, false, callback);
|
||||
}
|
||||
|
||||
const markdownlintPromisify = util.promisify(markdownlint);
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files.
|
||||
*
|
||||
* @param {Options} options Configuration options.
|
||||
* @returns {Promise<LintResults>} Results object.
|
||||
*/
|
||||
function markdownlintPromise(options) {
|
||||
return markdownlintPromisify(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files synchronously.
|
||||
*
|
||||
|
|
@ -928,6 +940,20 @@ function readConfig(file, parsers, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
const readConfigPromisify = util.promisify(readConfig);
|
||||
|
||||
/**
|
||||
* Read specified configuration file.
|
||||
*
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
|
||||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
function readConfigPromise(file, parsers) {
|
||||
// @ts-ignore
|
||||
return readConfigPromisify(file, parsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read specified configuration file synchronously.
|
||||
*
|
||||
|
|
@ -959,10 +985,14 @@ function readConfigSync(file, parsers) {
|
|||
return config;
|
||||
}
|
||||
|
||||
// Export a/synchronous APIs
|
||||
// Export a/synchronous/Promise APIs
|
||||
markdownlint.sync = markdownlintSync;
|
||||
markdownlint.readConfig = readConfig;
|
||||
markdownlint.readConfigSync = readConfigSync;
|
||||
markdownlint.promises = {
|
||||
"markdownlint": markdownlintPromise,
|
||||
"readConfig": readConfigPromise
|
||||
};
|
||||
module.exports = markdownlint;
|
||||
|
||||
// Type declarations
|
||||
|
|
@ -1081,11 +1111,8 @@ module.exports = markdownlint;
|
|||
* Lint results (for resultVersion 3).
|
||||
*
|
||||
* @typedef {Object.<string, LintError[]>} LintResults
|
||||
* @property {ToStringCallback} toString String representation.
|
||||
*/
|
||||
// The following should be part of the LintResults typedef, but that causes
|
||||
// TypeScript to "forget" about the string map.
|
||||
// * @property {ToStringCallback} toString String representation.
|
||||
// https://github.com/microsoft/TypeScript/issues/34911
|
||||
|
||||
/**
|
||||
* Lint error.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue