mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update to use named exports via / /async /promise /sync, simplify references via self-referencing, refine examples.
This commit is contained in:
parent
e41f034bef
commit
8da43dd246
96 changed files with 635 additions and 548 deletions
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
||||
// Displays the result object directly
|
||||
markdownlint(options, function callback(err, result) {
|
||||
if (!err) {
|
||||
console.dir(result, { "colors": true, "depth": null });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fixes all supported violations in Markdown content
|
||||
const original = "# Heading";
|
||||
const fixResults = markdownlint.sync({ "strings": { "content": original } });
|
||||
const fixed = markdownlint.applyFixes(original, fixResults.content);
|
||||
console.log(fixed);
|
||||
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());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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 results = lintSync({ "strings": { "content": original } });
|
||||
const fixed = applyFixes(original, results.content);
|
||||
console.log(fixed);
|
||||
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
[
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue