mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update to use named exports via / /async /promise /sync, simplify references via self-referencing, refine examples.
This commit is contained in:
parent
e41f034bef
commit
8da43dd246
96 changed files with 635 additions and 548 deletions
|
@ -954,19 +954,19 @@ function lintInput(options, synchronous, callback) {
|
|||
* @param {LintCallback} callback Callback (err, result) function.
|
||||
* @returns {void}
|
||||
*/
|
||||
function markdownlint(options, callback) {
|
||||
export function lintAsync(options, callback) {
|
||||
return lintInput(options, false, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files.
|
||||
*
|
||||
* @param {Options} options Configuration options.
|
||||
* @param {Options | null} options Configuration options.
|
||||
* @returns {Promise<LintResults>} Results object.
|
||||
*/
|
||||
function markdownlintPromise(options) {
|
||||
export function lintPromise(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
markdownlint(options, (error, results) => {
|
||||
lintAsync(options, (error, results) => {
|
||||
if (error || !results) {
|
||||
reject(error);
|
||||
} else {
|
||||
|
@ -977,12 +977,12 @@ function markdownlintPromise(options) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files synchronously.
|
||||
* Lint specified Markdown files.
|
||||
*
|
||||
* @param {Options | null} options Configuration options.
|
||||
* @returns {LintResults} Results object.
|
||||
*/
|
||||
function markdownlintSync(options) {
|
||||
export function lintSync(options) {
|
||||
let results = null;
|
||||
lintInput(options, true, function callback(error, res) {
|
||||
if (error) {
|
||||
|
@ -1072,7 +1072,7 @@ function extendConfig(config, file, parsers, fs, callback) {
|
|||
helpers.expandTildePath(configExtends, os),
|
||||
fs,
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
(_, resolvedExtends) => readConfig(
|
||||
(_, resolvedExtends) => readConfigAsync(
|
||||
// @ts-ignore
|
||||
resolvedExtends,
|
||||
parsers,
|
||||
|
@ -1103,7 +1103,7 @@ function extendConfig(config, file, parsers, fs, callback) {
|
|||
* @param {Object} fs File system implementation.
|
||||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
function extendConfigPromise(config, file, parsers, fs) {
|
||||
export function extendConfigPromise(config, file, parsers, fs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
extendConfig(config, file, parsers, fs, (error, results) => {
|
||||
if (error || !results) {
|
||||
|
@ -1125,7 +1125,7 @@ function extendConfigPromise(config, file, parsers, fs) {
|
|||
* @param {ReadConfigCallback} [callback] Callback (err, result) function.
|
||||
* @returns {void}
|
||||
*/
|
||||
function readConfig(file, parsers, fs, callback) {
|
||||
export function readConfigAsync(file, parsers, fs, callback) {
|
||||
if (!callback) {
|
||||
if (fs) {
|
||||
callback = fs;
|
||||
|
@ -1168,9 +1168,9 @@ function readConfig(file, parsers, fs, callback) {
|
|||
* @param {Object} [fs] File system implementation.
|
||||
* @returns {Promise<Configuration>} Configuration object.
|
||||
*/
|
||||
function readConfigPromise(file, parsers, fs) {
|
||||
export function readConfigPromise(file, parsers, fs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
readConfig(file, parsers, fs, (error, results) => {
|
||||
readConfigAsync(file, parsers, fs, (error, results) => {
|
||||
if (error || !results) {
|
||||
reject(error);
|
||||
} else {
|
||||
|
@ -1181,15 +1181,14 @@ function readConfigPromise(file, parsers, fs) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Read specified configuration file synchronously.
|
||||
* Read specified configuration file.
|
||||
*
|
||||
* @param {string} file Configuration file name.
|
||||
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
|
||||
* @param {Object} [fs] File system implementation.
|
||||
* @returns {Configuration} Configuration object.
|
||||
* @throws An Error if processing fails.
|
||||
*/
|
||||
function readConfigSync(file, parsers, fs) {
|
||||
export function readConfigSync(file, parsers, fs) {
|
||||
if (!fs) {
|
||||
fs = nodeFs;
|
||||
}
|
||||
|
@ -1242,7 +1241,7 @@ function normalizeFixInfo(fixInfo, lineNumber = 0) {
|
|||
* @param {string} [lineEnding] Line ending to use.
|
||||
* @returns {string | null} Fixed content or null if deleted.
|
||||
*/
|
||||
function applyFix(line, fixInfo, lineEnding = "\n") {
|
||||
export function applyFix(line, fixInfo, lineEnding = "\n") {
|
||||
const { editColumn, deleteCount, insertText } = normalizeFixInfo(fixInfo);
|
||||
const editIndex = editColumn - 1;
|
||||
return (deleteCount === -1) ?
|
||||
|
@ -1257,7 +1256,7 @@ function applyFix(line, fixInfo, lineEnding = "\n") {
|
|||
* @param {RuleOnErrorInfo[]} errors RuleOnErrorInfo instances.
|
||||
* @returns {string} Fixed content.
|
||||
*/
|
||||
function applyFixes(input, errors) {
|
||||
export function applyFixes(input, errors) {
|
||||
const lineEnding = helpers.getPreferredLineEnding(input, os);
|
||||
const lines = input.split(helpers.newLineRe);
|
||||
// Normalize fixInfo objects
|
||||
|
@ -1335,24 +1334,10 @@ function applyFixes(input, errors) {
|
|||
*
|
||||
* @returns {string} SemVer string.
|
||||
*/
|
||||
function getVersion() {
|
||||
export function getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
// Export a/synchronous/Promise APIs
|
||||
markdownlint.sync = markdownlintSync;
|
||||
markdownlint.readConfig = readConfig;
|
||||
markdownlint.readConfigSync = readConfigSync;
|
||||
markdownlint.getVersion = getVersion;
|
||||
markdownlint.promises = {
|
||||
"markdownlint": markdownlintPromise,
|
||||
"extendConfig": extendConfigPromise,
|
||||
"readConfig": readConfigPromise
|
||||
};
|
||||
markdownlint.applyFix = applyFix;
|
||||
markdownlint.applyFixes = applyFixes;
|
||||
export default markdownlint;
|
||||
|
||||
// Type declarations
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue