Update to use named exports via / /async /promise /sync, simplify references via self-referencing, refine examples.

This commit is contained in:
David Anson 2024-12-03 19:58:28 -08:00
parent e41f034bef
commit 8da43dd246
96 changed files with 635 additions and 548 deletions

View file

@ -312,42 +312,41 @@ alternate formats.
### Linting
Standard asynchronous API:
Asynchronous API via `import { lint } from "markdownlint/async"`:
```javascript
/**
* Lint specified Markdown files.
*
* @param {Options} options Configuration options.
* @param {Options | null} options Configuration options.
* @param {LintCallback} callback Callback (err, result) function.
* @returns {void}
*/
function markdownlint(options, callback) { ... }
function lint(options, callback) { ... }
```
Synchronous API (for build scripts, etc.):
```javascript
/**
* Lint specified Markdown files synchronously.
*
* @param {Options} options Configuration options.
* @returns {LintResults} Results object.
*/
function markdownlint.sync(options) { ... }
```
Promise API (in the `promises` namespace like Node.js's
[`fs` Promises API](https://nodejs.org/api/fs.html#fs_fs_promises_api)):
Synchronous API via `import { lint } from "markdownlint/sync"`:
```javascript
/**
* Lint specified Markdown files.
*
* @param {Options} options Configuration options.
* @param {Options | null} options Configuration options.
* @returns {LintResults} Results object.
*/
function lint(options) { ... }
```
Promise API via `import { lint } from "markdownlint/promise"`:
```javascript
/**
* Lint specified Markdown files.
*
* @param {Options | null} options Configuration options.
* @returns {Promise<LintResults>} Results object.
*/
function markdownlint(options) { ... }
function lint(options) { ... }
```
#### options
@ -669,7 +668,7 @@ By default, configuration files are parsed as JSON (and named
`.markdownlint.json`). Custom parsers can be provided to handle other formats
like JSONC, YAML, and TOML.
Asynchronous API:
Asynchronous API via `import { readConfig } from "markdownlint/async"`:
```javascript
/**
@ -684,22 +683,21 @@ Asynchronous API:
function readConfig(file, parsers, fs, callback) { ... }
```
Synchronous API:
Synchronous API via `import { readConfig } from "markdownlint/sync"`:
```javascript
/**
* 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.
*/
function readConfigSync(file, parsers, fs) { ... }
function readConfig(file, parsers, fs) { ... }
```
Promise API (in the `promises` namespace like Node.js's
[`fs` Promises API](https://nodejs.org/api/fs.html#fs_promises_api)):
Promise API via `import { readConfig } from "markdownlint/promise"`:
```javascript
/**
@ -772,7 +770,8 @@ Configuration object.
Rules that can be fixed automatically include a `fixInfo` property which is
outlined in the [documentation for custom rules](doc/CustomRules.md#authoring).
To apply fixes consistently, the `applyFix`/`applyFixes` methods may be used:
To apply fixes consistently, the `applyFix`/`applyFixes` methods may be used via
`import { applyFix, applyFixes } from "markdownlint"`:
```javascript
/**
@ -798,18 +797,19 @@ function applyFixes(input, errors) { ... }
Invoking `applyFixes` with the results of a call to lint can be done like so:
```javascript
import markdownlint from "markdownlint";
import { applyFixes } from "markdownlint";
import { lint as lintSync } from "markdownlint/sync";
const fixResults = markdownlint.sync({ "strings": { "content": original } });
const fixed = markdownlint.applyFixes(original, fixResults.content);
const results = lintSync({ "strings": { "content": original } });
const fixed = applyFixes(original, results.content);
```
## Usage
Invoke `markdownlint` and use the `result` object's `toString` method:
Invoke `lint` and use the `result` object's `toString` method:
```javascript
import markdownlint from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
const options = {
"files": [ "good.md", "bad.md" ],
@ -819,9 +819,9 @@ const options = {
}
};
markdownlint(options, function callback(err, result) {
if (!err) {
console.log(result.toString());
lintAsync(options, function callback(error, results) {
if (!error && results) {
console.log(results.toString());
}
});
```
@ -839,21 +839,22 @@ bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
```
Or invoke `markdownlint.sync` for a synchronous call:
Or as a synchronous call:
```javascript
const result = markdownlint.sync(options);
console.log(result.toString());
import { lint as lintSync } from "markdownlint/sync";
const results = lintSync(options);
console.log(results.toString());
```
To examine the `result` object directly:
To examine the `result` object directly via a `Promise`-based call:
```javascript
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true, "depth": null });
}
});
import { lint as lintPromise } from "markdownlint/promise";
const results = await lintPromise(options);
console.dir(results, { "colors": true, "depth": null });
```
Output:
@ -910,7 +911,7 @@ Generate normal and minified scripts with:
npm run build-demo
```
Then reference the `markdownlint` script:
Then reference the `markdownlint-browser` script:
```html
<script src="demo/markdownlint-browser.min.js"></script>
@ -924,7 +925,8 @@ const options = {
"content": "Some Markdown to lint."
}
};
const results = window.markdownlint.markdownlint.sync(options).toString();
const results = globalThis.markdownlint.lintSync(options).toString();
```
## Examples

View file

@ -1,6 +1,7 @@
// @ts-check
export { default as markdownlint } from "../lib/markdownlint.mjs";
export { applyFixes, getVersion } from "markdownlint";
export { lint as lintSync } from "markdownlint/sync";
export { compile, parse, postprocess, preprocess } from "micromark";
export { directive, directiveHtml } from "micromark-extension-directive";
export { gfmAutolinkLiteral, gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal";

View file

@ -3,8 +3,8 @@
(function main() {
// Dependencies
var markdownit = globalThis.markdownit;
var markdownlint = globalThis.markdownlint.markdownlint;
var micromark = globalThis.markdownlint;
var markdownlint = globalThis.markdownlint;
var micromark = markdownlint;
// DOM elements
var markdown = document.getElementById("markdown");
@ -112,7 +112,7 @@
},
"handleRuleFailures": true
};
allLintErrors = markdownlint.sync(options).content;
allLintErrors = markdownlint.lintSync(options).content;
violations.innerHTML = allLintErrors.map(function mapResult(result) {
var ruleName = result.ruleNames.slice(0, 2).join(" / ");
return "<em><a href='#line' target='" + result.lineNumber + "'>" +

View file

@ -160,8 +160,8 @@ implementation that is resolved when the rule completes. (The value passed to
reported via the `onError` function just like for synchronous rules.
**Note**: Asynchronous rules cannot be referenced in a synchronous calling
context (i.e., `markdownlint.sync(...)`). Attempting to do so throws an
exception.
context (i.e., `import { lint } from "markdownlint/sync"`). Attempting to do so
throws an exception.
## Examples

View file

@ -149,7 +149,7 @@ export default [
],
"rules": {
"no-console": "off",
"no-shadow": "off"
"no-constant-condition": "off"
}
},
{

View file

@ -13,8 +13,8 @@ module.exports = function wrapper(grunt) {
grunt.registerMultiTask("markdownlint", function task() {
const done = this.async();
import("markdownlint").then(({ "default": markdownlint }) => {
markdownlint(
import("markdownlint/async").then(({ lint }) => {
lint(
{ "files": this.filesSrc },
function callback(err, result) {
const resultString = err || ((result || "").toString());

View file

@ -9,8 +9,8 @@ const through2 = require("through2");
gulp.task("markdownlint", function task() {
return gulp.src("*.md", { "read": false })
.pipe(through2.obj(function obj(file, enc, next) {
import("markdownlint").then(({ "default": markdownlint }) => {
markdownlint(
import("markdownlint/async").then(({ lint }) => {
lint(
{ "files": [ file.relative ] },
function callback(err, result) {
const resultString = (result || "").toString();

View file

@ -1,6 +1,9 @@
// @ts-check
import markdownlint from "markdownlint";
import { applyFixes } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
const options = {
"files": [ "good.md", "bad.md" ],
@ -10,27 +13,39 @@ const options = {
}
};
// Makes a synchronous call, using result.toString for pretty formatting
const result = markdownlint.sync(options);
console.log(result.toString());
if (true) {
// Makes an asynchronous call
markdownlint(options, function callback(err, result) {
if (!err) {
// @ts-ignore
console.log(result.toString());
// Makes a synchronous call, uses result.toString for pretty formatting
const results = lintSync(options);
console.log(results.toString());
}
if (true) {
// Makes an asynchronous call, uses result.toString for pretty formatting
lintAsync(options, function callback(error, results) {
if (!error && results) {
console.log(results.toString());
}
});
// Displays the result object directly
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true, "depth": null });
}
});
if (true) {
// Makes a Promise-based asynchronous call, displays the result object directly
const results = await lintPromise(options);
console.dir(results, { "colors": true, "depth": null });
}
if (true) {
// Fixes all supported violations in Markdown content
const original = "# Heading";
const fixResults = markdownlint.sync({ "strings": { "content": original } });
const fixed = markdownlint.applyFixes(original, fixResults.content);
const results = lintSync({ "strings": { "content": original } });
const fixed = applyFixes(original, results.content);
console.log(fixed);
}

View file

@ -1,13 +1,17 @@
// Attempt to validate all the type declarations in markdownlint.d.mts
// Attempt to validate important type declarations
import { default as markdownlint, Configuration, ConfigurationStrict, LintResults, Options, Rule, RuleParams, RuleOnError, RuleOnErrorInfo } from "../../lib/markdownlint.mjs";
import { Configuration, ConfigurationStrict, LintResults, Options, Rule, RuleParams, RuleOnError, RuleOnErrorInfo } from "../../lib/exports.mjs";
import { applyFix, applyFixes, getVersion } from "../../lib/exports.mjs";
import { lint as lintAsync, readConfig as readConfigAsync } from "../../lib/exports-async.mjs";
import { lint as lintPromise, readConfig as readConfigPromise } from "../../lib/exports-promise.mjs";
import { lint as lintSync, readConfig as readConfigSync } from "../../lib/exports-sync.mjs";
import assert from "assert";
// @ts-expect-error TS7016: Could not find a declaration file for module 'markdown-it-sub'.
import markdownItSub from "markdown-it-sub";
const markdownlintJsonPath = "../../.markdownlint.json";
const version: string = markdownlint.getVersion();
const version: string = getVersion();
assert(/^\d+\.\d+\.\d+$/.test(version));
function assertConfiguration(config: Configuration) {
@ -67,15 +71,15 @@ function assertLintResultsCallback(err: Error | null, results?: LintResults) {
results && assertLintResults(results);
}
assertConfiguration(markdownlint.readConfigSync(markdownlintJsonPath));
assertConfiguration(markdownlint.readConfigSync(markdownlintJsonPath, [ JSON.parse ]));
assertConfiguration(readConfigSync(markdownlintJsonPath));
assertConfiguration(readConfigSync(markdownlintJsonPath, [ JSON.parse ]));
markdownlint.readConfig(markdownlintJsonPath, assertConfigurationCallback);
markdownlint.readConfig(markdownlintJsonPath, [ JSON.parse ], assertConfigurationCallback);
readConfigAsync(markdownlintJsonPath, assertConfigurationCallback);
readConfigAsync(markdownlintJsonPath, [ JSON.parse ], assertConfigurationCallback);
(async () => {
assertConfigurationCallback(null, await markdownlint.promises.readConfig(markdownlintJsonPath));
assertConfigurationCallback(null, await markdownlint.promises.readConfig(markdownlintJsonPath, [ JSON.parse ]))
assertConfigurationCallback(null, await readConfigPromise(markdownlintJsonPath));
assertConfigurationCallback(null, await readConfigPromise(markdownlintJsonPath, [ JSON.parse ]))
})();
let options: Options;
@ -98,17 +102,17 @@ options = {
"markdownItPlugins": [ [ markdownItSub ] ]
};
assertLintResults(markdownlint.sync(options));
markdownlint(options, assertLintResultsCallback);
assertLintResults(lintSync(options));
lintAsync(options, assertLintResultsCallback);
(async () => {
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
assertLintResultsCallback(null, await lintPromise(options));
})();
options.files = "../bad.md";
assertLintResults(markdownlint.sync(options));
markdownlint(options, assertLintResultsCallback);
assertLintResults(lintSync(options));
lintAsync(options, assertLintResultsCallback);
(async () => {
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
assertLintResultsCallback(null, await lintPromise(options));
})();
const testRule: Rule = {
@ -162,14 +166,14 @@ const testRule: Rule = {
};
options.customRules = [ testRule ];
assertLintResults(markdownlint.sync(options));
markdownlint(options, assertLintResultsCallback);
assertLintResults(lintSync(options));
lintAsync(options, assertLintResultsCallback);
(async () => {
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
assertLintResultsCallback(null, await lintPromise(options));
})();
assert.equal(
markdownlint.applyFix(
applyFix(
"# Fixing\n",
{
"insertText": "Head",
@ -182,7 +186,7 @@ assert.equal(
);
assert.equal(
markdownlint.applyFixes(
applyFixes(
"# Fixing\n",
[
{

View file

@ -10,13 +10,18 @@ module.exports.newLineRe = newLineRe;
module.exports.nextLinesRe = nextLinesRe;
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").RuleOnError} RuleOnError */
/** @typedef {import("markdownlint").RuleOnError} RuleOnError */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
/** @typedef {import("markdownlint").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} MicromarkToken */
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
// eslint-disable-next-line jsdoc/valid-types
/** @typedef {import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} */
// eslint-disable-next-line jsdoc/valid-types
/** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
// Regular expression for matching common front matter (YAML and TOML)
// @ts-ignore
module.exports.frontMatterRe =
/((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
@ -368,7 +373,7 @@ module.exports.frontMatterHasTitle =
/**
* Returns an object with information about reference links and images.
*
* @param {import("../helpers/micromark-helpers.cjs").Token[]} tokens Micromark tokens.
* @param {MicromarkToken[]} tokens Micromark tokens.
* @returns {Object} Reference link/image data.
*/
function getReferenceLinkImageData(tokens) {

View file

@ -4,10 +4,10 @@
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
// eslint-disable-next-line jsdoc/valid-types
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("micromark-util-types").TokenType} TokenType */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} Token */
/** @typedef {import("markdownlint").MicromarkToken} Token */
/**
* Determines if a Micromark token is within an htmlFlow type.

View file

@ -10,7 +10,7 @@ let params = undefined;
/**
* Initializes (resets) the cache.
*
* @param {import("./markdownlint.mjs").RuleParams} [p] Rule parameters object.
* @param {import("markdownlint").RuleParams} [p] Rule parameters object.
* @returns {void}
*/
export function initialize(p) {
@ -37,9 +37,9 @@ function getCached(name, getValue) {
/**
* Filters a list of Micromark tokens by type and caches the result.
*
* @param {import("./markdownlint.mjs").MicromarkTokenType[]} types Types to allow.
* @param {import("markdownlint").MicromarkTokenType[]} types Types to allow.
* @param {boolean} [htmlFlow] Whether to include htmlFlow content.
* @returns {import("./markdownlint.mjs").MicromarkToken[]} Filtered tokens.
* @returns {import("markdownlint").MicromarkToken[]} Filtered tokens.
*/
export function filterByTypesCached(types, htmlFlow) {
return getCached(

1
lib/exports-async.d.mts Normal file
View file

@ -0,0 +1 @@
export { lintAsync as lint, readConfigAsync as readConfig } from "./markdownlint.mjs";

3
lib/exports-async.mjs Normal file
View file

@ -0,0 +1,3 @@
// @ts-check
export { lintAsync as lint, readConfigAsync as readConfig } from "./markdownlint.mjs";

View file

@ -0,0 +1 @@
export { extendConfigPromise as extendConfig, lintPromise as lint, readConfigPromise as readConfig } from "./markdownlint.mjs";

3
lib/exports-promise.mjs Normal file
View file

@ -0,0 +1,3 @@
// @ts-check
export { extendConfigPromise as extendConfig, lintPromise as lint, readConfigPromise as readConfig } from "./markdownlint.mjs";

1
lib/exports-sync.d.mts Normal file
View file

@ -0,0 +1 @@
export { lintSync as lint, readConfigSync as readConfig } from "./markdownlint.mjs";

3
lib/exports-sync.mjs Normal file
View file

@ -0,0 +1,3 @@
// @ts-check
export { lintSync as lint, readConfigSync as readConfig } from "./markdownlint.mjs";

28
lib/exports.d.mts Normal file
View file

@ -0,0 +1,28 @@
export type Configuration = import("./markdownlint.mjs").Configuration;
export type ConfigurationParser = import("./markdownlint.mjs").ConfigurationParser;
export type ConfigurationStrict = import("./markdownlint.mjs").ConfigurationStrict;
export type FixInfo = import("./markdownlint.mjs").FixInfo;
export type LintCallback = import("./markdownlint.mjs").LintCallback;
export type LintContentCallback = import("./markdownlint.mjs").LintContentCallback;
export type LintError = import("./markdownlint.mjs").LintError;
export type LintResults = import("./markdownlint.mjs").LintResults;
export type MarkdownItToken = import("./markdownlint.mjs").MarkdownItToken;
export type MarkdownParsers = import("./markdownlint.mjs").MarkdownParsers;
export type MicromarkToken = import("./markdownlint.mjs").MicromarkToken;
export type MicromarkTokenType = import("./markdownlint.mjs").MicromarkTokenType;
export type Options = import("./markdownlint.mjs").Options;
export type ParserMarkdownIt = import("./markdownlint.mjs").ParserMarkdownIt;
export type ParserMicromark = import("./markdownlint.mjs").ParserMicromark;
export type Plugin = import("./markdownlint.mjs").Plugin;
export type ReadConfigCallback = import("./markdownlint.mjs").ReadConfigCallback;
export type ResolveConfigExtendsCallback = import("./markdownlint.mjs").ResolveConfigExtendsCallback;
export type Rule = import("./markdownlint.mjs").Rule;
export type RuleConfiguration = import("./markdownlint.mjs").RuleConfiguration;
export type RuleFunction = import("./markdownlint.mjs").RuleFunction;
export type RuleOnError = import("./markdownlint.mjs").RuleOnError;
export type RuleOnErrorFixInfo = import("./markdownlint.mjs").RuleOnErrorFixInfo;
export type RuleOnErrorFixInfoNormalized = import("./markdownlint.mjs").RuleOnErrorFixInfoNormalized;
export type RuleOnErrorInfo = import("./markdownlint.mjs").RuleOnErrorInfo;
export type RuleParams = import("./markdownlint.mjs").RuleParams;
export type ToStringCallback = import("./markdownlint.mjs").ToStringCallback;
export { applyFix, applyFixes, getVersion } from "./markdownlint.mjs";

31
lib/exports.mjs Normal file
View file

@ -0,0 +1,31 @@
// @ts-check
export { applyFix, applyFixes, getVersion } from "./markdownlint.mjs";
/** @typedef {import("./markdownlint.mjs").Configuration} Configuration */
/** @typedef {import("./markdownlint.mjs").ConfigurationParser} ConfigurationParser */
/** @typedef {import("./markdownlint.mjs").ConfigurationStrict} ConfigurationStrict */
/** @typedef {import("./markdownlint.mjs").FixInfo} FixInfo */
/** @typedef {import("./markdownlint.mjs").LintCallback} LintCallback */
/** @typedef {import("./markdownlint.mjs").LintContentCallback} LintContentCallback */
/** @typedef {import("./markdownlint.mjs").LintError} LintError */
/** @typedef {import("./markdownlint.mjs").LintResults} LintResults */
/** @typedef {import("./markdownlint.mjs").MarkdownItToken} MarkdownItToken */
/** @typedef {import("./markdownlint.mjs").MarkdownParsers} MarkdownParsers */
/** @typedef {import("./markdownlint.mjs").MicromarkToken} MicromarkToken */
/** @typedef {import("./markdownlint.mjs").MicromarkTokenType} MicromarkTokenType */
/** @typedef {import("./markdownlint.mjs").Options} Options */
/** @typedef {import("./markdownlint.mjs").ParserMarkdownIt} ParserMarkdownIt */
/** @typedef {import("./markdownlint.mjs").ParserMicromark} ParserMicromark */
/** @typedef {import("./markdownlint.mjs").Plugin} Plugin */
/** @typedef {import("./markdownlint.mjs").ReadConfigCallback} ReadConfigCallback */
/** @typedef {import("./markdownlint.mjs").ResolveConfigExtendsCallback} ResolveConfigExtendsCallback */
/** @typedef {import("./markdownlint.mjs").Rule} Rule */
/** @typedef {import("./markdownlint.mjs").RuleConfiguration} RuleConfiguration */
/** @typedef {import("./markdownlint.mjs").RuleFunction} RuleFunction */
/** @typedef {import("./markdownlint.mjs").RuleOnError} RuleOnError */
/** @typedef {import("./markdownlint.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
/** @typedef {import("./markdownlint.mjs").RuleOnErrorFixInfoNormalized} RuleOnErrorFixInfoNormalized */
/** @typedef {import("./markdownlint.mjs").RuleOnErrorInfo} RuleOnErrorInfo */
/** @typedef {import("./markdownlint.mjs").RuleParams} RuleParams */
/** @typedef {import("./markdownlint.mjs").ToStringCallback} ToStringCallback */

View file

@ -5,9 +5,9 @@
const { newLineRe } = require("../helpers");
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("./markdownlint.mjs").MarkdownItToken} MarkdownItToken */
/** @typedef {import("markdownlint").MarkdownItToken} MarkdownItToken */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("./markdownlint.mjs").Plugin} Plugin */
/** @typedef {import("markdownlint").Plugin} Plugin */
/**
* @callback InlineCodeSpanCallback

View file

@ -1,4 +1,87 @@
export default markdownlint;
/**
* Lint specified Markdown files.
*
* @param {Options | null} options Configuration options.
* @param {LintCallback} callback Callback (err, result) function.
* @returns {void}
*/
export function lintAsync(options: Options | null, callback: LintCallback): void;
/**
* Lint specified Markdown files.
*
* @param {Options | null} options Configuration options.
* @returns {Promise<LintResults>} Results object.
*/
export function lintPromise(options: Options | null): Promise<LintResults>;
/**
* Lint specified Markdown files.
*
* @param {Options | null} options Configuration options.
* @returns {LintResults} Results object.
*/
export function lintSync(options: Options | null): LintResults;
/**
* Extend specified configuration object.
*
* @param {Configuration} config Configuration object.
* @param {string} file Configuration file name.
* @param {ConfigurationParser[] | undefined} parsers Parsing function(s).
* @param {Object} fs File system implementation.
* @returns {Promise<Configuration>} Configuration object.
*/
export function extendConfigPromise(config: Configuration, file: string, parsers: ConfigurationParser[] | undefined, fs: any): Promise<Configuration>;
/**
* Read specified configuration file.
*
* @param {string} file Configuration file name.
* @param {ConfigurationParser[] | ReadConfigCallback} [parsers] Parsing
* function(s).
* @param {Object} [fs] File system implementation.
* @param {ReadConfigCallback} [callback] Callback (err, result) function.
* @returns {void}
*/
export function readConfigAsync(file: string, parsers?: ConfigurationParser[] | ReadConfigCallback, fs?: any, callback?: ReadConfigCallback): void;
/**
* Read specified configuration file.
*
* @param {string} file Configuration file name.
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
* @param {Object} [fs] File system implementation.
* @returns {Promise<Configuration>} Configuration object.
*/
export function readConfigPromise(file: string, parsers?: ConfigurationParser[], fs?: any): Promise<Configuration>;
/**
* 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.
*/
export function readConfigSync(file: string, parsers?: ConfigurationParser[], fs?: any): Configuration;
/**
* Applies the specified fix to a Markdown content line.
*
* @param {string} line Line of Markdown content.
* @param {RuleOnErrorFixInfo} fixInfo RuleOnErrorFixInfo instance.
* @param {string} [lineEnding] Line ending to use.
* @returns {string | null} Fixed content or null if deleted.
*/
export function applyFix(line: string, fixInfo: RuleOnErrorFixInfo, lineEnding?: string): string | null;
/**
* Applies as many of the specified fixes as possible to Markdown content.
*
* @param {string} input Lines of Markdown content.
* @param {RuleOnErrorInfo[]} errors RuleOnErrorInfo instances.
* @returns {string} Fixed content.
*/
export function applyFixes(input: string, errors: RuleOnErrorInfo[]): string;
/**
* Gets the (semantic) version of the library.
*
* @returns {string} SemVer string.
*/
export function getVersion(): string;
/**
* Function to implement rule logic.
*/
@ -431,101 +514,3 @@ export type ReadConfigCallback = (err: Error | null, config?: Configuration) =>
* Called with the result of the resolveConfigExtends function.
*/
export type ResolveConfigExtendsCallback = (err: Error | null, path?: string) => void;
/**
* Lint specified Markdown files.
*
* @param {Options | null} options Configuration options.
* @param {LintCallback} callback Callback (err, result) function.
* @returns {void}
*/
declare function markdownlint(options: Options | null, callback: LintCallback): void;
declare namespace markdownlint {
export { markdownlintSync as sync };
export { readConfig };
export { readConfigSync };
export { getVersion };
export namespace promises {
export { markdownlintPromise as markdownlint };
export { extendConfigPromise as extendConfig };
export { readConfigPromise as readConfig };
}
export { applyFix };
export { applyFixes };
}
/**
* Lint specified Markdown files synchronously.
*
* @param {Options | null} options Configuration options.
* @returns {LintResults} Results object.
*/
declare function markdownlintSync(options: Options | null): LintResults;
/**
* Read specified configuration file.
*
* @param {string} file Configuration file name.
* @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;
/**
* Read specified configuration file synchronously.
*
* @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.
*/
declare function readConfigSync(file: string, parsers?: ConfigurationParser[], fs?: any): Configuration;
/**
* Gets the (semantic) version of the library.
*
* @returns {string} SemVer string.
*/
declare function getVersion(): string;
/**
* Lint specified Markdown files.
*
* @param {Options} options Configuration options.
* @returns {Promise<LintResults>} Results object.
*/
declare function markdownlintPromise(options: Options): Promise<LintResults>;
/**
* Extend specified configuration object.
*
* @param {Configuration} config Configuration object.
* @param {string} file Configuration file name.
* @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[] | undefined, fs: any): Promise<Configuration>;
/**
* Read specified configuration file.
*
* @param {string} file Configuration file name.
* @param {ConfigurationParser[]} [parsers] Parsing function(s).
* @param {Object} [fs] File system implementation.
* @returns {Promise<Configuration>} Configuration object.
*/
declare function readConfigPromise(file: string, parsers?: ConfigurationParser[], fs?: any): Promise<Configuration>;
/**
* Applies the specified fix to a Markdown content line.
*
* @param {string} line Line of Markdown content.
* @param {RuleOnErrorFixInfo} fixInfo RuleOnErrorFixInfo instance.
* @param {string} [lineEnding] Line ending to use.
* @returns {string | null} Fixed content or null if deleted.
*/
declare function applyFix(line: string, fixInfo: RuleOnErrorFixInfo, lineEnding?: string): string | null;
/**
* Applies as many of the specified fixes as possible to Markdown content.
*
* @param {string} input Lines of Markdown content.
* @param {RuleOnErrorInfo[]} errors RuleOnErrorInfo instances.
* @returns {string} Fixed content.
*/
declare function applyFixes(input: string, errors: RuleOnErrorInfo[]): string;

View file

@ -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
/**

View file

@ -4,7 +4,7 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD001", "heading-increment" ],
"description": "Heading levels should only increment by one level at a time",

View file

@ -4,7 +4,7 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingStyle } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD003", "heading-style" ],
"description": "Heading style",

View file

@ -27,7 +27,7 @@ const validStyles = new Set([
"sublist"
]);
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD004", "ul-style" ],
"description": "Unordered list style",
@ -40,7 +40,7 @@ export default {
for (const listUnordered of filterByTypesCached([ "listUnordered" ])) {
let nesting = 0;
if (style === "sublist") {
/** @type {import("../helpers/micromark-helpers.cjs").Token | null} */
/** @type {import("markdownlint").MicromarkToken | null} */
let parent = listUnordered;
// @ts-ignore
while ((parent = getParentOfType(parent, [ "listOrdered", "listUnordered" ]))) {

View file

@ -3,7 +3,7 @@
import { addError, addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD005", "list-indent" ],
"description": "Inconsistent indentation for list items at the same level",

View file

@ -11,7 +11,7 @@ const unorderedListTypes =
const unorderedParentTypes =
[ "blockQuote", "listOrdered", "listUnordered" ];
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation",
@ -30,7 +30,7 @@ export default {
lastBlockQuotePrefix = token;
} else if (type === "listUnordered") {
let nesting = 0;
/** @type {import("../helpers/micromark-helpers.cjs").Token | null} */
/** @type {import("markdownlint").MicromarkToken | null} */
let current = token;
while (
// @ts-ignore

View file

@ -4,7 +4,7 @@ import { addError } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD009", "no-trailing-spaces" ],
"description": "Trailing spaces",

View file

@ -6,7 +6,7 @@ import { filterByTypesCached } from "./cache.mjs";
const tabRe = /\t+/g;
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD010", "no-hard-tabs" ],
"description": "Hard tabs",
@ -23,7 +23,7 @@ export default {
const spaceMultiplier = (spacesPerTab === undefined) ?
1 :
Math.max(0, Number(spacesPerTab));
/** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
/** @type {import("markdownlint").MicromarkTokenType[]} */
const exclusionTypes = [];
if (includeCode) {
if (ignoreCodeLanguages.size > 0) {

View file

@ -6,7 +6,7 @@ import { filterByTypesCached } from "./cache.mjs";
const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD011", "no-reversed-links" ],
"description": "Reversed link syntax",

View file

@ -4,7 +4,7 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines",

View file

@ -12,7 +12,7 @@ const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
/** @typedef {import("micromark-extension-gfm-autolink-literal")} */
/** @typedef {import("micromark-extension-gfm-table")} */
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD013", "line-length" ],
"description": "Line length",

View file

@ -5,7 +5,7 @@ import { filterByTypesCached } from "./cache.mjs";
const dollarCommandRe = /^(\s*)(\$\s+)/;
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output",

View file

@ -4,7 +4,7 @@ import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading",

View file

@ -7,8 +7,8 @@ import { filterByTypesCached } from "./cache.mjs";
/**
* Validate heading sequence and whitespace length at start or end.
*
* @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("./markdownlint.mjs").MicromarkToken} heading ATX heading token.
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
* @param {import("markdownlint").MicromarkToken} heading ATX heading token.
* @param {number} delta Direction to scan.
* @returns {void}
*/
@ -45,7 +45,7 @@ function validateHeadingSpaces(onError, heading, delta) {
}
}
/** @type {import("./markdownlint.mjs").Rule[]} */
/** @type {import("markdownlint").Rule[]} */
export default [
{
"names": [ "MD019", "no-multiple-space-atx" ],

View file

@ -4,7 +4,7 @@ import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD020", "no-missing-space-closed-atx" ],
"description": "No space inside hashes on closed atx style heading",

View file

@ -19,7 +19,7 @@ const getLinesFunction = (linesParam) => {
return () => lines;
};
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD022", "blanks-around-headings" ],
"description": "Headings should be surrounded by blank lines",

View file

@ -3,7 +3,7 @@
import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD023", "heading-start-left" ],
"description": "Headings must start at the beginning of the line",

View file

@ -4,7 +4,7 @@ import { addErrorContext } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD024", "no-duplicate-heading" ],
"description": "Multiple headings with the same content",

View file

@ -4,7 +4,7 @@ import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD025", "single-title", "single-h1" ],
"description": "Multiple top-level headings in the same document",

View file

@ -4,7 +4,7 @@ import { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
endOfLineHtmlEntityRe, escapeForRegExp } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD026", "no-trailing-punctuation" ],
"description": "Trailing punctuation in heading",

View file

@ -3,7 +3,7 @@
import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD027", "no-multiple-space-blockquote" ],
"description": "Multiple spaces after blockquote symbol",

View file

@ -5,7 +5,7 @@ import { filterByTypesCached } from "./cache.mjs";
const ignoreTypes = new Set([ "lineEnding", "listItemIndent", "linePrefix" ]);
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD028", "no-blanks-blockquote" ],
"description": "Blank line inside blockquote",

View file

@ -13,14 +13,14 @@ const listStyleExamples = {
/**
* Gets the value of an ordered list item prefix token.
*
* @param {import("../helpers/micromark-helpers.cjs").Token} listItemPrefix List item prefix token.
* @param {import("markdownlint").MicromarkToken} listItemPrefix List item prefix token.
* @returns {number} List item value.
*/
function getOrderedListItemValue(listItemPrefix) {
return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
}
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD029", "ol-prefix" ],
"description": "Ordered list item prefix",

View file

@ -3,7 +3,7 @@
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD030", "list-marker-space" ],
"description": "Spaces after list markers",

View file

@ -12,7 +12,7 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
/**
* Adds an error for the top or bottom of a code fence.
*
* @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
* @param {ReadonlyStringArray} lines Lines of Markdown content.
* @param {number} lineNumber Line number.
* @param {boolean} top True iff top fence.
@ -38,7 +38,7 @@ function addError(onError, lines, lineNumber, top) {
);
}
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD031", "blanks-around-fences" ],
"description": "Fenced code blocks should be surrounded by blank lines",

View file

@ -8,7 +8,7 @@ const isList = (token) => (
(token.type === "listOrdered") || (token.type === "listUnordered")
);
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD032", "blanks-around-lists" ],
"description": "Lists should be surrounded by blank lines",

View file

@ -4,7 +4,7 @@ import { addError, nextLinesRe } from "../helpers/helpers.cjs";
import { getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD033", "no-inline-html" ],
"description": "Inline HTML",

View file

@ -5,7 +5,7 @@ import { filterByPredicate, getHtmlTagInfo, inHtmlFlow } from "../helpers/microm
/** @typedef {import("micromark-extension-gfm-autolink-literal")} */
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used",

View file

@ -3,7 +3,7 @@
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD035", "hr-style" ],
"description": "Horizontal rule style",

View file

@ -4,14 +4,14 @@ import { addErrorContext, allPunctuation } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */
/** @typedef {import("markdownlint").MicromarkTokenType} TokenType */
/** @type {TokenType[][]} */
const emphasisTypes = [
[ "emphasis", "emphasisText" ],
[ "strong", "strongText" ]
];
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD036", "no-emphasis-as-heading" ],
"description": "Emphasis used instead of a heading",

View file

@ -3,7 +3,7 @@
import { addError } from "../helpers/helpers.cjs";
import { filterByPredicate, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD037", "no-space-in-emphasis" ],
"description": "Spaces inside emphasis markers",

View file

@ -17,7 +17,7 @@ const trimCodeText = (text, start, end) => {
return text;
};
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD038", "no-space-in-code" ],
"description": "Spaces inside code span elements",

View file

@ -6,9 +6,9 @@ import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
/**
* Adds an error for a label space issue.
*
* @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("../helpers/micromark-helpers.cjs").Token} label Label token.
* @param {import("../helpers/micromark-helpers.cjs").Token} labelText LabelText token.
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
* @param {import("markdownlint").MicromarkToken} label Label token.
* @param {import("markdownlint").MicromarkToken} labelText LabelText token.
* @param {boolean} isStart True iff error is at the start of the link.
*/
function addLabelSpaceError(onError, label, labelText, isStart) {
@ -38,8 +38,8 @@ function addLabelSpaceError(onError, label, labelText, isStart) {
/**
* Determines if a link is a valid link (and not a fake shortcut link due to parser tricks).
*
* @param {import("../helpers/micromark-helpers.cjs").Token} label Label token.
* @param {import("../helpers/micromark-helpers.cjs").Token} labelText LabelText token.
* @param {import("markdownlint").MicromarkToken} label Label token.
* @param {import("markdownlint").MicromarkToken} labelText LabelText token.
* @param {Map<string, any>} definitions Map of link definitions.
* @returns {boolean} True iff the link is valid.
*/
@ -47,7 +47,7 @@ function validLink(label, labelText, definitions) {
return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim());
}
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD039", "no-space-in-links" ],
"description": "Spaces inside link text",

View file

@ -4,7 +4,7 @@ import { addError, addErrorContext } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified",

View file

@ -3,7 +3,7 @@
import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
import { filterByTypes, getHeadingLevel, getHtmlTagInfo, isHtmlFlowComment, nonContentTokens } from "../helpers/micromark-helpers.cjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD041", "first-line-heading", "first-line-h1" ],
"description": "First line in a file should be a top-level heading",

View file

@ -4,7 +4,7 @@ import { addErrorContext } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD042", "no-empty-links" ],
"description": "No empty links",

View file

@ -4,7 +4,7 @@ import { addErrorContext, addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD043", "required-headings" ],
"description": "Required heading structure",

View file

@ -8,7 +8,7 @@ const ignoredChildTypes = new Set(
[ "codeFencedFence", "definition", "reference", "resource" ]
);
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD044", "proper-names" ],
"description": "Proper names should have the correct capitalization",

View file

@ -6,7 +6,7 @@ import { filterByTypesCached } from "./cache.mjs";
const altRe = getHtmlAttributeRe("alt");
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)",

View file

@ -8,7 +8,7 @@ const tokenTypeToStyle = {
"codeIndented": "indented"
};
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD046", "code-block-style" ],
"description": "Code block style",

View file

@ -2,7 +2,7 @@
import { addError, isBlankLine } from "../helpers/helpers.cjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD047", "single-trailing-newline" ],
"description": "Files should end with a single newline character",

View file

@ -19,7 +19,7 @@ function fencedCodeBlockStyleFor(markup) {
}
};
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD048", "code-fence-style" ],
"description": "Code fence style",

View file

@ -21,8 +21,8 @@ function emphasisOrStrongStyleFor(markup) {
};
/**
* @param {import("./markdownlint.mjs").RuleParams} params Rule parameters.
* @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("markdownlint").RuleParams} params Rule parameters.
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
* @param {import("micromark-util-types").TokenType} type Token type.
* @param {import("micromark-util-types").TokenType} typeSequence Token sequence type.
* @param {"*" | "**"} asterisk Asterisk kind.
@ -76,7 +76,7 @@ const impl =
}
};
/** @type {import("./markdownlint.mjs").Rule[]} */
/** @type {import("markdownlint").Rule[]} */
export default [
{
"names": [ "MD049", "emphasis-style" ],

View file

@ -20,7 +20,7 @@ const tokensInclude = new Set(
* Converts a Markdown heading into an HTML fragment according to the rules
* used by GitHub.
*
* @param {import("../helpers/micromark-helpers.cjs").Token} headingText Heading text token.
* @param {import("markdownlint").MicromarkToken} headingText Heading text token.
* @returns {string} Fragment string for heading.
*/
function convertHeadingToHTMLFragment(headingText) {
@ -49,7 +49,7 @@ function convertHeadingToHTMLFragment(headingText) {
/**
* Unescapes the text of a String-type micromark Token.
*
* @param {import("../helpers/micromark-helpers.cjs").Token} token String-type micromark Token.
* @param {import("markdownlint").MicromarkToken} token String-type micromark Token.
* @returns {string} Unescaped token text.
*/
function unescapeStringTokenText(token) {
@ -58,7 +58,7 @@ function unescapeStringTokenText(token) {
.join("");
}
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD051", "link-fragments" ],
"description": "Link fragments should be valid",
@ -101,7 +101,7 @@ export default {
}
// Process link and definition fragments
/** @type {import("../helpers/micromark-helpers.cjs").TokenType[][]} */
/** @type {import("markdownlint").MicromarkTokenType[][]} */
const parentChilds = [
[ "link", "resourceDestinationString" ],
[ "definition", "definitionDestinationString" ]

View file

@ -3,7 +3,7 @@
import { addError } from "../helpers/helpers.cjs";
import { getReferenceLinkImageData } from "./cache.mjs";
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD052", "reference-links-images" ],
"description":

View file

@ -5,7 +5,7 @@ import { getReferenceLinkImageData } from "./cache.mjs";
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD053", "link-image-reference-definitions" ],
"description": "Link and image reference definitions should be needed",

View file

@ -18,7 +18,7 @@ const autolinkAble = (destination) => {
return !autolinkDisallowedRe.test(destination);
};
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD054", "link-image-style" ],
"description": "Link and image style",

View file

@ -13,7 +13,7 @@ const makeRange = (start, end) => [ start, end - start + 1 ];
/** @typedef {import("micromark-extension-gfm-table")} */
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD055", "table-pipe-style" ],
"description": "Table pipe style",

View file

@ -8,7 +8,7 @@ const makeRange = (start, end) => [ start, end - start + 1 ];
/** @typedef {import("micromark-extension-gfm-table")} */
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD056", "table-column-count" ],
"description": "Table column count",

View file

@ -6,7 +6,7 @@ import { filterByTypesCached } from "./cache.mjs";
/** @typedef {import("micromark-extension-gfm-table")} */
/** @type {import("./markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD058", "blanks-around-tables" ],
"description": "Tables should be surrounded by blank lines",

View file

@ -17,8 +17,8 @@ import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "../helpers/shared.c
/** @typedef {import("micromark-util-types").State} State */
/** @typedef {import("micromark-util-types").Token} Token */
/** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
/** @typedef {import("./micromark-types.d.mts")} */
/** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} MicromarkToken */
/**
* Parse options.

12
lib/types.d.mts Normal file
View file

@ -0,0 +1,12 @@
declare module "markdownlint" {
export * from "./exports.mjs";
}
declare module "markdownlint/async" {
export * from "./exports-async.mjs";
}
declare module "markdownlint/promise" {
export * from "./exports-promise.mjs";
}
declare module "markdownlint/sync" {
export * from "./exports-sync.mjs";
}

View file

@ -4,14 +4,17 @@
"description": "A Node.js style checker and lint tool for Markdown/CommonMark files.",
"type": "module",
"exports": {
".": "./lib/markdownlint.mjs",
".": "./lib/exports.mjs",
"./async": "./lib/exports-async.mjs",
"./promise": "./lib/exports-promise.mjs",
"./sync": "./lib/exports-sync.mjs",
"./helpers": "./helpers/helpers.cjs",
"./style/all": "./style/all.json",
"./style/cirosantilli": "./style/cirosantilli.json",
"./style/prettier": "./style/prettier.json",
"./style/relaxed": "./style/relaxed.json"
},
"types": "./lib/markdownlint.d.mts",
"types": "./lib/types.d.mts",
"author": "David Anson (https://dlaa.me/)",
"license": "MIT",
"homepage": "https://github.com/DavidAnson/markdownlint",
@ -25,7 +28,7 @@
"build-config": "npm run build-config-schema && npm run build-config-example",
"build-config-example": "node schema/build-config-example.mjs",
"build-config-schema": "node schema/build-config-schema.mjs",
"build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module nodenext --outDir dts --target es2015 lib/markdownlint.mjs && node scripts/index.mjs copy dts/lib/markdownlint.d.mts lib/markdownlint.d.mts && node scripts/index.mjs remove dts",
"build-declaration": "tsc --allowJs --checkJs --declaration --emitDeclarationOnly --module nodenext --outDir dts --rootDir . --target es2015 lib/exports.mjs lib/exports-async.mjs lib/exports-promise.mjs lib/exports-sync.mjs lib/markdownlint.mjs && node scripts/index.mjs copy dts/lib/exports.d.mts lib/exports.d.mts && node scripts/index.mjs copy dts/lib/exports-async.d.mts lib/exports-async.d.mts && node scripts/index.mjs copy dts/lib/exports-promise.d.mts lib/exports-promise.d.mts && node scripts/index.mjs copy dts/lib/exports-sync.d.mts lib/exports-sync.d.mts && node scripts/index.mjs copy dts/lib/markdownlint.d.mts lib/markdownlint.d.mts && node scripts/index.mjs remove dts",
"build-demo": "node scripts/index.mjs copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && cd demo && webpack --no-stats",
"build-docs": "node doc-build/build-rules.mjs",
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",

View file

@ -2,7 +2,7 @@
import fs from "node:fs/promises";
import path from "node:path";
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
/** @type {import("markdownlint").Rule[]} */
import rules from "../lib/rules.mjs";
import jsonSchemaToTypeScript from "json-schema-to-typescript";
import { version } from "../lib/constants.mjs";

View file

@ -1,7 +1,6 @@
import { readFile } from "node:fs/promises";
import { lint } from "markdownlint/promise";
import { parse } from "../lib/micromark-parse.mjs";
import library from "../lib/markdownlint.mjs";
const markdownlint = library.promises.markdownlint;
/* eslint-disable no-await-in-loop, no-console */
@ -43,7 +42,7 @@ for (const file of files) {
let results = null;
performance.mark("profile-start");
for (let i = 0; i < count; i++) {
results = await markdownlint({
results = await lint({
"files": [ file ]
});
}

View file

@ -6,14 +6,16 @@ const require = createRequire(import.meta.url);
import os from "node:os";
import path from "node:path";
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { readConfig as readConfigAsync } from "markdownlint/async";
import { extendConfig, readConfig as readConfigPromise } from "markdownlint/promise";
import { readConfig as readConfigSync } from "markdownlint/sync";
import { __dirname } from "./esm-helpers.mjs";
const sameFileSystem = (path.relative(os.homedir(), __dirname(import.meta)) !== __dirname(import.meta));
test("configSingle", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig("./test/config/config-child.json",
readConfigAsync("./test/config/config-child.json",
function callback(err, actual) {
t.falsy(err);
const expected = require("./config/config-child.json");
@ -24,7 +26,7 @@ test("configSingle", (t) => new Promise((resolve) => {
test("configAbsolute", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig(path.join(__dirname(import.meta), "config", "config-child.json"),
readConfigAsync(path.join(__dirname(import.meta), "config", "config-child.json"),
function callback(err, actual) {
t.falsy(err);
const expected = require("./config/config-child.json");
@ -36,7 +38,7 @@ test("configAbsolute", (t) => new Promise((resolve) => {
if (sameFileSystem) {
test("configTilde", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig(
readConfigAsync(
`~/${path.relative(os.homedir(), "./test/config/config-child.json")}`,
function callback(err, actual) {
t.falsy(err);
@ -49,7 +51,7 @@ if (sameFileSystem) {
test("configMultiple", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig("./test/config/config-grandparent.json",
readConfigAsync("./test/config/config-grandparent.json",
function callback(err, actual) {
t.falsy(err);
const expected = {
@ -66,7 +68,7 @@ test("configMultiple", (t) => new Promise((resolve) => {
test("configMultipleWithRequireResolve", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig("./test/config/config-packageparent.json",
readConfigAsync("./test/config/config-packageparent.json",
function callback(err, actual) {
t.falsy(err);
const expected = {
@ -108,7 +110,7 @@ test("configCustomFileSystem", (t) => new Promise((resolve) => {
return t.fail(p);
}
};
markdownlint.readConfig(
readConfigAsync(
file,
// @ts-ignore
null,
@ -128,7 +130,7 @@ test("configCustomFileSystem", (t) => new Promise((resolve) => {
test("configBadFile", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint.readConfig("./test/config/config-badfile.json",
readConfigAsync("./test/config/config-badfile.json",
function callback(err, result) {
t.truthy(err, "Did not get an error for bad file.");
t.true(err instanceof Error, "Error not instance of Error.");
@ -141,7 +143,7 @@ test("configBadFile", (t) => new Promise((resolve) => {
test("configBadChildFile", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint.readConfig("./test/config/config-badchildfile.json",
readConfigAsync("./test/config/config-badchildfile.json",
function callback(err, result) {
t.truthy(err, "Did not get an error for bad child file.");
t.true(err instanceof Error, "Error not instance of Error.");
@ -155,7 +157,7 @@ test("configBadChildFile", (t) => new Promise((resolve) => {
test("configBadChildPackage", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint.readConfig("./test/config/config-badchildpackage.json",
readConfigAsync("./test/config/config-badchildpackage.json",
function callback(err, result) {
t.truthy(err, "Did not get an error for bad child package.");
t.true(err instanceof Error, "Error not instance of Error.");
@ -169,7 +171,7 @@ test("configBadChildPackage", (t) => new Promise((resolve) => {
test("configBadJson", (t) => new Promise((resolve) => {
t.plan(3);
markdownlint.readConfig("./test/config/config-badjson.json",
readConfigAsync("./test/config/config-badjson.json",
function callback(err, result) {
t.truthy(err, "Did not get an error for bad JSON.");
t.true(err instanceof Error, "Error not instance of Error.");
@ -180,7 +182,7 @@ test("configBadJson", (t) => new Promise((resolve) => {
test("configBadChildJson", (t) => new Promise((resolve) => {
t.plan(3);
markdownlint.readConfig("./test/config/config-badchildjson.json",
readConfigAsync("./test/config/config-badchildjson.json",
function callback(err, result) {
t.truthy(err, "Did not get an error for bad child JSON.");
t.true(err instanceof Error, "Error not instance of Error.");
@ -191,7 +193,7 @@ test("configBadChildJson", (t) => new Promise((resolve) => {
test("configSingleYaml", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig(
readConfigAsync(
"./test/config/config-child.yaml",
// @ts-ignore
[ require("js-yaml").load ],
@ -205,7 +207,7 @@ test("configSingleYaml", (t) => new Promise((resolve) => {
test("configMultipleYaml", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig(
readConfigAsync(
"./test/config/config-grandparent.yaml",
// @ts-ignore
[ require("js-yaml").load ],
@ -225,7 +227,7 @@ test("configMultipleYaml", (t) => new Promise((resolve) => {
test("configMultipleHybrid", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.readConfig(
readConfigAsync(
"./test/config/config-grandparent-hybrid.yaml",
// @ts-ignore
[ JSON.parse, require("toml").parse, require("js-yaml").load ],
@ -245,7 +247,7 @@ test("configMultipleHybrid", (t) => new Promise((resolve) => {
test("configBadHybrid", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint.readConfig(
readConfigAsync(
"./test/config/config-badcontent.txt",
// @ts-ignore
[ JSON.parse, require("toml").parse, require("js-yaml").load ],
@ -262,14 +264,14 @@ test("configBadHybrid", (t) => new Promise((resolve) => {
test("configSingleSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync("./test/config/config-child.json");
const actual = readConfigSync("./test/config/config-child.json");
const expected = require("./config/config-child.json");
t.deepEqual(actual, expected, "Config object not correct.");
});
test("configAbsoluteSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync(
const actual = readConfigSync(
path.join(__dirname(import.meta), "config", "config-child.json"));
const expected = require("./config/config-child.json");
t.deepEqual(actual, expected, "Config object not correct.");
@ -278,7 +280,7 @@ test("configAbsoluteSync", (t) => {
if (sameFileSystem) {
test("configTildeSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync(
const actual = readConfigSync(
`~/${path.relative(os.homedir(), "./test/config/config-child.json")}`);
const expected = require("./config/config-child.json");
t.deepEqual(actual, expected, "Config object not correct.");
@ -288,7 +290,7 @@ if (sameFileSystem) {
test("configMultipleSync", (t) => {
t.plan(1);
const actual =
markdownlint.readConfigSync("./test/config/config-grandparent.json");
readConfigSync("./test/config/config-grandparent.json");
const expected = {
...require("./config/config-child.json"),
...require("./config/config-parent.json"),
@ -303,7 +305,7 @@ test("configBadFileSync", (t) => {
t.plan(1);
t.throws(
function badFileCall() {
markdownlint.readConfigSync("./test/config/config-badfile.json");
readConfigSync("./test/config/config-badfile.json");
},
{
"message": /ENOENT/
@ -316,7 +318,7 @@ test("configBadChildFileSync", (t) => {
t.plan(1);
t.throws(
function badChildFileCall() {
markdownlint.readConfigSync("./test/config/config-badchildfile.json");
readConfigSync("./test/config/config-badchildfile.json");
},
{
"message": /ENOENT/
@ -329,7 +331,7 @@ test("configBadJsonSync", (t) => {
t.plan(1);
t.throws(
function badJsonCall() {
markdownlint.readConfigSync("./test/config/config-badjson.json");
readConfigSync("./test/config/config-badjson.json");
},
{
"message":
@ -343,7 +345,7 @@ test("configBadChildJsonSync", (t) => {
t.plan(1);
t.throws(
function badChildJsonCall() {
markdownlint.readConfigSync("./test/config/config-badchildjson.json");
readConfigSync("./test/config/config-badchildjson.json");
},
{
"message":
@ -355,7 +357,7 @@ test("configBadChildJsonSync", (t) => {
test("configSingleYamlSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync(
const actual = readConfigSync(
// @ts-ignore
"./test/config/config-child.yaml", [ require("js-yaml").load ]);
const expected = require("./config/config-child.json");
@ -364,7 +366,7 @@ test("configSingleYamlSync", (t) => {
test("configMultipleYamlSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync(
const actual = readConfigSync(
// @ts-ignore
"./test/config/config-grandparent.yaml", [ require("js-yaml").load ]);
const expected = {
@ -379,7 +381,7 @@ test("configMultipleYamlSync", (t) => {
test("configMultipleHybridSync", (t) => {
t.plan(1);
const actual = markdownlint.readConfigSync(
const actual = readConfigSync(
"./test/config/config-grandparent-hybrid.yaml",
// @ts-ignore
[ JSON.parse, require("toml").parse, require("js-yaml").load ]);
@ -420,7 +422,7 @@ test("configCustomFileSystemSync", (t) => {
return t.fail(p);
}
};
const actual = markdownlint.readConfigSync(file, undefined, fsApi);
const actual = readConfigSync(file, undefined, fsApi);
const expected = {
...extendedContent,
...fileContent
@ -434,7 +436,7 @@ test("configBadHybridSync", (t) => {
t.plan(1);
t.throws(
function badHybridCall() {
markdownlint.readConfigSync(
readConfigSync(
"./test/config/config-badcontent.txt",
// @ts-ignore
[ JSON.parse, require("toml").parse, require("js-yaml").load ]);
@ -448,7 +450,7 @@ test("configBadHybridSync", (t) => {
test("configSinglePromise", (t) => new Promise((resolve) => {
t.plan(1);
markdownlint.promises.readConfig("./test/config/config-child.json")
readConfigPromise("./test/config/config-child.json")
.then((actual) => {
const expected = require("./config/config-child.json");
t.deepEqual(actual, expected, "Config object not correct.");
@ -487,7 +489,7 @@ test("configCustomFileSystemPromise", (t) => new Promise((resolve) => {
}
}
};
markdownlint.promises.readConfig(file, undefined, fsApi)
readConfigPromise(file, undefined, fsApi)
.then((actual) => {
const expected = {
...extendedContent,
@ -502,7 +504,7 @@ test("configCustomFileSystemPromise", (t) => new Promise((resolve) => {
test("configBadFilePromise", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.promises.readConfig("./test/config/config-badfile.json")
readConfigPromise("./test/config/config-badfile.json")
.then(
null,
(error) => {
@ -516,7 +518,7 @@ test("configBadFilePromise", (t) => new Promise((resolve) => {
test("extendSinglePromise", (t) => new Promise((resolve) => {
t.plan(1);
const expected = require("./config/config-child.json");
markdownlint.promises.extendConfig(
extendConfig(
expected,
"./test/config/config-child.json",
undefined,
@ -530,7 +532,7 @@ test("extendSinglePromise", (t) => new Promise((resolve) => {
test("extendBadPromise", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint.promises.extendConfig(
extendConfig(
{
"extends": "missing.json"
},
@ -576,7 +578,7 @@ test("extendCustomFileSystemPromise", (t) => new Promise((resolve) => {
}
}
};
markdownlint.promises.extendConfig(fileContent, file, undefined, fsApi)
extendConfig(fileContent, file, undefined, fsApi)
.then((actual) => {
t.truthy(fileContent.extends);
const expected = {

View file

@ -4,7 +4,9 @@ import fs from "node:fs/promises";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
import customRules from "./rules/rules.cjs";
import { newLineRe } from "../helpers/helpers.cjs";
import { __filename, importWithTypeJson } from "./esm-helpers.mjs";
@ -14,13 +16,13 @@ const { homepage, version } = packageJson;
test("customRulesV0", (t) => new Promise((resolve) => {
t.plan(4);
const customRulesMd = "./test/custom-rules.md";
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.all,
"files": [ customRulesMd ],
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult[customRulesMd] = {
@ -86,13 +88,13 @@ test("customRulesV0", (t) => new Promise((resolve) => {
test("customRulesV1", (t) => new Promise((resolve) => {
t.plan(3);
const customRulesMd = "./test/custom-rules.md";
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.all,
"files": [ customRulesMd ],
"resultVersion": 1
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult[customRulesMd] = [
@ -217,13 +219,13 @@ test("customRulesV1", (t) => new Promise((resolve) => {
test("customRulesV2", (t) => new Promise((resolve) => {
t.plan(3);
const customRulesMd = "./test/custom-rules.md";
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.all,
"files": [ customRulesMd ],
"resultVersion": 2
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult[customRulesMd] = [
@ -338,7 +340,7 @@ test("customRulesV2", (t) => new Promise((resolve) => {
test("customRulesConfig", (t) => new Promise((resolve) => {
t.plan(2);
const customRulesMd = "./test/custom-rules.md";
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.all,
"files": [ customRulesMd ],
@ -351,7 +353,7 @@ test("customRulesConfig", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult[customRulesMd] = {
@ -368,7 +370,7 @@ test("customRulesConfig", (t) => new Promise((resolve) => {
test("customRulesNpmPackage", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
require("./rules/npm"),
@ -379,7 +381,7 @@ test("customRulesNpmPackage", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult.string = {
@ -431,13 +433,13 @@ test("customRulesBadProperty", (t) => {
for (const propertyValue of propertyValues) {
const badRule = { ...customRules.firstLine };
badRule[propertyName] = propertyValue;
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [ badRule ]
};
t.throws(
function badRuleCall() {
markdownlint.sync(options);
lintSync(options);
},
{
"message":
@ -451,8 +453,8 @@ test("customRulesBadProperty", (t) => {
test("customRulesUsedNameName", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name", "NO-missing-SPACE-atx" ],
@ -477,8 +479,8 @@ test("customRulesUsedNameName", (t) => new Promise((resolve) => {
test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name", "HtMl" ],
@ -502,8 +504,8 @@ test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
test("customRulesUsedTagName", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "filler" ],
@ -535,7 +537,7 @@ test("customRulesUsedTagName", (t) => new Promise((resolve) => {
test("customRulesParserUndefined", (t) => {
t.plan(5);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
// @ts-ignore
@ -557,12 +559,12 @@ test("customRulesParserUndefined", (t) => {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesParserNone", (t) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -581,12 +583,12 @@ test("customRulesParserNone", (t) => {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesParserMarkdownIt", (t) => {
t.plan(5);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -608,12 +610,12 @@ test("customRulesParserMarkdownIt", (t) => {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesParserMicromark", (t) => {
t.plan(5);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -635,12 +637,12 @@ test("customRulesParserMicromark", (t) => {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesMarkdownItParamsTokensSameObject", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
// @ts-ignore
@ -659,12 +661,12 @@ test("customRulesMarkdownItParamsTokensSameObject", (t) => {
"string": "# Heading\n"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesMarkdownItTokensSnapshot", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -684,13 +686,13 @@ test("customRulesMarkdownItTokensSnapshot", (t) => {
.readFile("./test/every-markdown-syntax.md", "utf8")
.then((content) => {
options.strings = { "content": content.split(newLineRe).join("\n") };
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
});
test("customRulesMicromarkTokensSnapshot", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -710,13 +712,13 @@ test("customRulesMicromarkTokensSnapshot", (t) => {
.readFile("./test/every-markdown-syntax.md", "utf8")
.then((content) => {
options.strings = { "content": content.split(newLineRe).join("\n") };
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
});
test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -741,7 +743,7 @@ test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
"string": "# Heading\n"
}
};
markdownlint(options, (err, actualResult) => {
lintAsync(options, (err, actualResult) => {
t.falsy(err);
const expectedResult = {
"string": [
@ -765,8 +767,8 @@ test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
test("customRulesThrowForFile", (t) => new Promise((resolve) => {
t.plan(4);
const exceptionMessage = "Test exception message";
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -795,8 +797,8 @@ test("customRulesThrowForFileSync", (t) => {
const exceptionMessage = "Test exception message";
t.throws(
function customRuleThrowsCall() {
markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -821,8 +823,8 @@ test("customRulesThrowForFileSync", (t) => {
test("customRulesThrowForString", (t) => new Promise((resolve) => {
t.plan(4);
const exceptionMessage = "Test exception message";
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -853,8 +855,8 @@ test("customRulesThrowForStringSync", (t) => {
const exceptionMessage = "Test exception message";
t.throws(
function customRuleThrowsCall() {
markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -880,8 +882,8 @@ test("customRulesThrowForStringSync", (t) => {
test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -914,7 +916,7 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
test("customRulesOnErrorNullSync", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -934,7 +936,7 @@ test("customRulesOnErrorNullSync", (t) => {
};
t.throws(
function nullErrorCall() {
markdownlint.sync(options);
lintSync(options);
},
{
"message": "Value of 'lineNumber' passed to onError by 'NAME' is incorrect for 'string'."
@ -1005,7 +1007,7 @@ test("customRulesOnErrorBad", (t) => {
badObject[propertyName] = propertyValue;
propertyNames = propertyName;
}
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1024,7 +1026,7 @@ test("customRulesOnErrorBad", (t) => {
};
t.throws(
function badErrorCall() {
markdownlint.sync(options);
lintSync(options);
},
{
"message":
@ -1077,7 +1079,7 @@ test("customRulesOnErrorInvalid", (t) => {
badObject[propertyName] = propertyValue;
propertyNames = propertyName;
}
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1096,7 +1098,7 @@ test("customRulesOnErrorInvalid", (t) => {
};
t.throws(
function invalidErrorCall() {
markdownlint.sync(options);
lintSync(options);
},
{
"message":
@ -1152,7 +1154,7 @@ test("customRulesOnErrorValid", (t) => {
} else {
goodObject[propertyName] = propertyValue;
}
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1169,7 +1171,7 @@ test("customRulesOnErrorValid", (t) => {
"string": "Text\ntext"
}
};
markdownlint.sync(options);
lintSync(options);
t.truthy(true);
}
}
@ -1177,7 +1179,7 @@ test("customRulesOnErrorValid", (t) => {
test("customRulesOnErrorLazy", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1199,7 +1201,7 @@ test("customRulesOnErrorLazy", (t) => new Promise((resolve) => {
"string": "# Heading\n"
}
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"string": [
@ -1234,7 +1236,7 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
"insertText": "text"
}
};
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1259,7 +1261,7 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
"string": "# Heading\n"
}
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"string": [
@ -1286,8 +1288,8 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
lintAsync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1329,8 +1331,8 @@ test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
test("customRulesOnErrorInvalidHandledSync", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1370,7 +1372,7 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
test("customRulesVersion", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1385,7 +1387,7 @@ test("customRulesVersion", (t) => new Promise((resolve) => {
],
"files": "doc/CustomRules.md"
};
markdownlint(options, function callback(err) {
lintAsync(options, function callback(err) {
t.falsy(err);
resolve();
});
@ -1393,7 +1395,7 @@ test("customRulesVersion", (t) => new Promise((resolve) => {
test("customRulesFileName", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1408,7 +1410,7 @@ test("customRulesFileName", (t) => new Promise((resolve) => {
],
"files": "doc/CustomRules.md"
};
markdownlint(options, function callback(err) {
lintAsync(options, function callback(err) {
t.falsy(err);
resolve();
});
@ -1416,7 +1418,7 @@ test("customRulesFileName", (t) => new Promise((resolve) => {
test("customRulesStringName", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1433,7 +1435,7 @@ test("customRulesStringName", (t) => new Promise((resolve) => {
"string": "# Heading"
}
};
markdownlint(options, function callback(err) {
lintAsync(options, function callback(err) {
t.falsy(err);
resolve();
});
@ -1441,8 +1443,8 @@ test("customRulesStringName", (t) => new Promise((resolve) => {
test("customRulesOnErrorInformationNotRuleNotError", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1465,8 +1467,8 @@ test("customRulesOnErrorInformationNotRuleNotError", (t) => {
test("customRulesOnErrorInformationRuleNotError", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1494,8 +1496,8 @@ test("customRulesOnErrorInformationRuleNotError", (t) => {
test("customRulesOnErrorInformationNotRuleError", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1523,8 +1525,8 @@ test("customRulesOnErrorInformationNotRuleError", (t) => {
test("customRulesOnErrorInformationRuleError", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1553,8 +1555,8 @@ test("customRulesOnErrorInformationRuleError", (t) => {
test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1583,8 +1585,8 @@ test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
test("customRulesOnErrorInformationRuleErrorMultiple", (t) => {
t.plan(6);
const actualResult = markdownlint.sync({
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
const actualResult = lintSync({
/** @type {import("markdownlint").Rule[]} */
"customRules": [
{
"names": [ "name" ],
@ -1645,7 +1647,7 @@ test("customRulesOnErrorInformationRuleErrorMultiple", (t) => {
test("customRulesDoc", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"files": "./doc/CustomRules.md",
"config": {
"MD013": { "line_length": 200 }
@ -1660,12 +1662,12 @@ test("customRulesDoc", (t) => new Promise((resolve) => {
test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
t.plan(2);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.lintJavaScript,
"files": "test/lint-javascript.md"
};
markdownlint(options, (err, actual) => {
lintAsync(options, (err, actual) => {
t.falsy(err);
const expected = {
"test/lint-javascript.md": [
@ -1688,12 +1690,12 @@ test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
test("customRulesValidateJson", (t) => new Promise((resolve) => {
t.plan(3);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": customRules.validateJson,
"files": "test/validate-json.md"
};
markdownlint(options, (err, actual) => {
lintAsync(options, (err, actual) => {
t.falsy(err);
const expected = {
"test/validate-json.md": [
@ -1721,7 +1723,7 @@ test("customRulesValidateJson", (t) => new Promise((resolve) => {
test("customRulesAsyncThrowsInSyncContext", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1738,7 +1740,7 @@ test("customRulesAsyncThrowsInSyncContext", (t) => {
}
};
t.throws(
() => markdownlint.sync(options),
() => lintSync(options),
{
"message": "Custom rule name1/name2 at index 0 is asynchronous and " +
"can not be used in a synchronous context."
@ -1765,7 +1767,7 @@ test("customRulesParamsAreFrozen", (t) => {
}
}
};
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1792,14 +1794,14 @@ test("customRulesParamsAreFrozen", (t) => {
],
"files": [ "README.md" ]
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesParamsAreStable", (t) => {
t.plan(4);
const config1 = { "value1": 10 };
const config2 = { "value2": 20 };
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"config": {
"MD010": true,
@ -1860,12 +1862,12 @@ test("customRulesParamsAreStable", (t) => {
"string": "# Heading"
}
};
return markdownlint.promises.markdownlint(options).then(() => null);
return lintPromise(options).then(() => null);
});
test("customRulesAsyncReadFiles", (t) => {
t.plan(3);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1947,13 +1949,13 @@ test("customRulesAsyncReadFiles", (t) => {
}
]
};
return markdownlint.promises.markdownlint(options)
return lintPromise(options)
.then((actual) => t.deepEqual(actual, expected, "Unexpected issues."));
});
test("customRulesAsyncIgnoresSyncReturn", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -2011,7 +2013,7 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
}
]
};
return markdownlint.promises.markdownlint(options)
return lintPromise(options)
.then((actual) => t.deepEqual(actual, expected, "Unexpected issues."));
});
@ -2044,7 +2046,7 @@ for (const flavor of [
]
]) {
const [ name, func ] = flavor;
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
/** @type {import("markdownlint").Rule[]} */
const customRule = [
{
"names": [ "name" ],
@ -2074,7 +2076,7 @@ for (const flavor of [
test(`${name}${subname}UnhandledAsync`, (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
lintAsync({
// @ts-ignore
"customRules": customRule,
// @ts-ignore
@ -2093,7 +2095,7 @@ for (const flavor of [
test(`${name}${subname}HandledAsync`, (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
// @ts-ignore
"customRules": customRule,
// @ts-ignore
@ -2111,7 +2113,7 @@ for (const flavor of [
test(`${name}${subname}UnhandledSync`, (t) => {
t.plan(1);
t.throws(
() => markdownlint.sync({
() => lintSync({
// @ts-ignore
"customRules": customRule,
// @ts-ignore
@ -2128,7 +2130,7 @@ for (const flavor of [
test(`${name}${subname}HandledSync`, (t) => {
t.plan(1);
const actualResult = markdownlint.sync({
const actualResult = lintSync({
// @ts-ignore
"customRules": customRule,
// @ts-ignore
@ -2181,7 +2183,7 @@ for (const flavor of [
]
]) {
const [ name, func ] = flavor;
/** @type {import("../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
const customRule = {
"names": [ "name" ],
"description": "description",
@ -2196,7 +2198,7 @@ for (const flavor of [
test(`${name}${subname}Unhandled`, (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
lintAsync({
// @ts-ignore
"customRules": [ customRule ],
// @ts-ignore
@ -2215,7 +2217,7 @@ for (const flavor of [
test(`${name}${subname}Handled`, (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
// @ts-ignore
"customRules": [ customRule ],
// @ts-ignore

View file

@ -2,12 +2,12 @@
import test from "ava";
import { globby } from "globby";
import markdownlint from "../lib/markdownlint.mjs";
import { lint } from "markdownlint/promise";
// Parses all Markdown files in all package dependencies
test("parseAllFiles", async(t) => {
t.plan(1);
const files = await globby("**/*.{md,markdown}");
await markdownlint.promises.markdownlint({ files });
await lint({ files });
t.pass();
});

View file

@ -3,7 +3,7 @@
import fs from "node:fs";
import path from "node:path";
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { lint } from "markdownlint/sync";
// Simulates typing each test file to validate handling of partial input
const files = fs
@ -18,7 +18,7 @@ for (const file of files) {
}
test.serial(`type ${file}`, (t) => {
t.plan(1);
markdownlint.sync({
lint({
// @ts-ignore
strings,
"resultVersion": 0

View file

@ -1,7 +1,7 @@
// @ts-check
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { applyFix, applyFixes } from "markdownlint";
test("applyFix", (t) => {
t.plan(4);
@ -46,7 +46,7 @@ test("applyFix", (t) => {
for (const testCase of testCases) {
const [ line, fixInfo, lineEnding, expected ] = testCase;
// @ts-ignore
const actual = markdownlint.applyFix(line, fixInfo, lineEnding);
const actual = applyFix(line, fixInfo, lineEnding);
t.is(actual, String(expected), "Incorrect fix applied.");
}
});
@ -524,7 +524,7 @@ test("applyFixes", (t) => {
for (const testCase of testCases) {
const [ input, errors, expected ] = testCase;
// @ts-ignore
const actual = markdownlint.applyFixes(input, errors);
const actual = applyFixes(input, errors);
t.is(actual, String(expected), "Incorrect fix applied.");
}
});

View file

@ -6,8 +6,7 @@ import test from "ava";
import { characterEntities } from "character-entities";
import { gemoji } from "gemoji";
import helpers from "../helpers/helpers.cjs";
import libMarkdownlint from "../lib/markdownlint.mjs";
const { markdownlint } = libMarkdownlint.promises;
import { lint } from "markdownlint/promise";
import { forEachInlineCodeSpan } from "../lib/markdownit.cjs";
import { getReferenceLinkImageData } from "../lib/cache.mjs";
@ -387,7 +386,7 @@ test("expandTildePath", (t) => {
test("getReferenceLinkImageData().shortcuts", (t) => {
t.plan(1);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -415,7 +414,7 @@ Empty bracket pair: [text4[]]
`
}
};
return markdownlint(options).then(() => null);
return lint(options).then(() => null);
});
test("endOfLineHtmlEntityRe", (t) => {

View file

@ -3,15 +3,14 @@
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import { availableParallelism } from "node:os";
import { Worker } from "node:worker_threads";
import { lint } from "markdownlint/sync";
import { __filename } from "./esm-helpers.mjs";
import markdownlint from "../lib/markdownlint.mjs";
const markdownlintSync = markdownlint.sync;
/**
* Lint specified Markdown files (using multiple threads).
*
* @param {import("../lib/markdownlint.mjs").Options} options Configuration options.
* @returns {Promise<import("../lib/markdownlint.mjs").LintResults>} Results object.
* @param {import("markdownlint").Options} options Configuration options.
* @returns {Promise<import("markdownlint").LintResults>} Results object.
*/
export function markdownlintParallel(options) {
const workerCount = availableParallelism();
@ -30,7 +29,7 @@ export function markdownlintParallel(options) {
}));
}
return Promise.all(promises).then((workerResults) => {
const combinedResults = markdownlintSync(null);
const combinedResults = lint(null);
for (const workerResult of workerResults) {
// eslint-disable-next-line guard-for-in
for (const result in workerResult) {

View file

@ -5,8 +5,7 @@ const { join } = path.posix;
import { globby } from "globby";
import jsoncParser from "jsonc-parser";
import jsYaml from "js-yaml";
import library from "../lib/markdownlint.mjs";
const { markdownlint, readConfig } = library.promises;
import { lint, readConfig } from "markdownlint/promise";
import { markdownlintParallel } from "./markdownlint-test-parallel.mjs";
/**
@ -39,7 +38,7 @@ export function lintTestRepo(t, globPatterns, configPath, parallel) {
v
])
);
return (parallel ? markdownlintParallel : markdownlint)({
return (parallel ? markdownlintParallel : lint)({
files,
config
}).then((results) => {

View file

@ -1,7 +1,8 @@
// @ts-check
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintSync } from "markdownlint/sync";
import { importWithTypeJson } from "./esm-helpers.mjs";
const packageJson = await importWithTypeJson(import.meta, "../package.json");
const { homepage, version } = packageJson;
@ -13,7 +14,7 @@ test("resultObjectToStringNotEnumerable", (t) => new Promise((resolve) => {
"string": "# Heading"
}
};
markdownlint(options, function callback(err, result) {
lintAsync(options, function callback(err, result) {
t.falsy(err);
// eslint-disable-next-line guard-for-in
for (const property in result) {
@ -36,7 +37,7 @@ test("resultFormattingV0", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -95,7 +96,7 @@ test("resultFormattingSyncV0", (t) => {
"noInlineConfig": true,
"resultVersion": 0
};
const actualResult = markdownlint.sync(options);
const actualResult = lintSync(options);
const expectedResult = {
"./test/atx_heading_spacing.md": {
"MD018": [ 1 ],
@ -154,7 +155,7 @@ test("resultFormattingV1", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 1
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"truncate": [
@ -258,7 +259,7 @@ test("resultFormattingV2", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 2
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"truncate": [
@ -352,7 +353,7 @@ test("resultFormattingV3", (t) => new Promise((resolve) => {
},
"resultVersion": 3
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": [
@ -467,7 +468,7 @@ test("onePerLineResultVersion0", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": {
@ -488,7 +489,7 @@ test("onePerLineResultVersion1", (t) => new Promise((resolve) => {
},
"resultVersion": 1
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": [
@ -519,7 +520,7 @@ test("onePerLineResultVersion2", (t) => new Promise((resolve) => {
},
"resultVersion": 2
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": [
@ -548,7 +549,7 @@ test("manyPerLineResultVersion3", (t) => new Promise((resolve) => {
},
"resultVersion": 3
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": [
@ -597,7 +598,7 @@ test("frontMatterResultVersion3", (t) => new Promise((resolve) => {
},
"resultVersion": 3
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"input": [

View file

@ -3,9 +3,8 @@
import fs from "node:fs/promises";
import path from "node:path";
import test from "ava";
import libMarkdownlint from "../lib/markdownlint.mjs";
const { applyFixes, promises } = libMarkdownlint;
const { markdownlint } = promises;
import { lint } from "markdownlint/promise";
import { applyFixes } from "markdownlint";
import helpers from "../helpers/helpers.cjs";
import { fixableRuleNames } from "../lib/constants.mjs";
@ -22,7 +21,7 @@ function createTestForFile(file) {
// Read and lint Markdown test file
Promise.all([
fs.readFile(file, "utf8"),
markdownlint({
lint({
"files": [ file ]
})
])
@ -89,7 +88,7 @@ function createTestForFile(file) {
fixed
});
// Identify missing fixes
return markdownlint({
return lint({
"strings": {
"input": fixed
}

View file

@ -1,10 +1,9 @@
// @ts-check
import { parentPort, workerData } from "node:worker_threads";
import library from "../lib/markdownlint.mjs";
const { markdownlint } = library.promises;
import { lint } from "markdownlint/promise";
const lintResults = await markdownlint(workerData);
const lintResults = await lint(workerData);
// @ts-ignore
parentPort
// eslint-disable-next-line unicorn/require-post-message-target-origin

View file

@ -13,7 +13,10 @@ import pluginInline from "markdown-it-for-inline";
import pluginSub from "markdown-it-sub";
import pluginSup from "markdown-it-sup";
import test from "ava";
import markdownlint from "../lib/markdownlint.mjs";
import { getVersion } from "markdownlint";
import { lint as lintAsync } from "markdownlint/async";
import { lint as lintPromise } from "markdownlint/promise";
import { lint as lintSync } from "markdownlint/sync";
import * as constants from "../lib/constants.mjs";
import rules from "../lib/rules.mjs";
import customRules from "./rules/rules.cjs";
@ -36,7 +39,7 @@ test("simpleAsync", (t) => new Promise((resolve) => {
};
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character";
markdownlint(options, (err, actual) => {
lintAsync(options, (err, actual) => {
t.falsy(err);
// @ts-ignore
t.is(actual.toString(), expected, "Unexpected results.");
@ -53,7 +56,7 @@ test("simpleSync", (t) => {
};
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character";
const actual = markdownlint.sync(options).toString();
const actual = lintSync(options).toString();
t.is(actual, expected, "Unexpected results.");
});
@ -66,7 +69,7 @@ test("simplePromise", (t) => {
};
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character";
return markdownlint.promises.markdownlint(options).then((actual) => {
return lintPromise(options).then((actual) => {
t.is(actual.toString(), expected, "Unexpected results.");
});
});
@ -90,7 +93,7 @@ test("projectFiles", (t) => {
"config": require("../.markdownlint.json")
};
// @ts-ignore
return markdownlint.promises.markdownlint(options).then((actual) => {
return lintPromise(options).then((actual) => {
const expected = {};
for (const file of files) {
expected[file] = [];
@ -118,7 +121,7 @@ test("projectFilesExtendedAscii", (t) => {
"customRules": [ require("markdownlint-rule-extended-ascii") ]
};
// @ts-ignore
return markdownlint.promises.markdownlint(options).then((actual) => {
return lintPromise(options).then((actual) => {
const expected = {};
for (const file of files) {
expected[file] = [];
@ -142,7 +145,7 @@ test("stringInputLineEndings", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"cr": { "MD018": [ 3 ] },
@ -168,7 +171,7 @@ test("inputOnlyNewline", (t) => new Promise((resolve) => {
"default": false
}
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"cr": [],
@ -193,7 +196,7 @@ test("defaultTrue", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -224,7 +227,7 @@ test("defaultFalse", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {},
@ -247,7 +250,7 @@ test("defaultUndefined", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -279,7 +282,7 @@ test("disableRules", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -308,7 +311,7 @@ test("enableRules", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -340,7 +343,7 @@ test("enableRulesMixedCase", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -371,7 +374,7 @@ test("disableTag", (t) => new Promise((resolve) => {
"noInlineConfig": true,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -401,7 +404,7 @@ test("enableTag", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -430,7 +433,7 @@ test("enableTagMixedCase", (t) => new Promise((resolve) => {
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
lintAsync(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {
"./test/atx_heading_spacing.md": {
@ -464,7 +467,7 @@ test("styleAll", async(t) => {
"noInlineConfig": true,
"resultVersion": 0
};
const actualResult = await markdownlint.promises.markdownlint(options);
const actualResult = await lintPromise(options);
const expectedResult = {
"./test/break-all-the-rules.md": {
"MD001": [ 3 ],
@ -527,7 +530,7 @@ test("styleRelaxed", async(t) => {
"noInlineConfig": true,
"resultVersion": 0
};
const actualResult = await markdownlint.promises.markdownlint(options);
const actualResult = await lintPromise(options);
const expectedResult = {
"./test/break-all-the-rules.md": {
"MD001": [ 3 ],
@ -569,7 +572,7 @@ test("styleRelaxed", async(t) => {
test("nullFrontMatter", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
"content": "---\n\t\n---\n# Heading\n"
},
@ -592,7 +595,7 @@ test("nullFrontMatter", (t) => new Promise((resolve) => {
test("customFrontMatter", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
"content": "<head>\n\t\n</head>\n# Heading\n"
},
@ -613,7 +616,7 @@ test("customFrontMatter", (t) => new Promise((resolve) => {
test("noInlineConfig", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
"content": [
"# Heading",
@ -646,7 +649,7 @@ test("noInlineConfig", (t) => new Promise((resolve) => {
test("readmeHeadings", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"files": "README.md",
"noInlineConfig": true,
"config": {
@ -713,7 +716,7 @@ test("filesArrayNotModified", (t) => new Promise((resolve) => {
"./test/first_heading_bad_atx.md"
];
const expectedFiles = [ ...files ];
markdownlint({ "files": files }, function callback(err) {
lintAsync({ "files": files }, function callback(err) {
t.falsy(err);
t.deepEqual(files, expectedFiles, "Files modified.");
resolve();
@ -722,7 +725,7 @@ test("filesArrayNotModified", (t) => new Promise((resolve) => {
test("filesArrayAsString", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"files": "README.md",
"noInlineConfig": true,
"config": {
@ -739,7 +742,7 @@ test("filesArrayAsString", (t) => new Promise((resolve) => {
test("missingOptions", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint(null, function callback(err, result) {
lintAsync(null, function callback(err, result) {
t.falsy(err);
t.deepEqual(
result,
@ -752,7 +755,7 @@ test("missingOptions", (t) => new Promise((resolve) => {
test("missingFilesAndStrings", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({}, function callback(err, result) {
lintAsync({}, function callback(err, result) {
t.falsy(err);
t.truthy(result, "Did not get result for missing files/strings.");
resolve();
@ -762,12 +765,12 @@ test("missingFilesAndStrings", (t) => new Promise((resolve) => {
test("missingCallback", (t) => {
t.plan(0);
// @ts-ignore
markdownlint();
lintAsync();
});
test("badFile", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
lintAsync({
"files": [ "./badFile" ]
}, function callback(err, result) {
t.truthy(err, "Did not get an error for bad file.");
@ -783,7 +786,7 @@ test("badFileSync", (t) => {
t.plan(1);
t.throws(
function badFileCall() {
markdownlint.sync({
lintSync({
"files": [ "./badFile" ]
});
},
@ -796,7 +799,7 @@ test("badFileSync", (t) => {
test("badFilePromise", (t) => new Promise((resolve) => {
t.plan(3);
markdownlint.promises.markdownlint({
lintPromise({
"files": [ "./badFile" ]
}).then(
null,
@ -811,7 +814,7 @@ test("badFilePromise", (t) => new Promise((resolve) => {
test("missingStringValue", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
// @ts-ignore
"undefined": undefined,
@ -840,7 +843,7 @@ test("customFileSystemSync", (t) => {
return "# Heading";
}
};
const result = markdownlint.sync({
const result = lintSync({
"files": file,
"fs": fsApi
});
@ -856,7 +859,7 @@ test("customFileSystemAsync", (t) => new Promise((resolve) => {
cb(null, "# Heading");
}
};
markdownlint({
lintAsync({
"files": file,
"fs": fsApi
}, function callback(err, result) {
@ -1101,7 +1104,7 @@ test("someCustomRulesHaveValidUrl", (t) => {
test("markdownItPluginsSingle", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
lintAsync({
"strings": {
"string": "# Heading\n\nText\n"
},
@ -1120,7 +1123,7 @@ test("markdownItPluginsSingle", (t) => new Promise((resolve) => {
test("markdownItPluginsMultiple", (t) => new Promise((resolve) => {
t.plan(4);
markdownlint({
lintAsync({
"strings": {
"string": "# Heading\n\nText H~2~0 text 29^th^ text\n"
},
@ -1142,7 +1145,7 @@ test("markdownItPluginsMultiple", (t) => new Promise((resolve) => {
test("markdownItPluginsNoMarkdownIt", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
"string": "# Heading\n\nText\n"
},
@ -1159,7 +1162,7 @@ test("markdownItPluginsNoMarkdownIt", (t) => new Promise((resolve) => {
test("markdownItPluginsUnusedUncalled", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"config": {
"default": false
},
@ -1181,7 +1184,7 @@ test("markdownItPluginsUnusedUncalled", (t) => new Promise((resolve) => {
test("Pandoc footnote", (t) => new Promise((resolve) => {
t.plan(2);
markdownlint({
lintAsync({
"strings": {
"string":
`# Heading
@ -1206,7 +1209,7 @@ Text with: [^footnote]
test("token-map-spans", (t) => {
t.plan(38);
/** @type {import("../lib/markdownlint.mjs").Options} */
/** @type {import("markdownlint").Options} */
const options = {
"customRules": [
{
@ -1239,7 +1242,7 @@ test("token-map-spans", (t) => {
],
"files": [ "./test/token-map-spans.md" ]
};
markdownlint.sync(options);
lintSync(options);
});
test("configParsersInvalid", async(t) => {
@ -1258,7 +1261,7 @@ test("configParsersInvalid", async(t) => {
};
const expected = "content: 1: MD041/first-line-heading/first-line-h1 " +
"First line in a file should be a top-level heading [Context: \"Text\"]";
const actual = await markdownlint.promises.markdownlint(options);
const actual = await lintPromise(options);
t.is(actual.toString(), expected, "Unexpected results.");
});
@ -1278,7 +1281,7 @@ test("configParsersJSON", async(t) => {
].join("\n")
}
};
const actual = await markdownlint.promises.markdownlint(options);
const actual = await lintPromise(options);
t.is(actual.toString(), "", "Unexpected results.");
});
@ -1300,7 +1303,7 @@ test("configParsersJSONC", async(t) => {
},
"configParsers": [ jsoncParser.parse ]
};
const actual = await markdownlint.promises.markdownlint(options);
const actual = await lintPromise(options);
t.is(actual.toString(), "", "Unexpected results.");
});
@ -1321,7 +1324,7 @@ test("configParsersYAML", async(t) => {
"configParsers": [ jsYaml.load ]
};
// @ts-ignore
const actual = await markdownlint.promises.markdownlint(options);
const actual = await lintPromise(options);
t.is(actual.toString(), "", "Unexpected results.");
});
@ -1344,13 +1347,13 @@ test("configParsersTOML", async(t) => {
require("toml").parse
]
};
const actual = await markdownlint.promises.markdownlint(options);
const actual = await lintPromise(options);
t.is(actual.toString(), "", "Unexpected results.");
});
test("getVersion", (t) => {
t.plan(1);
const actual = markdownlint.getVersion();
const actual = getVersion();
const expected = packageJson.version;
t.is(actual, expected, "Version string not correct.");
});
@ -1364,7 +1367,10 @@ test("constants", (t) => {
});
const exportMappings = new Map([
[ ".", "../lib/markdownlint.mjs" ],
[ ".", "../lib/exports.mjs" ],
[ "./async", "../lib/exports-async.mjs" ],
[ "./promise", "../lib/exports-promise.mjs" ],
[ "./sync", "../lib/exports-sync.mjs" ],
[ "./helpers", "../helpers/helpers.cjs" ],
[ "./style/all", "../style/all.json" ],
[ "./style/cirosantilli", "../style/cirosantilli.json" ],

View file

@ -1,6 +1,5 @@
import { readFile } from "node:fs/promises";
import library from "../lib/markdownlint.mjs";
const markdownlint = library.promises.markdownlint;
import { lint } from "markdownlint/promise";
const strings = {
"CHANGELOG": await readFile("CHANGELOG.md", "utf8"),
@ -14,7 +13,7 @@ const strings = {
const start = new Date();
for (let i = 0; i < 250; i++) {
// eslint-disable-next-line no-await-in-loop
await markdownlint({ strings });
await lint({ strings });
}
const end = new Date();
// eslint-disable-next-line no-console

View file

@ -2,7 +2,7 @@
"use strict";
/** @type {import("../../lib/markdownlint.mjs").Rule[]} */
/** @type {import("markdownlint").Rule[]} */
module.exports = [
// micromark parser (preferred)

View file

@ -2,7 +2,7 @@
"use strict";
/** @type {import("../../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines",

View file

@ -2,7 +2,7 @@
"use strict";
/** @type {import("../../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "first-line" ],
"description": "Rule that reports an error for the first line",

View file

@ -2,7 +2,7 @@
"use strict";
/** @type {import("../../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
"description": "Rule that reports an error for lines with the letters 'EX'",

View file

@ -7,7 +7,7 @@ const eslint = require("eslint");
const linter = new eslint.Linter();
const languageJavaScript = /js|javascript/i;
/** @type {import("../../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "lint-javascript" ],
"description": "Rule that lints JavaScript code",

View file

@ -4,7 +4,7 @@
const { parse, printParseErrorCode } = require("jsonc-parser");
/** @type {import("../../lib/markdownlint.mjs").Rule} */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "validate-json" ],
"description": "Rule that validates JSON code",