mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Address new TypeScript warnings from VS Code.
This commit is contained in:
parent
3d6afccae1
commit
312f4b8c6d
2 changed files with 40 additions and 25 deletions
|
|
@ -1261,7 +1261,7 @@ const dynamicRequire = (typeof require === "undefined") ? __webpack_require__(".
|
||||||
*
|
*
|
||||||
* @param {Rule[]} ruleList List of rules.
|
* @param {Rule[]} ruleList List of rules.
|
||||||
* @param {boolean} synchronous Whether to execute synchronously.
|
* @param {boolean} synchronous Whether to execute synchronously.
|
||||||
* @returns {string} Error message if validation fails.
|
* @returns {Error | null} Error message if validation fails.
|
||||||
*/
|
*/
|
||||||
function validateRuleList(ruleList, synchronous) {
|
function validateRuleList(ruleList, synchronous) {
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
@ -1328,7 +1328,6 @@ function validateRuleList(ruleList, synchronous) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -1577,7 +1576,7 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||||
*
|
*
|
||||||
* @param {string} name Name of the configuration file.
|
* @param {string} name Name of the configuration file.
|
||||||
* @param {string} content Configuration content.
|
* @param {string} content Configuration content.
|
||||||
* @param {ConfigurationParser[]} parsers Parsing function(s).
|
* @param {ConfigurationParser[] | null} [parsers] Parsing function(s).
|
||||||
* @returns {Object} Configuration object and error message.
|
* @returns {Object} Configuration object and error message.
|
||||||
*/
|
*/
|
||||||
function parseConfiguration(name, content, parsers) {
|
function parseConfiguration(name, content, parsers) {
|
||||||
|
|
@ -1613,7 +1612,7 @@ function parseConfiguration(name, content, parsers) {
|
||||||
* @param {string[]} frontMatterLines List of front matter lines.
|
* @param {string[]} frontMatterLines List of front matter lines.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
||||||
* names.
|
* names.
|
||||||
* @returns {Object} Effective configuration and enabled rules per line number.
|
* @returns {Object} Effective configuration and enabled rules per line number.
|
||||||
|
|
@ -1726,7 +1725,7 @@ function getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlin
|
||||||
* @param {string} content Markdown content.
|
* @param {string} content Markdown content.
|
||||||
* @param {Object} md Instance of markdown-it.
|
* @param {Object} md Instance of markdown-it.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {RegExp} frontMatter Regular expression for front matter.
|
* @param {RegExp} frontMatter Regular expression for front matter.
|
||||||
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
|
|
@ -1968,7 +1967,7 @@ function lintContent(ruleList, name, content, md, config, configParsers, frontMa
|
||||||
* @param {string} file Path of file to lint.
|
* @param {string} file Path of file to lint.
|
||||||
* @param {Object} md Instance of markdown-it.
|
* @param {Object} md Instance of markdown-it.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {RegExp} frontMatter Regular expression for front matter.
|
* @param {RegExp} frontMatter Regular expression for front matter.
|
||||||
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
|
|
@ -2010,7 +2009,8 @@ function lintInput(options, synchronous, callback) {
|
||||||
const ruleList = rules.concat(options.customRules || []);
|
const ruleList = rules.concat(options.customRules || []);
|
||||||
const ruleErr = validateRuleList(ruleList, synchronous);
|
const ruleErr = validateRuleList(ruleList, synchronous);
|
||||||
if (ruleErr) {
|
if (ruleErr) {
|
||||||
return callback(ruleErr);
|
callback(ruleErr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
let files = [];
|
let files = [];
|
||||||
if (Array.isArray(options.files)) {
|
if (Array.isArray(options.files)) {
|
||||||
|
|
@ -2064,10 +2064,9 @@ function lintInput(options, synchronous, callback) {
|
||||||
currentItem = files.shift();
|
currentItem = files.shift();
|
||||||
lintFile(ruleList, currentItem, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, fs, synchronous, lintWorkerCallback);
|
lintFile(ruleList, currentItem, md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, fs, synchronous, lintWorkerCallback);
|
||||||
}
|
}
|
||||||
else if (stringsKeys.length > 0) {
|
else if ((currentItem = stringsKeys.shift())) {
|
||||||
// Lint next string
|
// Lint next string
|
||||||
concurrency++;
|
concurrency++;
|
||||||
currentItem = stringsKeys.shift();
|
|
||||||
lintContent(ruleList, currentItem, strings[currentItem] || "", md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, lintWorkerCallback);
|
lintContent(ruleList, currentItem, strings[currentItem] || "", md, config, configParsers, frontMatter, handleRuleFailures, noInlineConfig, resultVersion, lintWorkerCallback);
|
||||||
}
|
}
|
||||||
else if (concurrency === 0) {
|
else if (concurrency === 0) {
|
||||||
|
|
@ -2095,7 +2094,6 @@ function lintInput(options, synchronous, callback) {
|
||||||
lintWorker();
|
lintWorker();
|
||||||
lintWorker();
|
lintWorker();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Lint specified Markdown files.
|
* Lint specified Markdown files.
|
||||||
|
|
@ -2115,6 +2113,7 @@ const markdownlintPromisify = promisify && promisify(markdownlint);
|
||||||
* @returns {Promise<LintResults>} Results object.
|
* @returns {Promise<LintResults>} Results object.
|
||||||
*/
|
*/
|
||||||
function markdownlintPromise(options) {
|
function markdownlintPromise(options) {
|
||||||
|
// @ts-ignore
|
||||||
return markdownlintPromisify(options);
|
return markdownlintPromisify(options);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -2124,13 +2123,14 @@ function markdownlintPromise(options) {
|
||||||
* @returns {LintResults} Results object.
|
* @returns {LintResults} Results object.
|
||||||
*/
|
*/
|
||||||
function markdownlintSync(options) {
|
function markdownlintSync(options) {
|
||||||
let results = null;
|
let results = {};
|
||||||
lintInput(options, true, function callback(error, res) {
|
lintInput(options, true, function callback(error, res) {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
results = res;
|
results = res;
|
||||||
});
|
});
|
||||||
|
// @ts-ignore
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
@ -2140,7 +2140,7 @@ function markdownlintSync(options) {
|
||||||
* @param {string} configFile Configuration file name.
|
* @param {string} configFile Configuration file name.
|
||||||
* @param {string} referenceId Referenced identifier to resolve.
|
* @param {string} referenceId Referenced identifier to resolve.
|
||||||
* @param {Object} fs File system implementation.
|
* @param {Object} fs File system implementation.
|
||||||
* @param {ResolveConfigExtendsCallback} [callback] Callback (err, result)
|
* @param {ResolveConfigExtendsCallback} callback Callback (err, result)
|
||||||
* function.
|
* function.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
|
@ -2206,6 +2206,7 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
else {
|
else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
callback = parsers;
|
callback = parsers;
|
||||||
|
// @ts-ignore
|
||||||
parsers = null;
|
parsers = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2217,25 +2218,32 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
file = helpers.expandTildePath(file, os);
|
file = helpers.expandTildePath(file, os);
|
||||||
fs.readFile(file, "utf8", (err, content) => {
|
fs.readFile(file, "utf8", (err, content) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
// Try to parse file
|
// Try to parse file
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { config, message } = parseConfiguration(file, content, parsers);
|
const { config, message } = parseConfiguration(file, content, parsers);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(new Error(message));
|
return callback(new Error(message));
|
||||||
}
|
}
|
||||||
// Extend configuration
|
// Extend configuration
|
||||||
const configExtends = config.extends;
|
const configExtends = config.extends;
|
||||||
if (configExtends) {
|
if (configExtends) {
|
||||||
delete config.extends;
|
delete config.extends;
|
||||||
return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, (_, resolvedExtends) => readConfig(resolvedExtends, parsers, fs, (errr, extendsConfig) => {
|
return resolveConfigExtends(file, helpers.expandTildePath(configExtends, os), fs, (_, resolvedExtends) => readConfig(
|
||||||
|
// @ts-ignore
|
||||||
|
resolvedExtends, parsers, fs, (errr, extendsConfig) => {
|
||||||
if (errr) {
|
if (errr) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(errr);
|
return callback(errr);
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
return callback(null, Object.assign(Object.assign({}, extendsConfig), config));
|
return callback(null, Object.assign(Object.assign({}, extendsConfig), config));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
return callback(null, config);
|
return callback(null, config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const dynamicRequire = (typeof __non_webpack_require__ === "undefined") ? requir
|
||||||
*
|
*
|
||||||
* @param {Rule[]} ruleList List of rules.
|
* @param {Rule[]} ruleList List of rules.
|
||||||
* @param {boolean} synchronous Whether to execute synchronously.
|
* @param {boolean} synchronous Whether to execute synchronously.
|
||||||
* @returns {string} Error message if validation fails.
|
* @returns {Error | null} Error message if validation fails.
|
||||||
*/
|
*/
|
||||||
function validateRuleList(ruleList, synchronous) {
|
function validateRuleList(ruleList, synchronous) {
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
@ -94,7 +94,6 @@ function validateRuleList(ruleList, synchronous) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,7 +352,7 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
|
||||||
*
|
*
|
||||||
* @param {string} name Name of the configuration file.
|
* @param {string} name Name of the configuration file.
|
||||||
* @param {string} content Configuration content.
|
* @param {string} content Configuration content.
|
||||||
* @param {ConfigurationParser[]} parsers Parsing function(s).
|
* @param {ConfigurationParser[] | null} [parsers] Parsing function(s).
|
||||||
* @returns {Object} Configuration object and error message.
|
* @returns {Object} Configuration object and error message.
|
||||||
*/
|
*/
|
||||||
function parseConfiguration(name, content, parsers) {
|
function parseConfiguration(name, content, parsers) {
|
||||||
|
|
@ -389,7 +388,7 @@ function parseConfiguration(name, content, parsers) {
|
||||||
* @param {string[]} frontMatterLines List of front matter lines.
|
* @param {string[]} frontMatterLines List of front matter lines.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
||||||
* names.
|
* names.
|
||||||
* @returns {Object} Effective configuration and enabled rules per line number.
|
* @returns {Object} Effective configuration and enabled rules per line number.
|
||||||
|
|
@ -519,7 +518,7 @@ function getEnabledRulesPerLineNumber(
|
||||||
* @param {string} content Markdown content.
|
* @param {string} content Markdown content.
|
||||||
* @param {Object} md Instance of markdown-it.
|
* @param {Object} md Instance of markdown-it.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {RegExp} frontMatter Regular expression for front matter.
|
* @param {RegExp} frontMatter Regular expression for front matter.
|
||||||
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
|
|
@ -790,7 +789,7 @@ function lintContent(
|
||||||
* @param {string} file Path of file to lint.
|
* @param {string} file Path of file to lint.
|
||||||
* @param {Object} md Instance of markdown-it.
|
* @param {Object} md Instance of markdown-it.
|
||||||
* @param {Configuration} config Configuration object.
|
* @param {Configuration} config Configuration object.
|
||||||
* @param {ConfigurationParser[]} configParsers Configuration parsers.
|
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||||
* @param {RegExp} frontMatter Regular expression for front matter.
|
* @param {RegExp} frontMatter Regular expression for front matter.
|
||||||
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
* @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
|
||||||
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
* @param {boolean} noInlineConfig Whether to allow inline configuration.
|
||||||
|
|
@ -856,7 +855,8 @@ function lintInput(options, synchronous, callback) {
|
||||||
const ruleList = rules.concat(options.customRules || []);
|
const ruleList = rules.concat(options.customRules || []);
|
||||||
const ruleErr = validateRuleList(ruleList, synchronous);
|
const ruleErr = validateRuleList(ruleList, synchronous);
|
||||||
if (ruleErr) {
|
if (ruleErr) {
|
||||||
return callback(ruleErr);
|
callback(ruleErr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
let files = [];
|
let files = [];
|
||||||
if (Array.isArray(options.files)) {
|
if (Array.isArray(options.files)) {
|
||||||
|
|
@ -920,10 +920,9 @@ function lintInput(options, synchronous, callback) {
|
||||||
synchronous,
|
synchronous,
|
||||||
lintWorkerCallback
|
lintWorkerCallback
|
||||||
);
|
);
|
||||||
} else if (stringsKeys.length > 0) {
|
} else if ((currentItem = stringsKeys.shift())) {
|
||||||
// Lint next string
|
// Lint next string
|
||||||
concurrency++;
|
concurrency++;
|
||||||
currentItem = stringsKeys.shift();
|
|
||||||
lintContent(
|
lintContent(
|
||||||
ruleList,
|
ruleList,
|
||||||
currentItem,
|
currentItem,
|
||||||
|
|
@ -961,7 +960,6 @@ function lintInput(options, synchronous, callback) {
|
||||||
lintWorker();
|
lintWorker();
|
||||||
lintWorker();
|
lintWorker();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -984,6 +982,7 @@ const markdownlintPromisify = promisify && promisify(markdownlint);
|
||||||
* @returns {Promise<LintResults>} Results object.
|
* @returns {Promise<LintResults>} Results object.
|
||||||
*/
|
*/
|
||||||
function markdownlintPromise(options) {
|
function markdownlintPromise(options) {
|
||||||
|
// @ts-ignore
|
||||||
return markdownlintPromisify(options);
|
return markdownlintPromisify(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -994,13 +993,14 @@ function markdownlintPromise(options) {
|
||||||
* @returns {LintResults} Results object.
|
* @returns {LintResults} Results object.
|
||||||
*/
|
*/
|
||||||
function markdownlintSync(options) {
|
function markdownlintSync(options) {
|
||||||
let results = null;
|
let results = {};
|
||||||
lintInput(options, true, function callback(error, res) {
|
lintInput(options, true, function callback(error, res) {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
results = res;
|
results = res;
|
||||||
});
|
});
|
||||||
|
// @ts-ignore
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1011,7 +1011,7 @@ function markdownlintSync(options) {
|
||||||
* @param {string} configFile Configuration file name.
|
* @param {string} configFile Configuration file name.
|
||||||
* @param {string} referenceId Referenced identifier to resolve.
|
* @param {string} referenceId Referenced identifier to resolve.
|
||||||
* @param {Object} fs File system implementation.
|
* @param {Object} fs File system implementation.
|
||||||
* @param {ResolveConfigExtendsCallback} [callback] Callback (err, result)
|
* @param {ResolveConfigExtendsCallback} callback Callback (err, result)
|
||||||
* function.
|
* function.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
|
@ -1081,6 +1081,7 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
callback = parsers;
|
callback = parsers;
|
||||||
|
// @ts-ignore
|
||||||
parsers = null;
|
parsers = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1092,12 +1093,14 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
file = helpers.expandTildePath(file, os);
|
file = helpers.expandTildePath(file, os);
|
||||||
fs.readFile(file, "utf8", (err, content) => {
|
fs.readFile(file, "utf8", (err, content) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
// Try to parse file
|
// Try to parse file
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { config, message } = parseConfiguration(file, content, parsers);
|
const { config, message } = parseConfiguration(file, content, parsers);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(new Error(message));
|
return callback(new Error(message));
|
||||||
}
|
}
|
||||||
// Extend configuration
|
// Extend configuration
|
||||||
|
|
@ -1109,13 +1112,16 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
helpers.expandTildePath(configExtends, os),
|
helpers.expandTildePath(configExtends, os),
|
||||||
fs,
|
fs,
|
||||||
(_, resolvedExtends) => readConfig(
|
(_, resolvedExtends) => readConfig(
|
||||||
|
// @ts-ignore
|
||||||
resolvedExtends,
|
resolvedExtends,
|
||||||
parsers,
|
parsers,
|
||||||
fs,
|
fs,
|
||||||
(errr, extendsConfig) => {
|
(errr, extendsConfig) => {
|
||||||
if (errr) {
|
if (errr) {
|
||||||
|
// @ts-ignore
|
||||||
return callback(errr);
|
return callback(errr);
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
...extendsConfig,
|
...extendsConfig,
|
||||||
...config
|
...config
|
||||||
|
|
@ -1124,6 +1130,7 @@ function readConfig(file, parsers, fs, callback) {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
return callback(null, config);
|
return callback(null, config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue