mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Remove import of node:util and manually implement promisify (improves browser scenario), improve JSDoc typing.
This commit is contained in:
parent
3599f694ba
commit
789190962c
5 changed files with 62 additions and 25 deletions
|
|
@ -463,13 +463,13 @@ declare function markdownlintSync(options: Options | null): LintResults;
|
|||
* Read specified configuration file.
|
||||
*
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[] | ReadConfigCallback} parsers Parsing
|
||||
* @param {ConfigurationParser[] | ReadConfigCallback} [parsers] Parsing
|
||||
* function(s).
|
||||
* @param {Object} [fs] File system implementation.
|
||||
* @param {ReadConfigCallback} [callback] Callback (err, result) function.
|
||||
* @returns {void}
|
||||
*/
|
||||
declare function readConfig(file: string, parsers: ConfigurationParser[] | ReadConfigCallback, fs?: any, callback?: ReadConfigCallback): void;
|
||||
declare function readConfig(file: string, parsers?: ConfigurationParser[] | ReadConfigCallback, fs?: any, callback?: ReadConfigCallback): void;
|
||||
/**
|
||||
* Read specified configuration file synchronously.
|
||||
*
|
||||
|
|
@ -498,11 +498,11 @@ declare function markdownlintPromise(options: Options): Promise<LintResults>;
|
|||
*
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
|
||||
* @param {Object} [fs] File system implementation.
|
||||
* @param {ConfigurationParser[] | undefined} parsers Parsing function(s).
|
||||
* @param {Object} fs File system implementation.
|
||||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
declare function extendConfigPromise(config: Configuration, file: string, parsers?: ConfigurationParser[], fs?: any): Promise<Configuration>;
|
||||
declare function extendConfigPromise(config: Configuration, file: string, parsers: ConfigurationParser[] | undefined, fs: any): Promise<Configuration>;
|
||||
/**
|
||||
* Read specified configuration file.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { createRequire } from "node:module";
|
|||
const dynamicRequire = createRequire(import.meta.url);
|
||||
import * as os from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { initialize as cacheInitialize } from "./cache.mjs";
|
||||
import { version } from "./constants.mjs";
|
||||
import rules from "./rules.mjs";
|
||||
|
|
@ -959,8 +958,6 @@ function markdownlint(options, callback) {
|
|||
return lintInput(options, false, callback);
|
||||
}
|
||||
|
||||
const markdownlintPromisify = promisify && promisify(markdownlint);
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files.
|
||||
*
|
||||
|
|
@ -968,8 +965,15 @@ const markdownlintPromisify = promisify && promisify(markdownlint);
|
|||
* @returns {Promise<LintResults>} Results object.
|
||||
*/
|
||||
function markdownlintPromise(options) {
|
||||
// @ts-ignore
|
||||
return markdownlintPromisify(options);
|
||||
return new Promise((resolve, reject) => {
|
||||
markdownlint(options, (error, results) => {
|
||||
if (error || !results) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1054,7 +1058,7 @@ function resolveConfigExtendsSync(configFile, referenceId, fs) {
|
|||
*
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[]} parsers Parsing
|
||||
* @param {ConfigurationParser[] | undefined} parsers Parsing
|
||||
* function(s).
|
||||
* @param {Object} fs File system implementation.
|
||||
* @param {ReadConfigCallback} callback Callback (err, result) function.
|
||||
|
|
@ -1090,27 +1094,32 @@ function extendConfig(config, file, parsers, fs, callback) {
|
|||
return callback(null, config);
|
||||
}
|
||||
|
||||
const extendConfigPromisify = promisify && promisify(extendConfig);
|
||||
|
||||
/**
|
||||
* Extend specified configuration object.
|
||||
*
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
|
||||
* @param {Object} [fs] File system implementation.
|
||||
* @param {ConfigurationParser[] | undefined} parsers Parsing function(s).
|
||||
* @param {Object} fs File system implementation.
|
||||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
function extendConfigPromise(config, file, parsers, fs) {
|
||||
// @ts-ignore
|
||||
return extendConfigPromisify(config, file, parsers, fs);
|
||||
return new Promise((resolve, reject) => {
|
||||
extendConfig(config, file, parsers, fs, (error, results) => {
|
||||
if (error || !results) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Read specified configuration file.
|
||||
*
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[] | ReadConfigCallback} parsers Parsing
|
||||
* @param {ConfigurationParser[] | ReadConfigCallback} [parsers] Parsing
|
||||
* function(s).
|
||||
* @param {Object} [fs] File system implementation.
|
||||
* @param {ReadConfigCallback} [callback] Callback (err, result) function.
|
||||
|
|
@ -1151,8 +1160,6 @@ function readConfig(file, parsers, fs, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
const readConfigPromisify = promisify && promisify(readConfig);
|
||||
|
||||
/**
|
||||
* Read specified configuration file.
|
||||
*
|
||||
|
|
@ -1162,8 +1169,15 @@ const readConfigPromisify = promisify && promisify(readConfig);
|
|||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
function readConfigPromise(file, parsers, fs) {
|
||||
// @ts-ignore
|
||||
return readConfigPromisify(file, parsers, fs);
|
||||
return new Promise((resolve, reject) => {
|
||||
readConfig(file, parsers, fs, (error, results) => {
|
||||
if (error || !results) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue