Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.

This commit is contained in:
David Anson 2024-11-28 20:36:44 -08:00
parent 191226f070
commit 1e71f6f44e
140 changed files with 1087 additions and 10428 deletions

View file

@ -30,11 +30,3 @@ jobs:
run: npm install --no-package-lock run: npm install --no-package-lock
- name: Run CI Tests - name: Run CI Tests
run: npm run ci run: npm run ci
- name: Install markdownlint-micromark Dependencies
run: npm run install-micromark
- name: Build markdownlint-micromark
run: npm run build-micromark
- name: Install local markdownlint-micromark
run: npm install --no-package-lock ./micromark
- name: Test with local markdownlint-micromark
run: npm test

9
.gitignore vendored
View file

@ -1,14 +1,7 @@
coverage coverage
demo/markdown-it.min.js demo/markdown-it.min.js
demo/markdownlint-browser.js
demo/markdownlint-browser.min.js demo/markdownlint-browser.min.js
demo/micromark-browser.js
demo/micromark-html-browser.js
micromark/micromark.cjs
micromark/micromark.dev.cjs
micromark/micromark-browser.js
micromark/micromark-browser.dev.js
micromark/micromark-html-browser.js
micromark/micromark-html-browser.dev.js
node_modules node_modules
!test/node_modules !test/node_modules
npm-debug.log npm-debug.log

View file

@ -5,13 +5,11 @@
.vscode .vscode
coverage coverage
demo/* demo/*
!demo/markdownlint-browser.js
doc-build doc-build
eslint.config.mjs eslint.config.mjs
example example
micromark
npm-debug.log npm-debug.log
schema/*.js schema/*.mjs
scripts scripts
test test
test-repos test-repos

View file

@ -798,12 +798,10 @@ function applyFixes(input, errors) { ... }
Invoking `applyFixes` with the results of a call to lint can be done like so: Invoking `applyFixes` with the results of a call to lint can be done like so:
```javascript ```javascript
const { "sync": markdownlintSync, applyFixes } = require("markdownlint"); import markdownlint from "markdownlint";
function fixMarkdownlintViolations(content) { const fixResults = markdownlint.sync({ "strings": { "content": original } });
const fixResults = markdownlintSync({ strings: { content } }); const fixed = markdownlint.applyFixes(original, fixResults.content);
return applyFixes(content, fixResults.content);
}
``` ```
## Usage ## Usage
@ -811,7 +809,7 @@ function fixMarkdownlintViolations(content) {
Invoke `markdownlint` and use the `result` object's `toString` method: Invoke `markdownlint` and use the `result` object's `toString` method:
```javascript ```javascript
const markdownlint = require("markdownlint"); import markdownlint from "markdownlint";
const options = { const options = {
"files": [ "good.md", "bad.md" ], "files": [ "good.md", "bad.md" ],
@ -897,10 +895,10 @@ Output:
``` ```
Integration with the [gulp](https://gulpjs.com/) build system is Integration with the [gulp](https://gulpjs.com/) build system is
straightforward: [`gulpfile.js`](example/gulpfile.js). straightforward: [`gulpfile.cjs`](example/gulpfile.cjs).
Integration with the [Grunt](https://gruntjs.com/) build system is similar: Integration with the [Grunt](https://gruntjs.com/) build system is similar:
[`Gruntfile.js`](example/Gruntfile.js). [`Gruntfile.cjs`](example/Gruntfile.cjs).
## Browser ## Browser
@ -912,11 +910,9 @@ Generate normal and minified scripts with:
npm run build-demo npm run build-demo
``` ```
Then reference `markdownlint` and `micromark` scripts: Then reference the `markdownlint` script:
```html ```html
<script src="demo/micromark-browser.js"></script>
<script src="demo/micromark-html-browser.js"></script>
<script src="demo/markdownlint-browser.min.js"></script> <script src="demo/markdownlint-browser.min.js"></script>
``` ```
@ -928,7 +924,7 @@ const options = {
"content": "Some Markdown to lint." "content": "Some Markdown to lint."
} }
}; };
const results = window.markdownlint.sync(options).toString(); const results = window.markdownlint.markdownlint.sync(options).toString();
``` ```
## Examples ## Examples

9
demo/browser-exports.mjs Normal file
View file

@ -0,0 +1,9 @@
// @ts-check
export { default as markdownlint } from "../lib/markdownlint.mjs";
export { compile, parse, postprocess, preprocess } from "micromark";
export { directive, directiveHtml } from "micromark-extension-directive";
export { gfmAutolinkLiteral, gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal";
export { gfmFootnote, gfmFootnoteHtml } from "micromark-extension-gfm-footnote";
export { gfmTable, gfmTableHtml } from "micromark-extension-gfm-table";
export { math, mathHtml } from "micromark-extension-math";

View file

@ -34,8 +34,6 @@
</div> </div>
</div> </div>
<script src="markdown-it.min.js"></script> <script src="markdown-it.min.js"></script>
<script src="micromark-browser.js"></script>
<script src="micromark-html-browser.js"></script>
<script src="markdownlint-browser.min.js"></script> <script src="markdownlint-browser.min.js"></script>
<script src="default.js"></script> <script src="default.js"></script>
</body> </body>

View file

@ -3,9 +3,8 @@
(function main() { (function main() {
// Dependencies // Dependencies
var markdownit = globalThis.markdownit; var markdownit = globalThis.markdownit;
var markdownlint = globalThis.markdownlint.library; var markdownlint = globalThis.markdownlint.markdownlint;
var micromark = globalThis.micromarkBrowser; var micromark = globalThis.markdownlint;
var micromarkHtml = globalThis.micromarkHtmlBrowser;
// DOM elements // DOM elements
var markdown = document.getElementById("markdown"); var markdown = document.getElementById("markdown");
@ -70,15 +69,15 @@
const compileOptions = { const compileOptions = {
"allowDangerousHtml": true, "allowDangerousHtml": true,
"htmlExtensions": [ "htmlExtensions": [
micromarkHtml.directiveHtml({ "*": handleDirective }), micromark.directiveHtml({ "*": handleDirective }),
micromarkHtml.gfmAutolinkLiteralHtml(), micromark.gfmAutolinkLiteralHtml(),
micromarkHtml.gfmFootnoteHtml(), micromark.gfmFootnoteHtml(),
micromarkHtml.gfmTableHtml(), micromark.gfmTableHtml(),
micromarkHtml.mathHtml() micromark.mathHtml()
] ]
}; };
try { try {
return micromarkHtml.compile(compileOptions)(events); return micromark.compile(compileOptions)(events);
} catch (error) { } catch (error) {
return `[Exception: "${error}"]`; return `[Exception: "${error}"]`;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,8 +0,0 @@
// @ts-check
"use strict";
module.exports = {
"library": require(".."),
"helpers": require("../helpers")
};

8
demo/module-stub.cjs Normal file
View file

@ -0,0 +1,8 @@
// @ts-check
"use strict";
module.exports = {
// @ts-ignore
"createRequire": () => require
};

View file

@ -1,11 +1,14 @@
// @ts-check // @ts-check
"use strict"; import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const webpack = require("webpack"); import webpack from "webpack";
const TerserPlugin = require("terser-webpack-plugin"); import TerserPlugin from "terser-webpack-plugin";
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
const libraryPackageJson = await importWithTypeJson(import.meta, "../package.json");
const nodeModulePrefixRe = /^node:/u; const nodeModulePrefixRe = /^node:/u;
// eslint-disable-next-line jsdoc/require-jsdoc
function config(options) { function config(options) {
const { entry, filename, mode, optimization, packageJson } = options; const { entry, filename, mode, optimization, packageJson } = options;
const { name, version, homepage, license } = packageJson; const { name, version, homepage, license } = packageJson;
@ -13,8 +16,7 @@ function config(options) {
"devtool": false, "devtool": false,
"entry": entry, "entry": entry,
"externals": { "externals": {
"markdown-it": "markdownit", "markdown-it": "markdownit"
"markdownlint-micromark": "micromarkBrowser"
}, },
"mode": mode, "mode": mode,
"module": { "module": {
@ -33,7 +35,7 @@ function config(options) {
"name": name.replace(/(-\w)/g, (m) => m.slice(1).toUpperCase()), "name": name.replace(/(-\w)/g, (m) => m.slice(1).toUpperCase()),
"type": "var" "type": "var"
}, },
"path": __dirname "path": __dirname(import.meta)
}, },
"plugins": [ "plugins": [
new webpack.NormalModuleReplacementPlugin( new webpack.NormalModuleReplacementPlugin(
@ -52,7 +54,8 @@ function config(options) {
"fs": false, "fs": false,
"os": false, "os": false,
"path": false, "path": false,
"util": false "util": false,
"module": require.resolve("./module-stub.cjs")
} }
} }
}; };
@ -77,14 +80,10 @@ const modeProduction = {
} }
}; };
const entryLibrary = { const entryLibrary = {
"entry": "./markdownlint-exports.js", "entry": "./browser-exports.mjs",
"packageJson": require("../package.json") "packageJson": libraryPackageJson
}; };
// const entryHelpers = { export default [
// "entry": "../helpers/helpers.js",
// "packageJson": require("../helpers/package.json")
// };
module.exports = [
config({ config({
...entryLibrary, ...entryLibrary,
...modeDevelopment, ...modeDevelopment,
@ -95,14 +94,4 @@ module.exports = [
...modeProduction, ...modeProduction,
"filename": "markdownlint-browser.min.js" "filename": "markdownlint-browser.min.js"
}) })
// config({
// ...entryHelpers,
// ...modeDevelopment,
// "filename": "markdownlint-rule-helpers-browser.js"
// }),
// config({
// ...entryHelpers,
// ...modeProduction,
// "filename": "markdownlint-rule-helpers-browser.min.js"
// })
]; ];

View file

@ -1,8 +1,8 @@
import { readFile, writeFile } from "node:fs/promises"; import { readFile, writeFile } from "node:fs/promises";
import { EOL } from "node:os"; import { EOL } from "node:os";
import { default as rules } from "../lib/rules.js"; import { default as rules } from "../lib/rules.mjs";
import { newLineRe } from "../helpers/helpers.js"; import { newLineRe } from "../helpers/helpers.cjs";
import { deprecatedRuleNames, fixableRuleNames } from "../lib/constants.js"; import { deprecatedRuleNames, fixableRuleNames } from "../lib/constants.mjs";
const maxLineLength = 80; const maxLineLength = 80;

View file

@ -36,7 +36,7 @@ A simple rule implementation using the `micromark` parser to report a violation
for any use of blockquotes might look like: for any use of blockquotes might look like:
```javascript ```javascript
/** @type import("markdownlint").Rule */ /** @type {import("markdownlint").Rule} */
module.exports = { module.exports = {
"names": [ "any-blockquote-micromark" ], "names": [ "any-blockquote-micromark" ],
"description": "Rule that reports an error for any blockquote", "description": "Rule that reports an error for any blockquote",
@ -61,7 +61,7 @@ module.exports = {
That same rule implemented using the `markdown-it` parser might look like: That same rule implemented using the `markdown-it` parser might look like:
```javascript ```javascript
/** @type import("markdownlint").Rule */ /** @type {import("markdownlint").Rule} */
module.exports = { module.exports = {
"names": [ "any-blockquote-markdown-it" ], "names": [ "any-blockquote-markdown-it" ],
"description": "Rule that reports an error for any blockquote", "description": "Rule that reports an error for any blockquote",
@ -187,8 +187,8 @@ exception.
[markdown-it-token]: https://markdown-it.github.io/markdown-it/#Token [markdown-it-token]: https://markdown-it.github.io/markdown-it/#Token
[markdownlint-rule]: https://www.npmjs.com/search?q=keywords:markdownlint-rule [markdownlint-rule]: https://www.npmjs.com/search?q=keywords:markdownlint-rule
[micromark]: https://github.com/micromark/micromark [micromark]: https://github.com/micromark/micromark
[micromark-token]: ../lib/markdownlint.d.ts [micromark-token]: ../lib/markdownlint.d.mts
[rule-helpers]: https://www.npmjs.com/package/markdownlint-rule-helpers [rule-helpers]: https://www.npmjs.com/package/markdownlint-rule-helpers
[options-custom-rules]: ../README.md#optionscustomrules [options-custom-rules]: ../README.md#optionscustomrules
[test-rules]: ../test/rules [test-rules]: ../test/rules
[tokens]: ../test/snapshots/markdownlint-test-custom-rules.js.md [tokens]: ../test/snapshots/markdownlint-test-custom-rules.mjs.md

View file

@ -25,20 +25,11 @@ export default [
"demo/markdown-it.min.js", "demo/markdown-it.min.js",
"demo/markdownlint-browser.js", "demo/markdownlint-browser.js",
"demo/markdownlint-browser.min.js", "demo/markdownlint-browser.min.js",
"demo/micromark-browser.js",
"demo/micromark-html-browser.js",
"example/typescript/type-check.js", "example/typescript/type-check.js",
"micromark/micromark.cjs",
"micromark/micromark.dev.cjs",
"micromark/micromark-browser.js",
"micromark/micromark-browser.dev.js",
"test-repos/**" "test-repos/**"
] ]
}, },
{ {
"languageOptions": {
"sourceType": "commonjs"
},
"linterOptions": { "linterOptions": {
"reportUnusedDisableDirectives": true "reportUnusedDisableDirectives": true
}, },
@ -88,7 +79,6 @@ export default [
"unicorn/no-null": "off", "unicorn/no-null": "off",
"unicorn/no-useless-undefined": "off", "unicorn/no-useless-undefined": "off",
"unicorn/prefer-at": "off", "unicorn/prefer-at": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-string-raw": "off", "unicorn/prefer-string-raw": "off",
"unicorn/prefer-string-replace-all": "off", "unicorn/prefer-string-replace-all": "off",
"unicorn/prefer-string-slice": "off", "unicorn/prefer-string-slice": "off",
@ -107,15 +97,20 @@ export default [
}, },
{ {
"files": [ "files": [
"**/*.mjs" "**/*.js",
"**/*.cjs"
], ],
"languageOptions": { "languageOptions": {
"sourceType": "module" "sourceType": "commonjs",
"globals": {
"module": "readonly",
"require": "readonly"
}
} }
}, },
{ {
"files": [ "files": [
"demo/*.js" "demo/default.js"
], ],
"languageOptions": { "languageOptions": {
"globals": { "globals": {
@ -131,26 +126,42 @@ export default [
"no-invalid-this": "off", "no-invalid-this": "off",
"no-shadow": "off", "no-shadow": "off",
"no-var": "off", "no-var": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-query-selector": "off" "unicorn/prefer-query-selector": "off"
} }
}, },
{ {
"files": [ "files": [
"example/*.js" "example/*.cjs"
], ],
"languageOptions": {
"sourceType": "commonjs"
},
"rules": { "rules": {
"n/no-missing-require": "off", "n/no-missing-require": "off",
"no-console": "off", "no-console": "off",
"no-invalid-this": "off", "no-invalid-this": "off"
}
},
{
"files": [
"example/standalone.mjs"
],
"rules": {
"no-console": "off",
"no-shadow": "off" "no-shadow": "off"
} }
}, },
{ {
"files": [ "files": [
"test/rules/**/*.js" "test/rules/**/*.js",
"test/rules/**/*.cjs"
], ],
"languageOptions": {
"sourceType": "commonjs"
},
"rules": { "rules": {
"jsdoc/valid-types": "off" "unicorn/prefer-module": "off"
} }
} }
]; ];

28
example/Gruntfile.cjs Normal file
View file

@ -0,0 +1,28 @@
// @ts-check
"use strict";
module.exports = function wrapper(grunt) {
grunt.initConfig({
"markdownlint": {
"example": {
"src": [ "*.md" ]
}
}
});
grunt.registerMultiTask("markdownlint", function task() {
const done = this.async();
import("markdownlint").then(({ "default": markdownlint }) => {
markdownlint(
{ "files": this.filesSrc },
function callback(err, result) {
const resultString = err || ((result || "").toString());
if (resultString) {
grunt.fail.warn("\n" + resultString + "\n");
}
done(!err || !resultString);
});
}).catch(done);
});
};

View file

@ -1,28 +0,0 @@
// @ts-check
"use strict";
const markdownlint = require("../lib/markdownlint");
module.exports = function wrapper(grunt) {
grunt.initConfig({
"markdownlint": {
"example": {
"src": [ "*.md" ]
}
}
});
grunt.registerMultiTask("markdownlint", function task() {
const done = this.async();
markdownlint(
{ "files": this.filesSrc },
function callback(err, result) {
const resultString = err || ((result || "").toString());
if (resultString) {
grunt.fail.warn("\n" + resultString + "\n");
}
done(!err || !resultString);
});
});
};

24
example/gulpfile.cjs Normal file
View file

@ -0,0 +1,24 @@
// @ts-check
"use strict";
const gulp = require("gulp");
const through2 = require("through2");
// Simple task wrapper
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(
{ "files": [ file.relative ] },
function callback(err, result) {
const resultString = (result || "").toString();
if (resultString) {
console.log(resultString);
}
next(err, file);
});
}).catch(next);
}));
});

View file

@ -1,23 +0,0 @@
// @ts-check
"use strict";
const gulp = require("gulp");
const through2 = require("through2");
const markdownlint = require("../lib/markdownlint");
// Simple task wrapper
gulp.task("markdownlint", function task() {
return gulp.src("*.md", { "read": false })
.pipe(through2.obj(function obj(file, enc, next) {
markdownlint(
{ "files": [ file.relative ] },
function callback(err, result) {
const resultString = (result || "").toString();
if (resultString) {
console.log(resultString);
}
next(err, file);
});
}));
});

View file

@ -1,8 +1,6 @@
// @ts-check // @ts-check
"use strict"; import markdownlint from "markdownlint";
const markdownlint = require("../lib/markdownlint");
const options = { const options = {
"files": [ "good.md", "bad.md" ], "files": [ "good.md", "bad.md" ],
@ -19,6 +17,7 @@ console.log(result.toString());
// Makes an asynchronous call // Makes an asynchronous call
markdownlint(options, function callback(err, result) { markdownlint(options, function callback(err, result) {
if (!err) { if (!err) {
// @ts-ignore
console.log(result.toString()); console.log(result.toString());
} }
}); });
@ -29,3 +28,9 @@ markdownlint(options, function callback(err, result) {
console.dir(result, { "colors": true, "depth": null }); 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);

View file

@ -1,25 +1,27 @@
// Attempt to validate all the type declarations in markdownlint.d.ts // Attempt to validate all the type declarations in markdownlint.d.mts
import markdownlint from "../.."; import { default as markdownlint, Configuration, ConfigurationStrict, LintResults, Options, Rule, RuleParams, RuleOnError, RuleOnErrorInfo } from "../../lib/markdownlint.mjs";
const assert = require("assert"); 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 markdownlintJsonPath = "../../.markdownlint.json";
const version: string = markdownlint.getVersion(); const version: string = markdownlint.getVersion();
assert(/^\d+\.\d+\.\d+$/.test(version)); assert(/^\d+\.\d+\.\d+$/.test(version));
function assertConfiguration(config: markdownlint.Configuration) { function assertConfiguration(config: Configuration) {
assert(!!config); assert(!!config);
assert.deepEqual(config["line-length"], { "strict": true, "code_blocks": false }); assert.deepEqual(config["line-length"], { "strict": true, "code_blocks": false });
// config assignment is covered by markdownlint.Options // config assignment is covered by markdownlint.Options
} }
function assertConfigurationCallback(err: Error | null, config?: markdownlint.Configuration) { function assertConfigurationCallback(err: Error | null, config?: Configuration) {
assert(!err); assert(!err);
config && assertConfiguration(config); config && assertConfiguration(config);
} }
function assertLintResults(results: markdownlint.LintResults) { function assertLintResults(results: LintResults) {
assert(!!results); assert(!!results);
assert.equal(results["string"].length, 1); assert.equal(results["string"].length, 1);
assert.equal(results["string"][0].lineNumber, 1); assert.equal(results["string"][0].lineNumber, 1);
@ -60,7 +62,7 @@ function assertLintResults(results: markdownlint.LintResults) {
}; };
} }
function assertLintResultsCallback(err: Error | null, results?: markdownlint.LintResults) { function assertLintResultsCallback(err: Error | null, results?: LintResults) {
assert(!err); assert(!err);
results && assertLintResults(results); results && assertLintResults(results);
} }
@ -76,7 +78,7 @@ markdownlint.readConfig(markdownlintJsonPath, [ JSON.parse ], assertConfiguratio
assertConfigurationCallback(null, await markdownlint.promises.readConfig(markdownlintJsonPath, [ JSON.parse ])) assertConfigurationCallback(null, await markdownlint.promises.readConfig(markdownlintJsonPath, [ JSON.parse ]))
})(); })();
let options: markdownlint.Options; let options: Options;
options = { options = {
"files": [ "../bad.md" ], "files": [ "../bad.md" ],
"strings": { "strings": {
@ -93,7 +95,7 @@ options = {
"frontMatter": /---/, "frontMatter": /---/,
"handleRuleFailures": false, "handleRuleFailures": false,
"noInlineConfig": false, "noInlineConfig": false,
"markdownItPlugins": [ [ require("markdown-it-sub") ] ] "markdownItPlugins": [ [ markdownItSub ] ]
}; };
assertLintResults(markdownlint.sync(options)); assertLintResults(markdownlint.sync(options));
@ -109,16 +111,16 @@ markdownlint(options, assertLintResultsCallback);
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options)); assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
})(); })();
const testRule: markdownlint.Rule = { const testRule: Rule = {
"names": [ "test-rule" ], "names": [ "test-rule" ],
"description": "Test rule", "description": "Test rule",
"information": new URL("https://example.com/rule-information"), "information": new URL("https://example.com/rule-information"),
"tags": [ "test-tag" ], "tags": [ "test-tag" ],
"parser": "none", "parser": "none",
"function": function rule(params: markdownlint.RuleParams, onError: markdownlint.RuleOnError) { "function": function rule(params: RuleParams, onError: RuleOnError) {
assert(!!params); assert(!!params);
assert(!!onError); assert(!!onError);
let ruleParams: markdownlint.RuleParams; let ruleParams: RuleParams;
ruleParams = { ruleParams = {
"name": "name", "name": "name",
"parsers": { "parsers": {
@ -140,7 +142,7 @@ const testRule: markdownlint.Rule = {
"version": "1.2.3" "version": "1.2.3"
}; };
assert(ruleParams); assert(ruleParams);
let ruleOnErrorInfo: markdownlint.RuleOnErrorInfo; let ruleOnErrorInfo: RuleOnErrorInfo;
ruleOnErrorInfo = { ruleOnErrorInfo = {
"lineNumber": 1, "lineNumber": 1,
"detail": "detail", "detail": "detail",
@ -196,7 +198,7 @@ assert.equal(
"# Heading\n" "# Heading\n"
); );
const configuration: markdownlint.Configuration = { const configuration: Configuration = {
"custom-rule": true, "custom-rule": true,
"no-hard-tabs": false, "no-hard-tabs": false,
"heading-style": { "heading-style": {
@ -204,7 +206,7 @@ const configuration: markdownlint.Configuration = {
} }
}; };
assert(configuration); assert(configuration);
const configurationStrict: markdownlint.ConfigurationStrict = { const configurationStrict: ConfigurationStrict = {
// "custom-rule": true, // "custom-rule": true,
"no-hard-tabs": false, "no-hard-tabs": false,
"heading-style": { "heading-style": {

View file

@ -1 +1 @@
test.js test.cjs

View file

@ -4,13 +4,17 @@
const micromark = require("./micromark-helpers.cjs"); const micromark = require("./micromark-helpers.cjs");
const { newLineRe, nextLinesRe } = require("./shared.js"); const { newLineRe, nextLinesRe } = require("./shared.cjs");
module.exports.newLineRe = newLineRe; module.exports.newLineRe = newLineRe;
module.exports.nextLinesRe = nextLinesRe; module.exports.nextLinesRe = nextLinesRe;
/** @typedef {import("../lib/markdownlint.js").RuleOnError} RuleOnError */ // @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.js").RuleOnErrorFixInfo} RuleOnErrorFixInfo */ /** @typedef {import("../lib/markdownlint.mjs").RuleOnError} RuleOnError */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} MicromarkToken */
// Regular expression for matching common front matter (YAML and TOML) // Regular expression for matching common front matter (YAML and TOML)
module.exports.frontMatterRe = module.exports.frontMatterRe =
@ -336,8 +340,8 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => (
/** /**
* Returns whether two ranges (or MicromarkTokens) overlap anywhere. * Returns whether two ranges (or MicromarkTokens) overlap anywhere.
* *
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeA Range A. * @param {FileRange|MicromarkToken} rangeA Range A.
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B. * @param {FileRange|MicromarkToken} rangeB Range B.
* @returns {boolean} True iff the two ranges overlap. * @returns {boolean} True iff the two ranges overlap.
*/ */
module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) { module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {

View file

@ -2,10 +2,12 @@
"use strict"; "use strict";
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.js"); const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
/** @typedef {import("markdownlint-micromark").TokenType} TokenType */ // @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */ /** @typedef {import("micromark-util-types").TokenType} TokenType */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} Token */
/** /**
* Determines if a Micromark token is within an htmlFlow type. * Determines if a Micromark token is within an htmlFlow type.

View file

@ -1,18 +1,24 @@
// @ts-check // @ts-check
"use strict"; import { directive } from "micromark-extension-directive";
import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
import { gfmFootnote } from "micromark-extension-gfm-footnote";
import { gfmTable } from "micromark-extension-gfm-table";
import { math } from "micromark-extension-math";
import { parse as micromarkParse, postprocess as micromarkPostprocess, preprocess as micromarkPreprocess } from "micromark";
// micromark-core-commonmark is not a dependency because this instance must match what's used by micromark
// eslint-disable-next-line n/no-extraneous-import
import { labelEnd } from "micromark-core-commonmark";
import { isHtmlFlowComment } from "./micromark-helpers.cjs";
import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "./shared.cjs";
const micromark = require("markdownlint-micromark"); /** @typedef {import("micromark-util-types").Event} Event */
const { isHtmlFlowComment } = require("./micromark-helpers.cjs"); /** @typedef {import("micromark-util-types").ParseOptions} MicromarkParseOptions */
const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js"); /** @typedef {import("micromark-util-types").State} State */
/** @typedef {import("micromark-util-types").Token} Token */
/** @typedef {import("markdownlint-micromark").Construct} Construct */ /** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
/** @typedef {import("markdownlint-micromark").Event} Event */ /** @typedef {import("./micromark-types.d.mts")} */
/** @typedef {import("markdownlint-micromark").ParseOptions} MicromarkParseOptions */ /** @typedef {import("../lib/markdownlint.mjs").MicromarkToken} MicromarkToken */
/** @typedef {import("markdownlint-micromark").State} State */
/** @typedef {import("markdownlint-micromark").Token} Token */
/** @typedef {import("markdownlint-micromark").Tokenizer} Tokenizer */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} MicromarkToken */
/** /**
* Parse options. * Parse options.
@ -28,27 +34,23 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");
* @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark. * @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark.
* @returns {Event[]} Micromark events. * @returns {Event[]} Micromark events.
*/ */
function getEvents( export function getEvents(
markdown, markdown,
micromarkParseOptions = {} micromarkParseOptions = {}
) { ) {
// Customize extensions list to add useful extensions // Customize extensions list to add useful extensions
const extensions = [ const extensions = [
micromark.directive(), directive(),
micromark.gfmAutolinkLiteral(), gfmAutolinkLiteral(),
micromark.gfmFootnote(), gfmFootnote(),
micromark.gfmTable(), gfmTable(),
micromark.math(), math(),
...(micromarkParseOptions.extensions || []) ...(micromarkParseOptions.extensions || [])
]; ];
// // Shim labelEnd to identify undefined link labels // // Shim labelEnd to identify undefined link labels
/** @type {Event[][]} */ /** @type {Event[][]} */
const artificialEventLists = []; const artificialEventLists = [];
/** @type {Construct} */
const labelEnd =
// @ts-ignore
micromark.labelEnd;
const tokenizeOriginal = labelEnd.tokenize; const tokenizeOriginal = labelEnd.tokenize;
/** @type {Tokenizer} */ /** @type {Tokenizer} */
@ -162,9 +164,9 @@ function getEvents(
// Use micromark to parse document into Events // Use micromark to parse document into Events
const encoding = undefined; const encoding = undefined;
const eol = true; const eol = true;
const parseContext = micromark.parse({ ...micromarkParseOptions, extensions }); const parseContext = micromarkParse({ ...micromarkParseOptions, extensions });
const chunks = micromark.preprocess()(markdown, encoding, eol); const chunks = micromarkPreprocess()(markdown, encoding, eol);
const events = micromark.postprocess(parseContext.document().write(chunks)); const events = micromarkPostprocess(parseContext.document().write(chunks));
// Append artificial events and return all events // Append artificial events and return all events
// eslint-disable-next-line unicorn/prefer-spread // eslint-disable-next-line unicorn/prefer-spread
@ -214,8 +216,7 @@ function parseInternal(
}; };
const history = [ root ]; const history = [ root ];
let current = root; let current = root;
// eslint-disable-next-line jsdoc/valid-types /** @type {MicromarkParseOptions | null} */
/** @type MicromarkParseOptions | null */
let reparseOptions = null; let reparseOptions = null;
let lines = null; let lines = null;
let skipHtmlFlowChildren = false; let skipHtmlFlowChildren = false;
@ -303,11 +304,6 @@ function parseInternal(
* @param {ParseOptions} [parseOptions] Options. * @param {ParseOptions} [parseOptions] Options.
* @returns {MicromarkToken[]} Micromark tokens. * @returns {MicromarkToken[]} Micromark tokens.
*/ */
function parse(markdown, parseOptions) { export function parse(markdown, parseOptions) {
return parseInternal(markdown, parseOptions); return parseInternal(markdown, parseOptions);
} }
module.exports = {
getEvents,
parse
};

View file

@ -0,0 +1,11 @@
export {};
// Augment TokenTypeMap with markdownlint-specific types.
declare module "micromark-util-types" {
export interface TokenTypeMap {
undefinedReference: "undefinedReference"
undefinedReferenceCollapsed: "undefinedReferenceCollapsed"
undefinedReferenceFull: "undefinedReferenceFull"
undefinedReferenceShortcut: "undefinedReferenceShortcut"
}
}

View file

@ -2,9 +2,9 @@
"name": "markdownlint-rule-helpers", "name": "markdownlint-rule-helpers",
"version": "0.27.0", "version": "0.27.0",
"description": "A collection of markdownlint helper functions for custom rules", "description": "A collection of markdownlint helper functions for custom rules",
"main": "./helpers.js", "main": "./helpers.cjs",
"exports": { "exports": {
".": "./helpers.js", ".": "./helpers.cjs",
"./micromark": "./micromark-helpers.cjs" "./micromark": "./micromark-helpers.cjs"
}, },
"author": "David Anson (https://dlaa.me/)", "author": "David Anson (https://dlaa.me/)",
@ -20,7 +20,12 @@
"node": ">=18" "node": ">=18"
}, },
"dependencies": { "dependencies": {
"markdownlint-micromark": "0.1.2" "micromark": "4.0.0",
"micromark-extension-directive": "3.0.2",
"micromark-extension-gfm-autolink-literal": "2.1.0",
"micromark-extension-gfm-footnote": "2.1.0",
"micromark-extension-gfm-table": "2.1.0",
"micromark-extension-math": "3.1.0"
}, },
"keywords": [ "keywords": [
"markdownlint", "markdownlint",

View file

@ -7,7 +7,7 @@ const test = require("ava").default;
const { "exports": packageExports, name } = require("../helpers/package.json"); const { "exports": packageExports, name } = require("../helpers/package.json");
const exportMappings = new Map([ const exportMappings = new Map([
[ ".", "../helpers/helpers.js" ], [ ".", "../helpers/helpers.cjs" ],
[ "./micromark", "../helpers/micromark-helpers.cjs" ] [ "./micromark", "../helpers/micromark-helpers.cjs" ]
]); ]);

View file

@ -1,9 +1,7 @@
// @ts-check // @ts-check
"use strict"; import { getReferenceLinkImageData as helpersGetReferenceLinkImageData } from "../helpers/helpers.cjs";
import { filterByTypes } from "../helpers/micromark-helpers.cjs";
const helpers = require("../helpers");
const { filterByTypes } = require("../helpers/micromark-helpers.cjs");
/** @type {Map<string, object>} */ /** @type {Map<string, object>} */
const map = new Map(); const map = new Map();
@ -12,10 +10,10 @@ let params = undefined;
/** /**
* Initializes (resets) the cache. * Initializes (resets) the cache.
* *
* @param {import("./markdownlint").RuleParams} [p] Rule parameters object. * @param {import("./markdownlint.mjs").RuleParams} [p] Rule parameters object.
* @returns {void} * @returns {void}
*/ */
function initialize(p) { export function initialize(p) {
map.clear(); map.clear();
params = p; params = p;
} }
@ -39,11 +37,11 @@ function getCached(name, getValue) {
/** /**
* Filters a list of Micromark tokens by type and caches the result. * Filters a list of Micromark tokens by type and caches the result.
* *
* @param {import("./markdownlint").MicromarkTokenType[]} types Types to allow. * @param {import("./markdownlint.mjs").MicromarkTokenType[]} types Types to allow.
* @param {boolean} [htmlFlow] Whether to include htmlFlow content. * @param {boolean} [htmlFlow] Whether to include htmlFlow content.
* @returns {import("./markdownlint").MicromarkToken[]} Filtered tokens. * @returns {import("./markdownlint.mjs").MicromarkToken[]} Filtered tokens.
*/ */
function filterByTypesCached(types, htmlFlow) { export function filterByTypesCached(types, htmlFlow) {
return getCached( return getCached(
// eslint-disable-next-line prefer-rest-params // eslint-disable-next-line prefer-rest-params
JSON.stringify(arguments), JSON.stringify(arguments),
@ -56,15 +54,9 @@ function filterByTypesCached(types, htmlFlow) {
* *
* @returns {Object} Reference link and image data object. * @returns {Object} Reference link and image data object.
*/ */
function getReferenceLinkImageData() { export function getReferenceLinkImageData() {
return getCached( return getCached(
getReferenceLinkImageData.name, getReferenceLinkImageData.name,
() => helpers.getReferenceLinkImageData(params.parsers.micromark.tokens) () => helpersGetReferenceLinkImageData(params.parsers.micromark.tokens)
); );
} }
module.exports = {
initialize,
filterByTypesCached,
getReferenceLinkImageData
};

View file

@ -1,4 +1,4 @@
import { ConfigurationStrict } from "./configuration-strict"; import type { ConfigurationStrict } from "./configuration-strict.d.ts";
export interface Configuration extends ConfigurationStrict { export interface Configuration extends ConfigurationStrict {
/** /**

View file

@ -1,9 +1,7 @@
// @ts-check // @ts-check
"use strict"; export const deprecatedRuleNames = [];
export const fixableRuleNames = [
module.exports.deprecatedRuleNames = [];
module.exports.fixableRuleNames = [
"MD004", "MD005", "MD007", "MD009", "MD010", "MD011", "MD004", "MD005", "MD007", "MD009", "MD010", "MD011",
"MD012", "MD014", "MD018", "MD019", "MD020", "MD021", "MD012", "MD014", "MD018", "MD019", "MD020", "MD021",
"MD022", "MD023", "MD026", "MD027", "MD030", "MD031", "MD022", "MD023", "MD026", "MD027", "MD030", "MD031",
@ -11,5 +9,5 @@ module.exports.fixableRuleNames = [
"MD047", "MD049", "MD050", "MD051", "MD053", "MD054", "MD047", "MD049", "MD050", "MD051", "MD053", "MD054",
"MD058" "MD058"
]; ];
module.exports.homepage = "https://github.com/DavidAnson/markdownlint"; export const homepage = "https://github.com/DavidAnson/markdownlint";
module.exports.version = "0.36.1"; export const version = "0.36.1";

View file

@ -4,6 +4,11 @@
const { newLineRe } = require("../helpers"); const { newLineRe } = require("../helpers");
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("./markdownlint.mjs").MarkdownItToken} MarkdownItToken */
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
/** @typedef {import("./markdownlint.mjs").Plugin} Plugin */
/** /**
* @callback InlineCodeSpanCallback * @callback InlineCodeSpanCallback
* @param {string} code Code content. * @param {string} code Code content.
@ -67,7 +72,7 @@ function forEachInlineCodeSpan(input, handler) {
/** /**
* Freeze all freeze-able members of a token and its children. * Freeze all freeze-able members of a token and its children.
* *
* @param {import("./markdownlint").MarkdownItToken} token A markdown-it token. * @param {MarkdownItToken} token A markdown-it token.
* @returns {void} * @returns {void}
*/ */
function freezeToken(token) { function freezeToken(token) {
@ -98,8 +103,7 @@ function freezeToken(token) {
*/ */
function annotateAndFreezeTokens(tokens, lines) { function annotateAndFreezeTokens(tokens, lines) {
let trMap = null; let trMap = null;
// eslint-disable-next-line jsdoc/valid-types /** @type {MarkdownItToken[]} */
/** @type import("./markdownlint").MarkdownItToken[] */
// @ts-ignore // @ts-ignore
const markdownItTokens = tokens; const markdownItTokens = tokens;
for (const token of markdownItTokens) { for (const token of markdownItTokens) {
@ -148,10 +152,10 @@ function annotateAndFreezeTokens(tokens, lines) {
/** /**
* Gets an array of markdown-it tokens for the input. * Gets an array of markdown-it tokens for the input.
* *
* @param {import("./markdownlint").Plugin[]} markdownItPlugins Additional plugins. * @param {Plugin[]} markdownItPlugins Additional plugins.
* @param {string} content Markdown content. * @param {string} content Markdown content.
* @param {string[]} lines Lines of Markdown content. * @param {string[]} lines Lines of Markdown content.
* @returns {import("../lib/markdownlint").MarkdownItToken} Array of markdown-it tokens. * @returns {MarkdownItToken} Array of markdown-it tokens.
*/ */
function getMarkdownItTokens(markdownItPlugins, content, lines) { function getMarkdownItTokens(markdownItPlugins, content, lines) {
const markdownit = require("markdown-it"); const markdownit = require("markdown-it");

View file

@ -1,79 +1,12 @@
export = markdownlint; export default markdownlint;
/**
* 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, readConfig, readConfigSync, getVersion, promises, applyFix, applyFixes, RuleFunction, RuleParams, MarkdownParsers, ParserMarkdownIt, ParserMicromark, MarkdownItToken, MicromarkTokenType, MicromarkToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, RuleOnErrorFixInfoNormalized, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, ConfigurationStrict, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
}
/**
* 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;
declare namespace promises {
export { markdownlintPromise as markdownlint };
export { extendConfigPromise as extendConfig };
export { readConfigPromise as readConfig };
}
/**
* 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;
/** /**
* Function to implement rule logic. * Function to implement rule logic.
*/ */
type RuleFunction = (params: RuleParams, onError: RuleOnError) => void; export type RuleFunction = (params: RuleParams, onError: RuleOnError) => void;
/** /**
* Rule parameters. * Rule parameters.
*/ */
type RuleParams = { export type RuleParams = {
/** /**
* File/string name. * File/string name.
*/ */
@ -102,7 +35,7 @@ type RuleParams = {
/** /**
* Markdown parser data. * Markdown parser data.
*/ */
type MarkdownParsers = { export type MarkdownParsers = {
/** /**
* Markdown parser data from markdown-it (only present when Rule.parser is "markdownit"). * Markdown parser data from markdown-it (only present when Rule.parser is "markdownit").
*/ */
@ -115,7 +48,7 @@ type MarkdownParsers = {
/** /**
* Markdown parser data from markdown-it. * Markdown parser data from markdown-it.
*/ */
type ParserMarkdownIt = { export type ParserMarkdownIt = {
/** /**
* Token objects from markdown-it. * Token objects from markdown-it.
*/ */
@ -124,7 +57,7 @@ type ParserMarkdownIt = {
/** /**
* Markdown parser data from micromark. * Markdown parser data from micromark.
*/ */
type ParserMicromark = { export type ParserMicromark = {
/** /**
* Token objects from micromark. * Token objects from micromark.
*/ */
@ -133,7 +66,7 @@ type ParserMicromark = {
/** /**
* markdown-it token. * markdown-it token.
*/ */
type MarkdownItToken = { export type MarkdownItToken = {
/** /**
* HTML attributes. * HTML attributes.
*/ */
@ -195,11 +128,11 @@ type MarkdownItToken = {
*/ */
line: string; line: string;
}; };
type MicromarkTokenType = import("markdownlint-micromark").TokenType; export type MicromarkTokenType = import("micromark-util-types").TokenType;
/** /**
* micromark token. * micromark token.
*/ */
type MicromarkToken = { export type MicromarkToken = {
/** /**
* Token type. * Token type.
*/ */
@ -236,11 +169,11 @@ type MicromarkToken = {
/** /**
* Error-reporting callback. * Error-reporting callback.
*/ */
type RuleOnError = (onErrorInfo: RuleOnErrorInfo) => void; export type RuleOnError = (onErrorInfo: RuleOnErrorInfo) => void;
/** /**
* Fix information for RuleOnError callback. * Fix information for RuleOnError callback.
*/ */
type RuleOnErrorInfo = { export type RuleOnErrorInfo = {
/** /**
* Line number (1-based). * Line number (1-based).
*/ */
@ -269,7 +202,7 @@ type RuleOnErrorInfo = {
/** /**
* Fix information for RuleOnErrorInfo. * Fix information for RuleOnErrorInfo.
*/ */
type RuleOnErrorFixInfo = { export type RuleOnErrorFixInfo = {
/** /**
* Line number (1-based). * Line number (1-based).
*/ */
@ -290,7 +223,7 @@ type RuleOnErrorFixInfo = {
/** /**
* RuleOnErrorInfo with all optional properties present. * RuleOnErrorInfo with all optional properties present.
*/ */
type RuleOnErrorFixInfoNormalized = { export type RuleOnErrorFixInfoNormalized = {
/** /**
* Line number (1-based). * Line number (1-based).
*/ */
@ -311,7 +244,7 @@ type RuleOnErrorFixInfoNormalized = {
/** /**
* Rule definition. * Rule definition.
*/ */
type Rule = { export type Rule = {
/** /**
* Rule name(s). * Rule name(s).
*/ */
@ -344,7 +277,7 @@ type Rule = {
/** /**
* Configuration options. * Configuration options.
*/ */
type Options = { export type Options = {
/** /**
* Configuration object. * Configuration object.
*/ */
@ -395,21 +328,21 @@ type Options = {
/** /**
* A markdown-it plugin. * A markdown-it plugin.
*/ */
type Plugin = any[]; export type Plugin = any[];
/** /**
* Function to pretty-print lint results. * Function to pretty-print lint results.
*/ */
type ToStringCallback = (ruleAliases?: boolean) => string; export type ToStringCallback = (ruleAliases?: boolean) => string;
/** /**
* Lint results (for resultVersion 3). * Lint results (for resultVersion 3).
*/ */
type LintResults = { export type LintResults = {
[x: string]: LintError[]; [x: string]: LintError[];
}; };
/** /**
* Lint error. * Lint error.
*/ */
type LintError = { export type LintError = {
/** /**
* Line number (1-based). * Line number (1-based).
*/ */
@ -446,7 +379,7 @@ type LintError = {
/** /**
* Fix information. * Fix information.
*/ */
type FixInfo = { export type FixInfo = {
/** /**
* Line number (1-based). * Line number (1-based).
*/ */
@ -467,37 +400,92 @@ type FixInfo = {
/** /**
* Called with the result of linting a string or document. * Called with the result of linting a string or document.
*/ */
type LintContentCallback = (error: Error | null, result?: LintError[]) => void; export type LintContentCallback = (error: Error | null, result?: LintError[]) => void;
/** /**
* Called with the result of the lint function. * Called with the result of the lint function.
*/ */
type LintCallback = (error: Error | null, results?: LintResults) => void; export type LintCallback = (error: Error | null, results?: LintResults) => void;
/** /**
* Configuration object for linting rules. For the JSON schema, see * Configuration object for linting rules. For the JSON schema, see
* {@link ../schema/markdownlint-config-schema.json}. * {@link ../schema/markdownlint-config-schema.json}.
*/ */
type Configuration = import("./configuration").Configuration; export type Configuration = import("./configuration.d.ts").Configuration;
/** /**
* Configuration object for linting rules strictly. For the JSON schema, see * Configuration object for linting rules strictly. For the JSON schema, see
* {@link ../schema/markdownlint-config-schema-strict.json}. * {@link ../schema/markdownlint-config-schema-strict.json}.
*/ */
type ConfigurationStrict = import("./configuration-strict").ConfigurationStrict; export type ConfigurationStrict = import("./configuration-strict.d.ts").ConfigurationStrict;
/** /**
* Rule configuration. * Rule configuration.
*/ */
type RuleConfiguration = boolean | any; export type RuleConfiguration = boolean | any;
/** /**
* Parses a configuration string and returns a configuration object. * Parses a configuration string and returns a configuration object.
*/ */
type ConfigurationParser = (text: string) => Configuration; export type ConfigurationParser = (text: string) => Configuration;
/** /**
* Called with the result of the readConfig function. * Called with the result of the readConfig function.
*/ */
type ReadConfigCallback = (err: Error | null, config?: Configuration) => void; export type ReadConfigCallback = (err: Error | null, config?: Configuration) => void;
/** /**
* Called with the result of the resolveConfigExtends function. * Called with the result of the resolveConfigExtends function.
*/ */
type ResolveConfigExtendsCallback = (err: Error | null, path?: string) => void; 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. * Lint specified Markdown files.
* *
@ -524,3 +512,20 @@ declare function extendConfigPromise(config: Configuration, file: string, parser
* @returns {Promise<Configuration>} Configuration object. * @returns {Promise<Configuration>} Configuration object.
*/ */
declare function readConfigPromise(file: string, parsers?: ConfigurationParser[], fs?: any): Promise<Configuration>; 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

@ -1,19 +1,16 @@
// @ts-check // @ts-check
"use strict"; import * as nodeFs from "node:fs";
import { createRequire } from "node:module";
const path = require("node:path"); const dynamicRequire = createRequire(import.meta.url);
const { promisify } = require("node:util"); import * as os from "node:os";
const micromark = require("../helpers/micromark-parse.cjs"); import path from "node:path";
const { version } = require("./constants"); import { promisify } from "node:util";
const rules = require("./rules"); import { initialize as cacheInitialize } from "./cache.mjs";
const helpers = require("../helpers"); import { version } from "./constants.mjs";
const cache = require("./cache"); import rules from "./rules.mjs";
import { parse as micromarkParse } from "../helpers/micromark-parse.mjs";
// @ts-ignore import * as helpers from "../helpers/helpers.cjs";
// eslint-disable-next-line camelcase, no-inline-comments, no-undef
const dynamicRequire = (typeof __non_webpack_require__ === "undefined") ? require : /* c8 ignore next */ __non_webpack_require__;
// Capture native require implementation for dynamic loading of modules
/** /**
* Validate the list of rules for structure and reuse. * Validate the list of rules for structure and reuse.
@ -497,7 +494,7 @@ function lintContent(
); );
const customRulesPresent = (ruleList.length !== rules.length); const customRulesPresent = (ruleList.length !== rules.length);
// Parse content into parser tokens // Parse content into parser tokens
const micromarkTokens = micromark.parse( const micromarkTokens = micromarkParse(
content, content,
{ "freezeTokens": customRulesPresent } { "freezeTokens": customRulesPresent }
); );
@ -507,7 +504,7 @@ function lintContent(
// Parse content into lines and get markdown-it tokens // Parse content into lines and get markdown-it tokens
const lines = content.split(helpers.newLineRe); const lines = content.split(helpers.newLineRe);
const markdownitTokens = needMarkdownItTokens ? const markdownitTokens = needMarkdownItTokens ?
require("./markdownit.cjs").getMarkdownItTokens(markdownItPlugins, preClearedContent, lines) : dynamicRequire("./markdownit.cjs").getMarkdownItTokens(markdownItPlugins, preClearedContent, lines) :
[]; [];
// Create (frozen) parameters for rules // Create (frozen) parameters for rules
/** @type {MarkdownParsers} */ /** @type {MarkdownParsers} */
@ -533,7 +530,7 @@ function lintContent(
"lines": Object.freeze(lines), "lines": Object.freeze(lines),
"frontMatterLines": Object.freeze(frontMatterLines) "frontMatterLines": Object.freeze(frontMatterLines)
}; };
cache.initialize({ cacheInitialize({
...paramsBase, ...paramsBase,
"parsers": parsersMicromark, "parsers": parsersMicromark,
"config": null "config": null
@ -751,7 +748,7 @@ function lintContent(
} catch (error) { } catch (error) {
callbackError(error); callbackError(error);
} finally { } finally {
cache.initialize(); cacheInitialize();
} }
} }
@ -866,7 +863,7 @@ function lintInput(options, synchronous, callback) {
3 : 3 :
options.resultVersion; options.resultVersion;
const markdownItPlugins = options.markdownItPlugins || []; const markdownItPlugins = options.markdownItPlugins || [];
const fs = options.fs || require("node:fs"); const fs = options.fs || nodeFs;
const aliasToRuleNames = mapAliasToRuleNames(ruleList); const aliasToRuleNames = mapAliasToRuleNames(ruleList);
const results = newResults(ruleList); const results = newResults(ruleList);
let done = false; let done = false;
@ -1068,7 +1065,7 @@ function extendConfig(config, file, parsers, fs, callback) {
if (configExtends) { if (configExtends) {
return resolveConfigExtends( return resolveConfigExtends(
file, file,
helpers.expandTildePath(configExtends, require("node:os")), helpers.expandTildePath(configExtends, os),
fs, fs,
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
(_, resolvedExtends) => readConfig( (_, resolvedExtends) => readConfig(
@ -1132,10 +1129,10 @@ function readConfig(file, parsers, fs, callback) {
} }
} }
if (!fs) { if (!fs) {
fs = require("node:fs"); fs = nodeFs;
} }
// Read file // Read file
file = helpers.expandTildePath(file, require("node:os")); file = helpers.expandTildePath(file, os);
fs.readFile(file, "utf8", (err, content) => { fs.readFile(file, "utf8", (err, content) => {
if (err) { if (err) {
// @ts-ignore // @ts-ignore
@ -1180,10 +1177,9 @@ function readConfigPromise(file, parsers, fs) {
*/ */
function readConfigSync(file, parsers, fs) { function readConfigSync(file, parsers, fs) {
if (!fs) { if (!fs) {
fs = require("node:fs"); fs = nodeFs;
} }
// Read file // Read file
const os = require("node:os");
file = helpers.expandTildePath(file, os); file = helpers.expandTildePath(file, os);
const content = fs.readFileSync(file, "utf8"); const content = fs.readFileSync(file, "utf8");
// Try to parse file // Try to parse file
@ -1248,7 +1244,7 @@ function applyFix(line, fixInfo, lineEnding = "\n") {
* @returns {string} Fixed content. * @returns {string} Fixed content.
*/ */
function applyFixes(input, errors) { function applyFixes(input, errors) {
const lineEnding = helpers.getPreferredLineEnding(input, require("node:os")); const lineEnding = helpers.getPreferredLineEnding(input, os);
const lines = input.split(helpers.newLineRe); const lines = input.split(helpers.newLineRe);
// Normalize fixInfo objects // Normalize fixInfo objects
let fixInfos = errors let fixInfos = errors
@ -1267,8 +1263,7 @@ function applyFixes(input, errors) {
); );
}); });
// Remove duplicate entries (needed for following collapse step) // Remove duplicate entries (needed for following collapse step)
// eslint-disable-next-line jsdoc/valid-types /** @type {RuleOnErrorFixInfo} */
/** @type RuleOnErrorFixInfo */
let lastFixInfo = {}; let lastFixInfo = {};
fixInfos = fixInfos.filter((fixInfo) => { fixInfos = fixInfos.filter((fixInfo) => {
const unique = ( const unique = (
@ -1342,7 +1337,7 @@ markdownlint.promises = {
}; };
markdownlint.applyFix = applyFix; markdownlint.applyFix = applyFix;
markdownlint.applyFixes = applyFixes; markdownlint.applyFixes = applyFixes;
module.exports = markdownlint; export default markdownlint;
// Type declarations // Type declarations
@ -1414,7 +1409,7 @@ module.exports = markdownlint;
* @property {string} line Line content. * @property {string} line Line content.
*/ */
/** @typedef {import("markdownlint-micromark").TokenType} MicromarkTokenType */ /** @typedef {import("micromark-util-types").TokenType} MicromarkTokenType */
/** /**
* micromark token. * micromark token.
@ -1567,14 +1562,14 @@ module.exports = markdownlint;
* Configuration object for linting rules. For the JSON schema, see * Configuration object for linting rules. For the JSON schema, see
* {@link ../schema/markdownlint-config-schema.json}. * {@link ../schema/markdownlint-config-schema.json}.
* *
* @typedef {import("./configuration").Configuration} Configuration * @typedef {import("./configuration.d.ts").Configuration} Configuration
*/ */
/** /**
* Configuration object for linting rules strictly. For the JSON schema, see * Configuration object for linting rules strictly. For the JSON schema, see
* {@link ../schema/markdownlint-config-schema-strict.json}. * {@link ../schema/markdownlint-config-schema-strict.json}.
* *
* @typedef {import("./configuration-strict").ConfigurationStrict} ConfigurationStrict * @typedef {import("./configuration-strict.d.ts").ConfigurationStrict} ConfigurationStrict
*/ */
/** /**

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHeadingLevel } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD001", "heading-increment" ], "names": [ "MD001", "heading-increment" ],
"description": "Heading levels should only increment by one level at a time", "description": "Heading levels should only increment by one level at a time",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingStyle } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHeadingLevel, getHeadingStyle } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD003", "heading-style" ], "names": [ "MD003", "heading-style" ],
"description": "Heading style", "description": "Heading style",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getDescendantsByType, getParentOfType } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType, getParentOfType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const markerToStyle = { const markerToStyle = {
"-": "dash", "-": "dash",
@ -29,9 +27,8 @@ const validStyles = new Set([
"sublist" "sublist"
]); ]);
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD004", "ul-style" ], "names": [ "MD004", "ul-style" ],
"description": "Unordered list style", "description": "Unordered list style",
"tags": [ "bullet", "ul" ], "tags": [ "bullet", "ul" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addError, addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError, addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypesCached } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD005", "list-indent" ], "names": [ "MD005", "list-indent" ],
"description": "Inconsistent indentation for list items at the same level", "description": "Inconsistent indentation for list items at the same level",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],

View file

@ -1,23 +1,18 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("micromark-util-types").TokenType[]} */
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("markdownlint-micromark").TokenType[] */
const unorderedListTypes = const unorderedListTypes =
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ]; [ "blockQuotePrefix", "listItemPrefix", "listUnordered" ];
// eslint-disable-next-line jsdoc/valid-types /** @type {import("micromark-util-types").TokenType[]} */
/** @type import("markdownlint-micromark").TokenType[] */
const unorderedParentTypes = const unorderedParentTypes =
[ "blockQuote", "listOrdered", "listUnordered" ]; [ "blockQuote", "listOrdered", "listUnordered" ];
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD007", "ul-indent" ], "names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation", "description": "Unordered list indentation",
"tags": [ "bullet", "ul", "indentation" ], "tags": [ "bullet", "ul", "indentation" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addError } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD009", "no-trailing-spaces" ], "names": [ "MD009", "no-trailing-spaces" ],
"description": "Trailing spaces", "description": "Trailing spaces",
"tags": [ "whitespace" ], "tags": [ "whitespace" ],

View file

@ -1,16 +1,13 @@
// @ts-check // @ts-check
"use strict"; import { addError, hasOverlap } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addError, hasOverlap } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const tabRe = /\t+/g; const tabRe = /\t+/g;
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD010", "no-hard-tabs" ], "names": [ "MD010", "no-hard-tabs" ],
"description": "Hard tabs", "description": "Hard tabs",
"tags": [ "whitespace", "hard_tab" ], "tags": [ "whitespace", "hard_tab" ],
@ -26,8 +23,7 @@ module.exports = {
const spaceMultiplier = (spacesPerTab === undefined) ? const spaceMultiplier = (spacesPerTab === undefined) ?
1 : 1 :
Math.max(0, Number(spacesPerTab)); Math.max(0, Number(spacesPerTab));
// eslint-disable-next-line jsdoc/valid-types /** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
/** @type import("../helpers/micromark-helpers.cjs").TokenType[] */
const exclusionTypes = []; const exclusionTypes = [];
if (includeCode) { if (includeCode) {
if (ignoreCodeLanguages.size > 0) { if (ignoreCodeLanguages.size > 0) {
@ -60,7 +56,7 @@ module.exports = {
const lineNumber = lineIndex + 1; const lineNumber = lineIndex + 1;
const column = match.index + 1; const column = match.index + 1;
const length = match[0].length; const length = match[0].length;
/** @type {import("../helpers").FileRange} */ /** @type {import("../helpers/helpers.cjs").FileRange} */
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 }; const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
if (!codeRanges.some((codeRange) => hasOverlap(codeRange, range))) { if (!codeRanges.some((codeRange) => hasOverlap(codeRange, range))) {
addError( addError(

View file

@ -1,17 +1,13 @@
// @ts-check // @ts-check
"use strict"; import { addError, hasOverlap } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError, hasOverlap } = require("../helpers"); const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const reversedLinkRe = /** @type {import("./markdownlint.mjs").Rule} */
/(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g; export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD011", "no-reversed-links" ], "names": [ "MD011", "no-reversed-links" ],
"description": "Reversed link syntax", "description": "Reversed link syntax",
"tags": [ "links" ], "tags": [ "links" ],
@ -34,7 +30,7 @@ module.exports = {
) { ) {
const column = match.index + preChar.length + 1; const column = match.index + preChar.length + 1;
const length = match[0].length - preChar.length; const length = match[0].length - preChar.length;
/** @type {import("../helpers").FileRange} */ /** @type {import("../helpers/helpers.cjs").FileRange} */
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 }; const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) { if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) {
addError( addError(

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD012", "no-multiple-blanks" ], "names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines", "description": "Multiple consecutive blank lines",
"tags": [ "whitespace", "blank_lines" ], "tags": [ "whitespace", "blank_lines" ],

View file

@ -1,20 +1,19 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached, getReferenceLinkImageData } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); import { addRangeToSet, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { getReferenceLinkImageData } = require("./cache");
const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const longLineRePrefix = "^.{"; const longLineRePrefix = "^.{";
const longLineRePostfixRelaxed = "}.*\\s.*$"; const longLineRePostfixRelaxed = "}.*\\s.*$";
const longLineRePostfixStrict = "}.+$"; const longLineRePostfixStrict = "}.+$";
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/; const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
// eslint-disable-next-line jsdoc/valid-types /** @typedef {import("micromark-extension-gfm-autolink-literal")} */
/** @type import("./markdownlint").Rule */ /** @typedef {import("micromark-extension-gfm-table")} */
module.exports = {
/** @type {import("./markdownlint.mjs").Rule} */
export default {
"names": [ "MD013", "line-length" ], "names": [ "MD013", "line-length" ],
"description": "Line length", "description": "Line length",
"tags": [ "line_length" ], "tags": [ "line_length" ],

View file

@ -1,15 +1,12 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers");
const { filterByTypesCached } = require("./cache");
const dollarCommandRe = /^(\s*)(\$\s+)/; const dollarCommandRe = /^(\s*)(\$\s+)/;
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD014", "commands-show-output" ], "names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output", "description": "Dollar signs used before commands without showing output",
"tags": [ "code" ], "tags": [ "code" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD018", "no-missing-space-atx" ], "names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading", "description": "No space after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ], "tags": [ "headings", "atx", "spaces" ],

View file

@ -1,16 +1,14 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getHeadingStyle } from "../helpers/micromark-helpers.cjs";
const { addErrorContext } = require("../helpers/helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getHeadingStyle } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
/** /**
* Validate heading sequence and whitespace length at start or end. * Validate heading sequence and whitespace length at start or end.
* *
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. * @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("./markdownlint").MicromarkToken} heading ATX heading token. * @param {import("./markdownlint.mjs").MicromarkToken} heading ATX heading token.
* @param {number} delta Direction to scan. * @param {number} delta Direction to scan.
* @returns {void} * @returns {void}
*/ */
@ -47,9 +45,8 @@ function validateHeadingSpaces(onError, heading, delta) {
} }
} }
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule[]} */
/** @type import("./markdownlint").Rule[] */ export default [
module.exports = [
{ {
"names": [ "MD019", "no-multiple-space-atx" ], "names": [ "MD019", "no-multiple-space-atx" ],
"description": "Multiple spaces after hash on atx style heading", "description": "Multiple spaces after hash on atx style heading",

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD020", "no-missing-space-closed-atx" ], "names": [ "MD020", "no-missing-space-closed-atx" ],
"description": "No space inside hashes on closed atx style heading", "description": "No space inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ], "tags": [ "headings", "atx_closed", "spaces" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf, isBlankLine } from "../helpers/helpers.cjs";
import { getBlockQuotePrefixText, getHeadingLevel } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf, isBlankLine } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getBlockQuotePrefixText, getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const defaultLines = 1; const defaultLines = 1;
@ -21,9 +19,8 @@ const getLinesFunction = (linesParam) => {
return () => lines; return () => lines;
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD022", "blanks-around-headings" ], "names": [ "MD022", "blanks-around-headings" ],
"description": "Headings should be surrounded by blank lines", "description": "Headings should be surrounded by blank lines",
"tags": [ "headings", "blank_lines" ], "tags": [ "headings", "blank_lines" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypesCached } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD023", "heading-start-left" ], "names": [ "MD023", "heading-start-left" ],
"description": "Headings must start at the beginning of the line", "description": "Headings must start at the beginning of the line",
"tags": [ "headings", "spaces" ], "tags": [ "headings", "spaces" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD024", "no-duplicate-heading" ], "names": [ "MD024", "no-duplicate-heading" ],
"description": "Multiple headings with the same content", "description": "Multiple headings with the same content",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext, frontMatterHasTitle } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD025", "single-title", "single-h1" ], "names": [ "MD025", "single-title", "single-h1" ],
"description": "Multiple top-level headings in the same document", "description": "Multiple top-level headings in the same document",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
endOfLineHtmlEntityRe, escapeForRegExp } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe, /** @type {import("./markdownlint.mjs").Rule} */
endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD026", "no-trailing-punctuation" ], "names": [ "MD026", "no-trailing-punctuation" ],
"description": "Trailing punctuation in heading", "description": "Trailing punctuation in heading",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypesCached } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD027", "no-multiple-space-blockquote" ], "names": [ "MD027", "no-multiple-space-blockquote" ],
"description": "Multiple spaces after blockquote symbol", "description": "Multiple spaces after blockquote symbol",
"tags": [ "blockquote", "whitespace", "indentation" ], "tags": [ "blockquote", "whitespace", "indentation" ],

View file

@ -1,15 +1,12 @@
// @ts-check // @ts-check
"use strict"; import { addError } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError } = require("../helpers");
const { filterByTypesCached } = require("./cache");
const ignoreTypes = new Set([ "lineEnding", "listItemIndent", "linePrefix" ]); const ignoreTypes = new Set([ "lineEnding", "listItemIndent", "linePrefix" ]);
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD028", "no-blanks-blockquote" ], "names": [ "MD028", "no-blanks-blockquote" ],
"description": "Blank line inside blockquote", "description": "Blank line inside blockquote",
"tags": [ "blockquote", "whitespace" ], "tags": [ "blockquote", "whitespace" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const listStyleExamples = { const listStyleExamples = {
"one": "1/1/1", "one": "1/1/1",
@ -22,9 +20,8 @@ function getOrderedListItemValue(listItemPrefix) {
return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text); return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
} }
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD029", "ol-prefix" ], "names": [ "MD029", "ol-prefix" ],
"description": "Ordered list item prefix", "description": "Ordered list item prefix",
"tags": [ "ol" ], "tags": [ "ol" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypesCached } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD030", "list-marker-space" ], "names": [ "MD030", "list-marker-space" ],
"description": "Spaces after list markers", "description": "Spaces after list markers",
"tags": [ "ol", "ul", "whitespace" ], "tags": [ "ol", "ul", "whitespace" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
const { addErrorContext, isBlankLine } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const codeFencePrefixRe = /^(.*?)[`~]/; const codeFencePrefixRe = /^(.*?)[`~]/;
@ -14,7 +12,7 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
/** /**
* Adds an error for the top or bottom of a code fence. * Adds an error for the top or bottom of a code fence.
* *
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. * @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {ReadonlyStringArray} lines Lines of Markdown content. * @param {ReadonlyStringArray} lines Lines of Markdown content.
* @param {number} lineNumber Line number. * @param {number} lineNumber Line number.
* @param {boolean} top True iff top fence. * @param {boolean} top True iff top fence.
@ -24,7 +22,7 @@ function addError(onError, lines, lineNumber, top) {
const line = lines[lineNumber - 1]; const line = lines[lineNumber - 1];
const [ , prefix ] = line.match(codeFencePrefixRe) || []; const [ , prefix ] = line.match(codeFencePrefixRe) || [];
const fixInfo = (prefix === undefined) ? const fixInfo = (prefix === undefined) ?
null : undefined :
{ {
"lineNumber": lineNumber + (top ? 0 : 1), "lineNumber": lineNumber + (top ? 0 : 1),
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n` "insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
@ -40,9 +38,8 @@ function addError(onError, lines, lineNumber, top) {
); );
} }
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD031", "blanks-around-fences" ], "names": [ "MD031", "blanks-around-fences" ],
"description": "Fenced code blocks should be surrounded by blank lines", "description": "Fenced code blocks should be surrounded by blank lines",
"tags": [ "code", "blank_lines" ], "tags": [ "code", "blank_lines" ],

View file

@ -1,18 +1,15 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
import { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } from "../helpers/micromark-helpers.cjs";
const { addErrorContext, isBlankLine } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const isList = (token) => ( const isList = (token) => (
(token.type === "listOrdered") || (token.type === "listUnordered") (token.type === "listOrdered") || (token.type === "listUnordered")
); );
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD032", "blanks-around-lists" ], "names": [ "MD032", "blanks-around-lists" ],
"description": "Lists should be surrounded by blank lines", "description": "Lists should be surrounded by blank lines",
"tags": [ "bullet", "ul", "ol", "blank_lines" ], "tags": [ "bullet", "ul", "ol", "blank_lines" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addError, nextLinesRe } from "../helpers/helpers.cjs";
import { getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError, nextLinesRe } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD033", "no-inline-html" ], "names": [ "MD033", "no-inline-html" ],
"description": "Inline HTML", "description": "Inline HTML",
"tags": [ "html" ], "tags": [ "html" ],

View file

@ -1,13 +1,12 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByPredicate, getHtmlTagInfo, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
const { addErrorContext } = require("../helpers"); /** @typedef {import("micromark-extension-gfm-autolink-literal")} */
const { filterByPredicate, getHtmlTagInfo, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD034", "no-bare-urls" ], "names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used", "description": "Bare URL used",
"tags": [ "links", "url" ], "tags": [ "links", "url" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypesCached } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD035", "hr-style" ], "names": [ "MD035", "hr-style" ],
"description": "Horizontal rule style", "description": "Horizontal rule style",
"tags": [ "hr" ], "tags": [ "hr" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, allPunctuation } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addErrorContext, allPunctuation } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
/** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */ /** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */
/** @type {TokenType[][]} */ /** @type {TokenType[][]} */
@ -13,9 +11,8 @@ const emphasisTypes = [
[ "strong", "strongText" ] [ "strong", "strongText" ]
]; ];
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD036", "no-emphasis-as-heading" ], "names": [ "MD036", "no-emphasis-as-heading" ],
"description": "Emphasis used instead of a heading", "description": "Emphasis used instead of a heading",
"tags": [ "headings", "emphasis" ], "tags": [ "headings", "emphasis" ],

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addError } from "../helpers/helpers.cjs";
import { filterByPredicate, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
const { addError } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark-helpers.cjs"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD037", "no-space-in-emphasis" ], "names": [ "MD037", "no-space-in-emphasis" ],
"description": "Spaces inside emphasis markers", "description": "Spaces inside emphasis markers",
"tags": [ "whitespace", "emphasis" ], "tags": [ "whitespace", "emphasis" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addErrorContext } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const leftSpaceRe = /^\s(?:[^`]|$)/; const leftSpaceRe = /^\s(?:[^`]|$)/;
const rightSpaceRe = /[^`]\s$/; const rightSpaceRe = /[^`]\s$/;
@ -19,9 +17,8 @@ const trimCodeText = (text, start, end) => {
return text; return text;
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD038", "no-space-in-code" ], "names": [ "MD038", "no-space-in-code" ],
"description": "Spaces inside code span elements", "description": "Spaces inside code span elements",
"tags": [ "whitespace", "code" ], "tags": [ "whitespace", "code" ],

View file

@ -1,14 +1,12 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers");
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
/** /**
* Adds an error for a label space issue. * Adds an error for a label space issue.
* *
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. * @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} label Label token.
* @param {import("../helpers/micromark-helpers.cjs").Token} labelText LabelText token. * @param {import("../helpers/micromark-helpers.cjs").Token} labelText LabelText token.
* @param {boolean} isStart True iff error is at the start of the link. * @param {boolean} isStart True iff error is at the start of the link.
@ -49,9 +47,8 @@ function validLink(label, labelText, definitions) {
return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim()); return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim());
} }
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD039", "no-space-in-links" ], "names": [ "MD039", "no-space-in-links" ],
"description": "Spaces inside link text", "description": "Spaces inside link text",
"tags": [ "whitespace", "links" ], "tags": [ "whitespace", "links" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addError, addErrorContext } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addError, addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD040", "fenced-code-language" ], "names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified", "description": "Fenced code blocks should have a language specified",
"tags": [ "code", "language" ], "tags": [ "code", "language" ],

View file

@ -1,14 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
import { filterByTypes, getHeadingLevel, getHtmlTagInfo, isHtmlFlowComment, nonContentTokens } from "../helpers/micromark-helpers.cjs";
const { addErrorContext, frontMatterHasTitle } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { filterByTypes, getHeadingLevel, getHtmlTagInfo, isHtmlFlowComment, nonContentTokens } = export default {
require("../helpers/micromark-helpers.cjs");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD041", "first-line-heading", "first-line-h1" ], "names": [ "MD041", "first-line-heading", "first-line-h1" ],
"description": "First line in a file should be a top-level heading", "description": "First line in a file should be a top-level heading",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
const { addErrorContext } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs"); export default {
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD042", "no-empty-links" ], "names": [ "MD042", "no-empty-links" ],
"description": "No empty links", "description": "No empty links",
"tags": [ "links" ], "tags": [ "links" ],

View file

@ -1,14 +1,11 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext, addErrorDetailIf } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs"); export default {
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD043", "required-headings" ], "names": [ "MD043", "required-headings" ],
"description": "Required heading structure", "description": "Required heading structure",
"tags": [ "headings" ], "tags": [ "headings" ],

View file

@ -1,18 +1,15 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf, escapeForRegExp, hasOverlap } from "../helpers/helpers.cjs";
import { filterByPredicate, filterByTypes } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf, escapeForRegExp, hasOverlap } = require("../helpers"); import { parse } from "../helpers/micromark-parse.mjs";
const { filterByPredicate, filterByTypes } = require("../helpers/micromark-helpers.cjs");
const { parse } = require("../helpers/micromark-parse.cjs");
const ignoredChildTypes = new Set( const ignoredChildTypes = new Set(
[ "codeFencedFence", "definition", "reference", "resource" ] [ "codeFencedFence", "definition", "reference", "resource" ]
); );
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD044", "proper-names" ], "names": [ "MD044", "proper-names" ],
"description": "Proper names should have the correct capitalization", "description": "Proper names should have the correct capitalization",
"tags": [ "spelling" ], "tags": [ "spelling" ],
@ -48,7 +45,7 @@ module.exports = {
token.children.filter((t) => !ignoredChildTypes.has(t.type)) token.children.filter((t) => !ignoredChildTypes.has(t.type))
) )
); );
/** @type {import("../helpers").FileRange[]} */ /** @type {import("../helpers/helpers.cjs").FileRange[]} */
const exclusions = []; const exclusions = [];
const scannedTokens = new Set(); const scannedTokens = new Set();
for (const name of names) { for (const name of names) {
@ -64,7 +61,7 @@ module.exports = {
const column = token.startColumn + match.index + leftMatch.length; const column = token.startColumn + match.index + leftMatch.length;
const length = nameMatch.length; const length = nameMatch.length;
const lineNumber = token.startLine; const lineNumber = token.startLine;
/** @type {import("../helpers").FileRange} */ /** @type {import("../helpers/helpers.cjs").FileRange} */
const nameRange = { const nameRange = {
"startLine": lineNumber, "startLine": lineNumber,
"startColumn": column, "startColumn": column,
@ -75,7 +72,7 @@ module.exports = {
!names.includes(nameMatch) && !names.includes(nameMatch) &&
!exclusions.some((exclusion) => hasOverlap(exclusion, nameRange)) !exclusions.some((exclusion) => hasOverlap(exclusion, nameRange))
) { ) {
/** @type {import("../helpers").FileRange[]} */ /** @type {import("../helpers/helpers.cjs").FileRange[]} */
let autolinkRanges = []; let autolinkRanges = [];
if (!scannedTokens.has(token)) { if (!scannedTokens.has(token)) {
autolinkRanges = filterByTypes(parse(token.text), [ "literalAutolink" ]) autolinkRanges = filterByTypes(parse(token.text), [ "literalAutolink" ])

View file

@ -1,16 +1,13 @@
// @ts-check // @ts-check
"use strict"; import { addError, getHtmlAttributeRe, nextLinesRe } from "../helpers/helpers.cjs";
import { getHtmlTagInfo, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getHtmlTagInfo, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const altRe = getHtmlAttributeRe("alt"); const altRe = getHtmlAttributeRe("alt");
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD045", "no-alt-text" ], "names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)", "description": "Images should have alternate text (alt text)",
"tags": [ "accessibility", "images" ], "tags": [ "accessibility", "images" ],

View file

@ -1,18 +1,15 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers");
const { filterByTypesCached } = require("./cache");
const tokenTypeToStyle = { const tokenTypeToStyle = {
"codeFenced": "fenced", "codeFenced": "fenced",
"codeIndented": "indented" "codeIndented": "indented"
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD046", "code-block-style" ], "names": [ "MD046", "code-block-style" ],
"description": "Code block style", "description": "Code block style",
"tags": [ "code" ], "tags": [ "code" ],

View file

@ -1,12 +1,9 @@
// @ts-check // @ts-check
"use strict"; import { addError, isBlankLine } from "../helpers/helpers.cjs";
const { addError, isBlankLine } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD047", "single-trailing-newline" ], "names": [ "MD047", "single-trailing-newline" ],
"description": "Files should end with a single newline character", "description": "Files should end with a single newline character",
"tags": [ "blank_lines" ], "tags": [ "blank_lines" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
/** /**
* Return the string representation of a fence markup character. * Return the string representation of a fence markup character.
@ -21,9 +19,8 @@ function fencedCodeBlockStyleFor(markup) {
} }
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD048", "code-fence-style" ], "names": [ "MD048", "code-fence-style" ],
"description": "Code fence style", "description": "Code fence style",
"tags": [ "code" ], "tags": [ "code" ],

View file

@ -1,9 +1,7 @@
// @ts-check // @ts-check
"use strict"; import { addError } from "../helpers/helpers.cjs";
import { filterByPredicate, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addError } = require("../helpers");
const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const intrawordRe = /^\w$/; const intrawordRe = /^\w$/;
@ -23,10 +21,10 @@ function emphasisOrStrongStyleFor(markup) {
}; };
/** /**
* @param {import("./markdownlint").RuleParams} params Rule parameters. * @param {import("./markdownlint.mjs").RuleParams} params Rule parameters.
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. * @param {import("./markdownlint.mjs").RuleOnError} onError Error-reporting callback.
* @param {import("markdownlint-micromark").TokenType} type Token type. * @param {import("micromark-util-types").TokenType} type Token type.
* @param {import("markdownlint-micromark").TokenType} typeSequence Token sequence type. * @param {import("micromark-util-types").TokenType} typeSequence Token sequence type.
* @param {"*" | "**"} asterisk Asterisk kind. * @param {"*" | "**"} asterisk Asterisk kind.
* @param {"_" | "__"} underline Underline kind. * @param {"_" | "__"} underline Underline kind.
* @param {"asterisk" | "consistent" | "underscore"} style Style string. * @param {"asterisk" | "consistent" | "underscore"} style Style string.
@ -78,9 +76,8 @@ const impl =
} }
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule[]} */
/** @type import("./markdownlint").Rule[] */ export default [
module.exports = [
{ {
"names": [ "MD049", "emphasis-style" ], "names": [ "MD049", "emphasis-style" ],
"description": "Emphasis style", "description": "Emphasis style",

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addError, getHtmlAttributeRe } from "../helpers/helpers.cjs";
import { filterByPredicate, filterByTypes, getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
const { addError, getHtmlAttributeRe } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { filterByPredicate, filterByTypes, getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
// Regular expression for identifying HTML anchor names // Regular expression for identifying HTML anchor names
const idRe = getHtmlAttributeRe("id"); const idRe = getHtmlAttributeRe("id");
@ -60,9 +58,8 @@ function unescapeStringTokenText(token) {
.join(""); .join("");
} }
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD051", "link-fragments" ], "names": [ "MD051", "link-fragments" ],
"description": "Link fragments should be valid", "description": "Link fragments should be valid",
"tags": [ "links" ], "tags": [ "links" ],
@ -104,8 +101,7 @@ module.exports = {
} }
// Process link and definition fragments // Process link and definition fragments
// eslint-disable-next-line jsdoc/valid-types /** @type {import("../helpers/micromark-helpers.cjs").TokenType[][]} */
/** @type import("../helpers/micromark-helpers.cjs").TokenType[][] */
const parentChilds = [ const parentChilds = [
[ "link", "resourceDestinationString" ], [ "link", "resourceDestinationString" ],
[ "definition", "definitionDestinationString" ] [ "definition", "definitionDestinationString" ]

View file

@ -1,13 +1,10 @@
// @ts-check // @ts-check
"use strict"; import { addError } from "../helpers/helpers.cjs";
import { getReferenceLinkImageData } from "./cache.mjs";
const { addError } = require("../helpers"); /** @type {import("./markdownlint.mjs").Rule} */
const { getReferenceLinkImageData } = require("./cache"); export default {
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD052", "reference-links-images" ], "names": [ "MD052", "reference-links-images" ],
"description": "description":
"Reference links and images should use a label that is defined", "Reference links and images should use a label that is defined",

View file

@ -1,15 +1,12 @@
// @ts-check // @ts-check
"use strict"; import { addError, ellipsify } from "../helpers/helpers.cjs";
import { getReferenceLinkImageData } from "./cache.mjs";
const { addError, ellipsify } = require("../helpers");
const { getReferenceLinkImageData } = require("./cache");
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/; const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD053", "link-image-reference-definitions" ], "names": [ "MD053", "link-image-reference-definitions" ],
"description": "Link and image reference definitions should be needed", "description": "Link and image reference definitions should be needed",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],

View file

@ -1,10 +1,8 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, nextLinesRe } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
const { addErrorContext, nextLinesRe } = require("../helpers"); import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
const backslashEscapeRe = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g; const backslashEscapeRe = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
const removeBackslashEscapes = (text) => text.replace(backslashEscapeRe, "$1"); const removeBackslashEscapes = (text) => text.replace(backslashEscapeRe, "$1");
@ -20,9 +18,8 @@ const autolinkAble = (destination) => {
return !autolinkDisallowedRe.test(destination); return !autolinkDisallowedRe.test(destination);
}; };
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD054", "link-image-style" ], "names": [ "MD054", "link-image-style" ],
"description": "Link and image style", "description": "Link and image style",
"tags": [ "images", "links" ], "tags": [ "images", "links" ],

View file

@ -1,9 +1,7 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorDetailIf } = require("../helpers");
const { filterByTypesCached } = require("./cache");
const whitespaceTypes = new Set([ "linePrefix", "whitespace" ]); const whitespaceTypes = new Set([ "linePrefix", "whitespace" ]);
const ignoreWhitespace = (tokens) => tokens.filter( const ignoreWhitespace = (tokens) => tokens.filter(
@ -13,9 +11,10 @@ const firstOrNothing = (items) => items[0];
const lastOrNothing = (items) => items[items.length - 1]; const lastOrNothing = (items) => items[items.length - 1];
const makeRange = (start, end) => [ start, end - start + 1 ]; const makeRange = (start, end) => [ start, end - start + 1 ];
// eslint-disable-next-line jsdoc/valid-types /** @typedef {import("micromark-extension-gfm-table")} */
/** @type import("./markdownlint").Rule */
module.exports = { /** @type {import("./markdownlint.mjs").Rule} */
export default {
"names": [ "MD055", "table-pipe-style" ], "names": [ "MD055", "table-pipe-style" ],
"description": "Table pipe style", "description": "Table pipe style",
"tags": [ "table" ], "tags": [ "table" ],

View file

@ -1,16 +1,15 @@
// @ts-check // @ts-check
"use strict"; import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
const { addErrorDetailIf } = require("../helpers"); import { filterByTypesCached } from "./cache.mjs";
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const makeRange = (start, end) => [ start, end - start + 1 ]; const makeRange = (start, end) => [ start, end - start + 1 ];
// eslint-disable-next-line jsdoc/valid-types /** @typedef {import("micromark-extension-gfm-table")} */
/** @type import("./markdownlint").Rule */
module.exports = { /** @type {import("./markdownlint.mjs").Rule} */
export default {
"names": [ "MD056", "table-column-count" ], "names": [ "MD056", "table-column-count" ],
"description": "Table column count", "description": "Table column count",
"tags": [ "table" ], "tags": [ "table" ],

View file

@ -1,14 +1,13 @@
// @ts-check // @ts-check
"use strict"; import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
import { getBlockQuotePrefixText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
const { addErrorContext, isBlankLine } = require("../helpers"); /** @typedef {import("micromark-extension-gfm-table")} */
const { getBlockQuotePrefixText } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types /** @type {import("./markdownlint.mjs").Rule} */
/** @type import("./markdownlint").Rule */ export default {
module.exports = {
"names": [ "MD058", "blanks-around-tables" ], "names": [ "MD058", "blanks-around-tables" ],
"description": "Tables should be surrounded by blank lines", "description": "Tables should be surrounded by blank lines",
"tags": [ "table" ], "tags": [ "table" ],

View file

@ -1,74 +0,0 @@
// @ts-check
"use strict";
const { homepage, version } = require("./constants");
// @ts-ignore
const [ md019, md021 ] = require("./md019-md021");
// @ts-ignore
const [ md049, md050 ] = require("./md049-md050");
const rules = [
require("./md001"),
// md002: Deprecated and removed
require("./md003"),
require("./md004"),
require("./md005"),
// md006: Deprecated and removed
require("./md007"),
require("./md009"),
require("./md010"),
require("./md011"),
require("./md012"),
require("./md013"),
require("./md014"),
require("./md018"),
md019,
require("./md020"),
md021,
require("./md022"),
require("./md023"),
require("./md024"),
require("./md025"),
require("./md026"),
require("./md027"),
require("./md028"),
require("./md029"),
require("./md030"),
require("./md031"),
require("./md032"),
require("./md033"),
require("./md034"),
require("./md035"),
require("./md036"),
require("./md037"),
require("./md038"),
require("./md039"),
require("./md040"),
require("./md041"),
require("./md042"),
require("./md043"),
require("./md044"),
require("./md045"),
require("./md046"),
require("./md047"),
require("./md048"),
md049,
md050,
require("./md051"),
require("./md052"),
require("./md053"),
require("./md054"),
require("./md055"),
require("./md056"),
// md057: See https://github.com/markdownlint/markdownlint
require("./md058")
];
for (const rule of rules) {
const name = rule.names[0].toLowerCase();
// eslint-disable-next-line dot-notation
rule["information"] =
new URL(`${homepage}/blob/v${version}/doc/${name}.md`);
}
module.exports = rules;

118
lib/rules.mjs Normal file
View file

@ -0,0 +1,118 @@
// @ts-check
import { homepage, version } from "./constants.mjs";
import md001 from "./md001.mjs";
import md003 from "./md003.mjs";
import md004 from "./md004.mjs";
import md005 from "./md005.mjs";
import md007 from "./md007.mjs";
import md009 from "./md009.mjs";
import md010 from "./md010.mjs";
import md011 from "./md011.mjs";
import md012 from "./md012.mjs";
import md013 from "./md013.mjs";
import md014 from "./md014.mjs";
import md018 from "./md018.mjs";
import md019md021 from "./md019-md021.mjs";
const [ md019, md021 ] = md019md021;
import md020 from "./md020.mjs";
import md022 from "./md022.mjs";
import md023 from "./md023.mjs";
import md024 from "./md024.mjs";
import md025 from "./md025.mjs";
import md026 from "./md026.mjs";
import md027 from "./md027.mjs";
import md028 from "./md028.mjs";
import md029 from "./md029.mjs";
import md030 from "./md030.mjs";
import md031 from "./md031.mjs";
import md032 from "./md032.mjs";
import md033 from "./md033.mjs";
import md034 from "./md034.mjs";
import md035 from "./md035.mjs";
import md036 from "./md036.mjs";
import md037 from "./md037.mjs";
import md038 from "./md038.mjs";
import md039 from "./md039.mjs";
import md040 from "./md040.mjs";
import md041 from "./md041.mjs";
import md042 from "./md042.mjs";
import md043 from "./md043.mjs";
import md044 from "./md044.mjs";
import md045 from "./md045.mjs";
import md046 from "./md046.mjs";
import md047 from "./md047.mjs";
import md048 from "./md048.mjs";
import md049md050 from "./md049-md050.mjs";
const [ md049, md050 ] = md049md050;
import md051 from "./md051.mjs";
import md052 from "./md052.mjs";
import md053 from "./md053.mjs";
import md054 from "./md054.mjs";
import md055 from "./md055.mjs";
import md056 from "./md056.mjs";
import md058 from "./md058.mjs";
const rules = [
md001,
// md002: Deprecated and removed
md003,
md004,
md005,
// md006: Deprecated and removed
md007,
md009,
md010,
md011,
md012,
md013,
md014,
md018,
md019,
md020,
md021,
md022,
md023,
md024,
md025,
md026,
md027,
md028,
md029,
md030,
md031,
md032,
md033,
md034,
md035,
md036,
md037,
md038,
md039,
md040,
md041,
md042,
md043,
md044,
md045,
md046,
md047,
md048,
md049,
md050,
md051,
md052,
md053,
md054,
md055,
md056,
// md057: See https://github.com/markdownlint/markdownlint
md058
];
for (const rule of rules) {
const name = rule.names[0].toLowerCase();
// eslint-disable-next-line dot-notation
rule["information"] = new URL(`${homepage}/blob/v${version}/doc/${name}.md`);
}
export default rules;

View file

@ -1,6 +0,0 @@
exports.mjs
exports-html.mjs
micromark.dev.cjs
micromark-browser.dev.js
micromark-html-browser.dev.js
webpack.config.js

View file

@ -1,2 +0,0 @@
ignore-scripts=true
package-lock=false

View file

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) David Anson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,10 +0,0 @@
# markdownlint-micromark
> A trivial package that re-exports some [`micromark`][micromark] functionality
> as a CommonJS module
This package is unlikely to be of any use beyond a specific scenario used by
[`markdownlint`][markdownlint].
[markdownlint]: https://github.com/DavidAnson/markdownlint
[micromark]: https://github.com/micromark/micromark

View file

@ -1,40 +0,0 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/types.d.ts",
"bundledPackages": [ "*" ],
"newlineKind": "os",
"compiler": {
"overrideTsconfig": {}
},
"apiReport": {
"enabled": false
},
"docModel": {
"enabled": false
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/micromark.d.cts"
},
"tsdocMetadata": {
"enabled": false
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
}
}
}
}

View file

@ -1,10 +0,0 @@
// @ts-check
/* eslint-disable n/no-missing-import */
export { compile } from "micromark";
export { directiveHtml } from "micromark-extension-directive";
export { gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal";
export { gfmFootnoteHtml } from "micromark-extension-gfm-footnote";
export { gfmTableHtml } from "micromark-extension-gfm-table";
export { mathHtml } from "micromark-extension-math";

View file

@ -1,14 +0,0 @@
// @ts-check
/* eslint-disable n/no-missing-import */
export { directive } from "micromark-extension-directive";
export { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
export { gfmFootnote } from "micromark-extension-gfm-footnote";
export { gfmTable } from "micromark-extension-gfm-table";
export { math } from "micromark-extension-math";
export { parse } from "micromark";
export { postprocess } from "micromark";
export { preprocess } from "micromark";
// micromark-core-commonmark is not a dev/dependency because this instance must match what's used by micromark
export { labelEnd } from "micromark-core-commonmark";

File diff suppressed because it is too large Load diff

View file

@ -1,46 +0,0 @@
{
"name": "markdownlint-micromark",
"version": "0.1.12",
"description": "A trivial package that re-exports some micromark functionality as a CommonJS module",
"type": "commonjs",
"exports": "./micromark.cjs",
"types": "./micromark.d.cts",
"author": "David Anson (https://dlaa.me/)",
"license": "MIT",
"homepage": "https://github.com/DavidAnson/markdownlint",
"repository": {
"type": "git",
"url": "git+https://github.com/DavidAnson/markdownlint.git"
},
"bugs": "https://github.com/DavidAnson/markdownlint/issues",
"funding": "https://github.com/sponsors/DavidAnson",
"scripts": {
"build": "webpack --stats minimal",
"types": "api-extractor run --local"
},
"engines": {
"node": ">=18"
},
"files": [
"LICENSE",
"micromark-browser.js",
"micromark-html-browser.js",
"micromark.cjs",
"micromark.d.cts",
"package.json",
"README.md"
],
"devDependencies": {
"@microsoft/api-extractor": "7.48.0",
"micromark": "4.0.1",
"micromark-extension-directive": "3.0.2",
"micromark-extension-gfm-autolink-literal": "2.1.0",
"micromark-extension-gfm-footnote": "2.1.0",
"micromark-extension-gfm-table": "2.1.0",
"micromark-extension-math": "3.1.0",
"micromark-util-types": "2.0.1",
"terser-webpack-plugin": "5.3.10",
"webpack": "5.96.1",
"webpack-cli": "5.1.4"
}
}

34
micromark/types.d.ts vendored
View file

@ -1,34 +0,0 @@
// Manually update due to api-extractor limitations including:
// - https://github.com/microsoft/rushstack/issues/1709
// - ERROR: Failed to fetch entity for import() type node: import('micromark-util-types').ParseContext
// - Unwillingness to treat "katex" as one of bundledPackages
//
// 1. npm install
// 2. Comment-out micromark-util-types/ParseContext in micromark/node_modules/micromark-extension-gfm-footnote/index.d.ts
// 3. npm run types
// 4. Remove "import type { KatexOptions } from 'katex';" in micromark/micromark.d.cts
// 5. Replace "KatexOptions" with "Object" in micromark/micromark.d.cts
// 6. Append "declare module 'micromark-util-types' { interface TokenTypeMap { ... } }" in micromark/micromark.d.cts from:
// - micromark/node_modules/micromark-extension-directive/index.d.ts
// - micromark/node_modules/micromark-extension-gfm-autolink-literal/index.d.ts
// - micromark/node_modules/micromark-extension-gfm-footnote/index.d.ts
// - micromark/node_modules/micromark-extension-gfm-table/index.d.ts
// - micromark/node_modules/micromark-extension-math/index.d.ts
// - export declare interface TokenTypeMap {
// undefinedReference: 'undefinedReference'
// undefinedReferenceCollapsed: 'undefinedReferenceCollapsed'
// undefinedReferenceFull: 'undefinedReferenceFull'
// undefinedReferenceShortcut: 'undefinedReferenceShortcut'
// }
// 7. Update version number in package.json and stage changes
// 8. Test: npm run build, npm pack, npm install ./micromark/markdownlint-micromark-0.1.11.tgz, npm run ci, verify types like gfmFootnote* in getReferenceLinkImageData(...)
// 9. Publish: git clean -dfx, npm install, npm run build, npm publish ., git push
export type { directive, directiveHtml } from "micromark-extension-directive";
export type { gfmAutolinkLiteral, gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal";
export type { gfmFootnote, gfmFootnoteHtml } from "micromark-extension-gfm-footnote";
export type { gfmTable, gfmTableHtml } from "micromark-extension-gfm-table";
export type { math, mathHtml } from "micromark-extension-math";
export type { compile, parse, postprocess, preprocess } from "micromark";
export type { CompileData, Construct, Event, ParseOptions, State, Token, TokenType, TokenTypeMap, Tokenizer } from "micromark-util-types";

View file

@ -1,127 +0,0 @@
// @ts-check
"use strict";
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const { name, version, homepage } = require("./package.json");
const htmlEntry = "./exports-html.mjs";
const htmlName = "micromarkHtmlBrowser";
const base = {
"entry": "./exports.mjs",
"output": {
"path": __dirname
},
"plugins": [
new webpack.BannerPlugin({
"banner": `${name} ${version} ${homepage}`
})
]
};
const commonjs = {
...base,
"output": {
...base.output,
"library": {
"type": "commonjs"
}
},
"target": "node"
};
const web = {
...base,
"output": {
...base.output,
"library": {
"name": "micromarkBrowser",
"type": "var"
}
},
"target": "web"
};
const production = {
"mode": "production",
"optimization": {
"minimizer": [
new TerserPlugin({
"extractComments": false,
"terserOptions": {
"compress": {
"passes": 2
}
}
})
]
}
};
const development = {
"devtool": false,
"mode": "development"
};
module.exports = [
{
...commonjs,
...production,
"output": {
...commonjs.output,
"filename": "micromark.cjs"
}
},
{
...commonjs,
...development,
"output": {
...commonjs.output,
"filename": "micromark.dev.cjs"
}
},
{
...web,
...production,
"output": {
...web.output,
"filename": "micromark-browser.js"
}
},
{
...web,
...development,
"output": {
...web.output,
"filename": "micromark-browser.dev.js"
}
},
{
...web,
...production,
"entry": htmlEntry,
"output": {
...web.output,
"library": {
...web.output.library,
"name": htmlName
},
"filename": "micromark-html-browser.js"
}
},
{
...web,
...development,
"entry": htmlEntry,
"output": {
...web.output,
"library": {
...web.output.library,
"name": htmlName
},
"filename": "micromark-html-browser.dev.js"
}
}
];

View file

@ -2,17 +2,16 @@
"name": "markdownlint", "name": "markdownlint",
"version": "0.36.1", "version": "0.36.1",
"description": "A Node.js style checker and lint tool for Markdown/CommonMark files.", "description": "A Node.js style checker and lint tool for Markdown/CommonMark files.",
"type": "commonjs", "type": "module",
"main": "./lib/markdownlint.js",
"exports": { "exports": {
".": "./lib/markdownlint.js", ".": "./lib/markdownlint.mjs",
"./helpers": "./helpers/helpers.js", "./helpers": "./helpers/helpers.cjs",
"./style/all": "./style/all.json", "./style/all": "./style/all.json",
"./style/cirosantilli": "./style/cirosantilli.json", "./style/cirosantilli": "./style/cirosantilli.json",
"./style/prettier": "./style/prettier.json", "./style/prettier": "./style/prettier.json",
"./style/relaxed": "./style/relaxed.json" "./style/relaxed": "./style/relaxed.json"
}, },
"types": "./lib/markdownlint.d.ts", "types": "./lib/markdownlint.d.mts",
"author": "David Anson (https://dlaa.me/)", "author": "David Anson (https://dlaa.me/)",
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/DavidAnson/markdownlint", "homepage": "https://github.com/DavidAnson/markdownlint",
@ -24,13 +23,12 @@
"funding": "https://github.com/sponsors/DavidAnson", "funding": "https://github.com/sponsors/DavidAnson",
"scripts": { "scripts": {
"build-config": "npm run build-config-schema && npm run build-config-example", "build-config": "npm run build-config-schema && npm run build-config-example",
"build-config-example": "node schema/build-config-example.js", "build-config-example": "node schema/build-config-example.mjs",
"build-config-schema": "node schema/build-config-schema.js", "build-config-schema": "node schema/build-config-schema.mjs",
"build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --outDir dts --resolveJsonModule --target es2015 lib/markdownlint.js && node scripts copy dts/lib/markdownlint.d.ts lib/markdownlint.d.ts && node scripts remove dts", "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-demo": "node scripts copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && node scripts copy node_modules/markdownlint-micromark/micromark-browser.js demo/micromark-browser.js && node scripts copy node_modules/markdownlint-micromark/micromark-html-browser.js demo/micromark-html-browser.js && cd demo && webpack --no-stats", "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-docs": "node doc-build/build-rules.mjs",
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2", "build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
"build-micromark": "cd micromark && npm run build",
"ci": "npm-run-all --continue-on-error --parallel lint serial-config-docs serial-declaration-demo test-cover && git diff --exit-code", "ci": "npm-run-all --continue-on-error --parallel lint serial-config-docs serial-declaration-demo test-cover && git diff --exit-code",
"clone-test-repos-apache-airflow": "cd test-repos && git clone https://github.com/apache/airflow apache-airflow --depth 1 --no-tags --quiet", "clone-test-repos-apache-airflow": "cd test-repos && git clone https://github.com/apache/airflow apache-airflow --depth 1 --no-tags --quiet",
"clone-test-repos-dotnet-docs": "cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet", "clone-test-repos-dotnet-docs": "cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet",
@ -45,20 +43,17 @@
"clone-test-repos-webpack-webpack-js-org": "cd test-repos && git clone https://github.com/webpack/webpack.js.org webpack-webpack-js-org --depth 1 --no-tags --quiet", "clone-test-repos-webpack-webpack-js-org": "cd test-repos && git clone https://github.com/webpack/webpack.js.org webpack-webpack-js-org --depth 1 --no-tags --quiet",
"clone-test-repos": "mkdir test-repos && cd test-repos && npm run clone-test-repos-apache-airflow && npm run clone-test-repos-dotnet-docs && npm run clone-test-repos-electron-electron && npm run clone-test-repos-eslint-eslint && npm run clone-test-repos-mdn-content && npm run clone-test-repos-mkdocs-mkdocs && npm run clone-test-repos-mochajs-mocha && npm run clone-test-repos-pi-hole-docs && npm run clone-test-repos-v8-v8-dev && npm run clone-test-repos-webhintio-hint && npm run clone-test-repos-webpack-webpack-js-org", "clone-test-repos": "mkdir test-repos && cd test-repos && npm run clone-test-repos-apache-airflow && npm run clone-test-repos-dotnet-docs && npm run clone-test-repos-electron-electron && npm run clone-test-repos-eslint-eslint && npm run clone-test-repos-mdn-content && npm run clone-test-repos-mkdocs-mkdocs && npm run clone-test-repos-mochajs-mocha && npm run clone-test-repos-pi-hole-docs && npm run clone-test-repos-v8-v8-dev && npm run clone-test-repos-webhintio-hint && npm run clone-test-repos-webpack-webpack-js-org",
"declaration": "npm run build-declaration && npm run test-declaration", "declaration": "npm run build-declaration && npm run test-declaration",
"example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint", "example": "cd example && node standalone.mjs && grunt markdownlint --force && gulp markdownlint",
"docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:latest npm install",
"docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:latest npm run upgrade",
"install-micromark": "cd micromark && npm install",
"lint": "eslint --max-warnings 0", "lint": "eslint --max-warnings 0",
"lint-test-repos": "ava --timeout=10m test/markdownlint-test-repos-*.js", "lint-test-repos": "ava --timeout=10m test/markdownlint-test-repos-*.mjs",
"serial-config-docs": "npm run build-config && npm run build-docs", "serial-config-docs": "npm run build-config && npm run build-docs",
"serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration", "serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration",
"test": "ava --timeout=30s test/markdownlint-test.js test/markdownlint-test-config.js test/markdownlint-test-custom-rules.js test/markdownlint-test-fixes.js test/markdownlint-test-helpers.js test/markdownlint-test-micromark.mjs test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js helpers/test.cjs", "test": "ava --timeout=30s test/markdownlint-test.mjs test/markdownlint-test-config.mjs test/markdownlint-test-custom-rules.mjs test/markdownlint-test-fixes.mjs test/markdownlint-test-helpers.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-result-object.mjs test/markdownlint-test-scenarios.mjs helpers/test.cjs",
"test-cover": "c8 --100 npm test", "test-cover": "c8 --100 npm test",
"test-declaration": "cd example/typescript && tsc --module nodenext && tsc --module commonjs && node type-check.js", "test-declaration": "cd example/typescript && tsc --module commonjs && tsc --module nodenext && node type-check.js",
"test-extra": "ava --timeout=10m test/markdownlint-test-extra-parse.js test/markdownlint-test-extra-type.js", "test-extra": "ava --timeout=10m test/markdownlint-test-extra-parse.mjs test/markdownlint-test-extra-type.mjs",
"update-snapshots": "ava --update-snapshots test/markdownlint-test-custom-rules.js test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.js", "update-snapshots": "ava --update-snapshots test/markdownlint-test-custom-rules.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.mjs",
"update-snapshots-test-repos": "ava --timeout=10m --update-snapshots test/markdownlint-test-repos-*.js", "update-snapshots-test-repos": "ava --timeout=10m --update-snapshots test/markdownlint-test-repos-*.mjs",
"upgrade": "npx --yes npm-check-updates --upgrade" "upgrade": "npx --yes npm-check-updates --upgrade"
}, },
"engines": { "engines": {
@ -66,7 +61,13 @@
}, },
"dependencies": { "dependencies": {
"markdown-it": "14.1.0", "markdown-it": "14.1.0",
"markdownlint-micromark": "0.1.12" "micromark": "4.0.0",
"micromark-extension-directive": "3.0.2",
"micromark-extension-gfm-autolink-literal": "2.1.0",
"micromark-extension-gfm-footnote": "2.1.0",
"micromark-extension-gfm-table": "2.1.0",
"micromark-extension-math": "3.1.0",
"micromark-util-types": "2.0.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "9.15.0", "@eslint/js": "9.15.0",

View file

@ -1,11 +1,10 @@
// @ts-check // @ts-check
"use strict"; import fs from "node:fs/promises";
import path from "node:path";
const fs = require("node:fs"); import yaml from "js-yaml";
const path = require("node:path"); import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
const yaml = require("js-yaml"); const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
const configSchema = require("./markdownlint-config-schema.json");
const configExample = {}; const configExample = {};
for (const rule in configSchema.properties) { for (const rule in configSchema.properties) {
@ -35,8 +34,8 @@ const transformComments = (input, commentPrefix) => (
); );
const configStringJson = JSON.stringify(configExample, null, 2); const configStringJson = JSON.stringify(configExample, null, 2);
fs.writeFileSync( await fs.writeFile(
path.join(__dirname, ".markdownlint.jsonc"), path.join(__dirname(import.meta), ".markdownlint.jsonc"),
transformComments(configStringJson, "//"), transformComments(configStringJson, "//"),
"utf8" "utf8"
); );
@ -49,8 +48,8 @@ const configStringYaml = yaml.dump(
"quotingType": "\"" "quotingType": "\""
} }
); );
fs.writeFileSync( await fs.writeFile(
path.join(__dirname, ".markdownlint.yaml"), path.join(__dirname(import.meta), ".markdownlint.yaml"),
transformComments(configStringYaml, "#"), transformComments(configStringYaml, "#"),
"utf8" "utf8"
); );

View file

@ -1,13 +1,12 @@
// @ts-check // @ts-check
"use strict"; import fs from "node:fs/promises";
import path from "node:path";
const fs = require("node:fs"); /** @type {import("../lib/markdownlint.mjs").Rule[]} */
const path = require("node:path"); import rules from "../lib/rules.mjs";
/** @type {import("../lib/markdownlint").Rule[]} */ import jsonSchemaToTypeScript from "json-schema-to-typescript";
const rules = require("../lib/rules"); import { version } from "../lib/constants.mjs";
const jsonSchemaToTypeScript = require("json-schema-to-typescript"); import { __dirname } from "../test/esm-helpers.mjs";
const { version } = require("../lib/constants");
const schemaName = "markdownlint-config-schema.json"; const schemaName = "markdownlint-config-schema.json";
const schemaUri = `https://raw.githubusercontent.com/DavidAnson/markdownlint/v${version}/schema/${schemaName}`; const schemaUri = `https://raw.githubusercontent.com/DavidAnson/markdownlint/v${version}/schema/${schemaName}`;
@ -586,8 +585,8 @@ for (const [ tag, tagTags ] of Object.entries(tags)) {
} }
// Write schema // Write schema
const schemaFile = path.join(__dirname, schemaName); const schemaFile = path.join(__dirname(import.meta), schemaName);
fs.writeFileSync(schemaFile, JSON.stringify(schema, null, " ")); await fs.writeFile(schemaFile, JSON.stringify(schema, null, " "));
// Create and write strict schema // Create and write strict schema
const schemaStrict = { const schemaStrict = {
@ -595,15 +594,15 @@ const schemaStrict = {
"$id": schemaStrictUri, "$id": schemaStrictUri,
"additionalProperties": false "additionalProperties": false
}; };
const schemaFileStrict = path.join(__dirname, schemaStrictName); const schemaFileStrict = path.join(__dirname(import.meta), schemaStrictName);
fs.writeFileSync(schemaFileStrict, JSON.stringify(schemaStrict, null, " ")); await fs.writeFile(schemaFileStrict, JSON.stringify(schemaStrict, null, " "));
// Write TypeScript declaration file // Write TypeScript declaration file
const declarationStrictName = path.join(__dirname, "..", "lib", "configuration-strict.d.ts"); const declarationStrictName = path.join(__dirname(import.meta), "..", "lib", "configuration-strict.d.ts");
schemaStrict.title = "ConfigurationStrict"; schemaStrict.title = "ConfigurationStrict";
jsonSchemaToTypeScript.compile( const declaration = await jsonSchemaToTypeScript.compile(
// @ts-ignore // @ts-ignore
schemaStrict, schemaStrict,
"UNUSED" "UNUSED"
// eslint-disable-next-line unicorn/prefer-top-level-await );
).then((declaration) => fs.writeFileSync(declarationStrictName, declaration)); await fs.writeFile(declarationStrictName, declaration);

View file

@ -1,29 +0,0 @@
// @ts-check
"use strict";
const fs = require("node:fs").promises;
const [ command, ...args ] = process.argv.slice(2);
// eslint-disable-next-line unicorn/prefer-top-level-await
(async() => {
if (command === "copy") {
const [ src, dest ] = args;
await fs.copyFile(src, dest);
} else if (command === "delete") {
const { globby } = await import("globby");
await Promise.all(
args.flatMap(
(glob) => globby(glob)
.then(
(files) => files.map((file) => fs.unlink(file))
)
)
);
} else if (command === "remove") {
await Promise.all(args.map((dir) => fs.rm(dir, { "recursive": true })));
} else {
throw new Error(`Unsupported command: ${command}`);
}
})();

Some files were not shown because too many files have changed in this diff Show more