mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
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:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
38
test/esm-helpers.mjs
Normal file
38
test/esm-helpers.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// @ts-check
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
/**
|
||||
* Gets the file name of the current module.
|
||||
* Shims import.meta.filename for Node 18.
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @returns {string} File name.
|
||||
*/
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
export const __filename = (meta) => fileURLToPath(meta.url);
|
||||
|
||||
/**
|
||||
* Gets the directory name of the current module.
|
||||
* Shims import.meta.dirname for Node 18.
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @returns {string} Directory name.
|
||||
*/
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
export const __dirname = (meta) => path.dirname(__filename(meta));
|
||||
|
||||
/**
|
||||
* Imports a file as JSON.
|
||||
* Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time".
|
||||
*
|
||||
* @param {Object} meta ESM import.meta object.
|
||||
* @param {string} file JSON file to import.
|
||||
* @returns {Promise<Object>} JSON object.
|
||||
*/
|
||||
export const importWithTypeJson = async(meta, file) => (
|
||||
// @ts-ignore
|
||||
JSON.parse(await fs.readFile(path.resolve(__dirname(meta), file)))
|
||||
);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import { parse } from "../helpers/micromark-parse.cjs";
|
||||
import library from "../lib/markdownlint.js";
|
||||
import { parse } from "../helpers/micromark-parse.mjs";
|
||||
import library from "../lib/markdownlint.mjs";
|
||||
const markdownlint = library.promises.markdownlint;
|
||||
|
||||
/* eslint-disable no-await-in-loop, no-console */
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
import { createRequire } from "node:module";
|
||||
const require = createRequire(import.meta.url);
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
import { __dirname } from "./esm-helpers.mjs";
|
||||
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
|
||||
const sameFileSystem = (path.relative(os.homedir(), __dirname) !== __dirname);
|
||||
const sameFileSystem = (path.relative(os.homedir(), __dirname(import.meta)) !== __dirname(import.meta));
|
||||
|
||||
test("configSingle", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
|
|
@ -22,7 +23,7 @@ test("configSingle", (t) => new Promise((resolve) => {
|
|||
|
||||
test("configAbsolute", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
markdownlint.readConfig(path.join(__dirname, "config", "config-child.json"),
|
||||
markdownlint.readConfig(path.join(__dirname(import.meta), "config", "config-child.json"),
|
||||
function callback(err, actual) {
|
||||
t.falsy(err);
|
||||
const expected = require("./config/config-child.json");
|
||||
|
|
@ -268,7 +269,7 @@ test("configSingleSync", (t) => {
|
|||
test("configAbsoluteSync", (t) => {
|
||||
t.plan(1);
|
||||
const actual = markdownlint.readConfigSync(
|
||||
path.join(__dirname, "config", "config-child.json"));
|
||||
path.join(__dirname(import.meta), "config", "config-child.json"));
|
||||
const expected = require("./config/config-child.json");
|
||||
t.deepEqual(actual, expected, "Config object not correct.");
|
||||
});
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs").promises;
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const customRules = require("./rules/rules.js");
|
||||
const { homepage, version } = require("../package.json");
|
||||
const { newLineRe } = require("../helpers/helpers.js");
|
||||
import fs from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
const require = createRequire(import.meta.url);
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
import customRules from "./rules/rules.cjs";
|
||||
import { newLineRe } from "../helpers/helpers.cjs";
|
||||
import { __filename, importWithTypeJson } from "./esm-helpers.mjs";
|
||||
const packageJson = await importWithTypeJson(import.meta, "../package.json");
|
||||
const { homepage, version } = packageJson;
|
||||
|
||||
test("customRulesV0", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
|
|
@ -85,8 +86,7 @@ test("customRulesV0", (t) => new Promise((resolve) => {
|
|||
test("customRulesV1", (t) => new Promise((resolve) => {
|
||||
t.plan(3);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
|
|
@ -217,8 +217,7 @@ test("customRulesV1", (t) => new Promise((resolve) => {
|
|||
test("customRulesV2", (t) => new Promise((resolve) => {
|
||||
t.plan(3);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
|
|
@ -339,8 +338,7 @@ test("customRulesV2", (t) => new Promise((resolve) => {
|
|||
test("customRulesConfig", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
const customRulesMd = "./test/custom-rules.md";
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.all,
|
||||
"files": [ customRulesMd ],
|
||||
|
|
@ -370,8 +368,7 @@ test("customRulesConfig", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesNpmPackage", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
require("./rules/npm"),
|
||||
|
|
@ -434,8 +431,7 @@ test("customRulesBadProperty", (t) => {
|
|||
for (const propertyValue of propertyValues) {
|
||||
const badRule = { ...customRules.firstLine };
|
||||
badRule[propertyName] = propertyValue;
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [ badRule ]
|
||||
};
|
||||
|
|
@ -456,8 +452,7 @@ test("customRulesBadProperty", (t) => {
|
|||
test("customRulesUsedNameName", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name", "NO-missing-SPACE-atx" ],
|
||||
|
|
@ -483,8 +478,7 @@ test("customRulesUsedNameName", (t) => new Promise((resolve) => {
|
|||
test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name", "HtMl" ],
|
||||
|
|
@ -509,8 +503,7 @@ test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
|
|||
test("customRulesUsedTagName", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "filler" ],
|
||||
|
|
@ -542,8 +535,7 @@ test("customRulesUsedTagName", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesParserUndefined", (t) => {
|
||||
t.plan(5);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
// @ts-ignore
|
||||
|
|
@ -570,8 +562,7 @@ test("customRulesParserUndefined", (t) => {
|
|||
|
||||
test("customRulesParserNone", (t) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -595,8 +586,7 @@ test("customRulesParserNone", (t) => {
|
|||
|
||||
test("customRulesParserMarkdownIt", (t) => {
|
||||
t.plan(5);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -623,8 +613,7 @@ test("customRulesParserMarkdownIt", (t) => {
|
|||
|
||||
test("customRulesParserMicromark", (t) => {
|
||||
t.plan(5);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -651,8 +640,7 @@ test("customRulesParserMicromark", (t) => {
|
|||
|
||||
test("customRulesMarkdownItParamsTokensSameObject", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
// @ts-ignore
|
||||
|
|
@ -676,8 +664,7 @@ test("customRulesMarkdownItParamsTokensSameObject", (t) => {
|
|||
|
||||
test("customRulesMarkdownItTokensSnapshot", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -703,8 +690,7 @@ test("customRulesMarkdownItTokensSnapshot", (t) => {
|
|||
|
||||
test("customRulesMicromarkTokensSnapshot", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -730,8 +716,7 @@ test("customRulesMicromarkTokensSnapshot", (t) => {
|
|||
|
||||
test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -781,8 +766,7 @@ test("customRulesThrowForFile", (t) => new Promise((resolve) => {
|
|||
t.plan(4);
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -812,8 +796,7 @@ test("customRulesThrowForFileSync", (t) => {
|
|||
t.throws(
|
||||
function customRuleThrowsCall() {
|
||||
markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -839,8 +822,7 @@ test("customRulesThrowForString", (t) => new Promise((resolve) => {
|
|||
t.plan(4);
|
||||
const exceptionMessage = "Test exception message";
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -872,8 +854,7 @@ test("customRulesThrowForStringSync", (t) => {
|
|||
t.throws(
|
||||
function customRuleThrowsCall() {
|
||||
markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -900,8 +881,7 @@ test("customRulesThrowForStringSync", (t) => {
|
|||
test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -934,8 +914,7 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesOnErrorNullSync", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1026,8 +1005,7 @@ test("customRulesOnErrorBad", (t) => {
|
|||
badObject[propertyName] = propertyValue;
|
||||
propertyNames = propertyName;
|
||||
}
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1099,8 +1077,7 @@ test("customRulesOnErrorInvalid", (t) => {
|
|||
badObject[propertyName] = propertyValue;
|
||||
propertyNames = propertyName;
|
||||
}
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1175,8 +1152,7 @@ test("customRulesOnErrorValid", (t) => {
|
|||
} else {
|
||||
goodObject[propertyName] = propertyValue;
|
||||
}
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1201,8 +1177,7 @@ test("customRulesOnErrorValid", (t) => {
|
|||
|
||||
test("customRulesOnErrorLazy", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1259,8 +1234,7 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
|
|||
"insertText": "text"
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1313,8 +1287,7 @@ test("customRulesOnErrorModified", (t) => new Promise((resolve) => {
|
|||
test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
markdownlint({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1357,8 +1330,7 @@ test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
|
|||
test("customRulesOnErrorInvalidHandledSync", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1398,8 +1370,7 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
|
|||
|
||||
test("customRulesVersion", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1422,8 +1393,7 @@ test("customRulesVersion", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesFileName", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1446,8 +1416,7 @@ test("customRulesFileName", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesStringName", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1473,8 +1442,7 @@ test("customRulesStringName", (t) => new Promise((resolve) => {
|
|||
test("customRulesOnErrorInformationNotRuleNotError", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1498,8 +1466,7 @@ test("customRulesOnErrorInformationNotRuleNotError", (t) => {
|
|||
test("customRulesOnErrorInformationRuleNotError", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1528,8 +1495,7 @@ test("customRulesOnErrorInformationRuleNotError", (t) => {
|
|||
test("customRulesOnErrorInformationNotRuleError", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1558,8 +1524,7 @@ test("customRulesOnErrorInformationNotRuleError", (t) => {
|
|||
test("customRulesOnErrorInformationRuleError", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1589,8 +1554,7 @@ test("customRulesOnErrorInformationRuleError", (t) => {
|
|||
test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
|
||||
t.plan(1);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1620,8 +1584,7 @@ test("customRulesOnErrorInformationRuleErrorUndefined", (t) => {
|
|||
test("customRulesOnErrorInformationRuleErrorMultiple", (t) => {
|
||||
t.plan(6);
|
||||
const actualResult = markdownlint.sync({
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -1697,8 +1660,7 @@ test("customRulesDoc", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.lintJavaScript,
|
||||
"files": "test/lint-javascript.md"
|
||||
|
|
@ -1726,8 +1688,7 @@ test("customRulesLintJavaScript", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesValidateJson", (t) => new Promise((resolve) => {
|
||||
t.plan(3);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": customRules.validateJson,
|
||||
"files": "test/validate-json.md"
|
||||
|
|
@ -1760,8 +1721,7 @@ test("customRulesValidateJson", (t) => new Promise((resolve) => {
|
|||
|
||||
test("customRulesAsyncThrowsInSyncContext", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1805,8 +1765,7 @@ test("customRulesParamsAreFrozen", (t) => {
|
|||
}
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1840,8 +1799,7 @@ test("customRulesParamsAreStable", (t) => {
|
|||
t.plan(4);
|
||||
const config1 = { "value1": 10 };
|
||||
const config2 = { "value2": 20 };
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"config": {
|
||||
"MD010": true,
|
||||
|
|
@ -1907,8 +1865,7 @@ test("customRulesParamsAreStable", (t) => {
|
|||
|
||||
test("customRulesAsyncReadFiles", (t) => {
|
||||
t.plan(3);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1919,7 +1876,7 @@ test("customRulesAsyncReadFiles", (t) => {
|
|||
"asynchronous": true,
|
||||
"parser": "none",
|
||||
"function":
|
||||
(params, onError) => fs.readFile(__filename, "utf8").then(
|
||||
(params, onError) => fs.readFile(__filename(import.meta), "utf8").then(
|
||||
(content) => {
|
||||
t.true(content.length > 0);
|
||||
onError({
|
||||
|
|
@ -1939,7 +1896,7 @@ test("customRulesAsyncReadFiles", (t) => {
|
|||
"parser": "none",
|
||||
"function":
|
||||
async(params, onError) => {
|
||||
const content = await fs.readFile(__filename, "utf8");
|
||||
const content = await fs.readFile(__filename(import.meta), "utf8");
|
||||
t.true(content.length > 0);
|
||||
onError({
|
||||
"lineNumber": 1,
|
||||
|
|
@ -1996,8 +1953,7 @@ test("customRulesAsyncReadFiles", (t) => {
|
|||
|
||||
test("customRulesAsyncIgnoresSyncReturn", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -2088,8 +2044,7 @@ for (const flavor of [
|
|||
]
|
||||
]) {
|
||||
const [ name, func ] = flavor;
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule[]} */
|
||||
const customRule = [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
|
|
@ -2202,7 +2157,7 @@ for (const flavor of [
|
|||
],
|
||||
[
|
||||
"customRulesAsyncDeferredString",
|
||||
() => fs.readFile(__filename, "utf8").then(
|
||||
() => fs.readFile(__filename(import.meta), "utf8").then(
|
||||
() => {
|
||||
throw errorMessage;
|
||||
}
|
||||
|
|
@ -2210,7 +2165,7 @@ for (const flavor of [
|
|||
],
|
||||
[
|
||||
"customRulesAsyncDeferredError",
|
||||
() => fs.readFile(__filename, "utf8").then(
|
||||
() => fs.readFile(__filename(import.meta), "utf8").then(
|
||||
() => {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
|
@ -2226,8 +2181,7 @@ for (const flavor of [
|
|||
]
|
||||
]) {
|
||||
const [ name, func ] = flavor;
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Rule */
|
||||
/** @type {import("../lib/markdownlint.mjs").Rule} */
|
||||
const customRule = {
|
||||
"names": [ "name" ],
|
||||
"description": "description",
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
import test from "ava";
|
||||
import { globby } from "globby";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
|
||||
// Parses all Markdown files in all package dependencies
|
||||
test("parseAllFiles", async(t) => {
|
||||
t.plan(1);
|
||||
const { globby } = await import("globby");
|
||||
const files = await globby("**/*.{md,markdown}");
|
||||
await markdownlint.promises.markdownlint({ files });
|
||||
t.pass();
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
|
||||
// Simulates typing each test file to validate handling of partial input
|
||||
const files = fs
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const test = require("ava").default;
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
|
||||
test("applyFix", (t) => {
|
||||
t.plan(4);
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const test = require("ava").default;
|
||||
const helpers = require("../helpers");
|
||||
const libMarkdownlint = require("../lib/markdownlint");
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "ava";
|
||||
import { characterEntities } from "character-entities";
|
||||
import { gemoji } from "gemoji";
|
||||
import helpers from "../helpers/helpers.cjs";
|
||||
import libMarkdownlint from "../lib/markdownlint.mjs";
|
||||
const { markdownlint } = libMarkdownlint.promises;
|
||||
const { forEachInlineCodeSpan } = require("../lib/markdownit.cjs");
|
||||
import { forEachInlineCodeSpan } from "../lib/markdownit.cjs";
|
||||
import { getReferenceLinkImageData } from "../lib/cache.mjs";
|
||||
|
||||
test("clearHtmlCommentTextValid", (t) => {
|
||||
t.plan(1);
|
||||
|
|
@ -386,8 +387,7 @@ test("expandTildePath", (t) => {
|
|||
|
||||
test("getReferenceLinkImageData().shortcuts", (t) => {
|
||||
t.plan(1);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -397,7 +397,6 @@ test("getReferenceLinkImageData().shortcuts", (t) => {
|
|||
"parser": "none",
|
||||
"function":
|
||||
() => {
|
||||
const { getReferenceLinkImageData } = require("../lib/cache");
|
||||
const { shortcuts } = getReferenceLinkImageData();
|
||||
t.is(shortcuts.size, 0, [ ...shortcuts.keys() ].join(", "));
|
||||
}
|
||||
|
|
@ -419,8 +418,7 @@ Empty bracket pair: [text4[]]
|
|||
return markdownlint(options).then(() => null);
|
||||
});
|
||||
|
||||
test("endOfLineHtmlEntityRe", async(t) => {
|
||||
const { characterEntities } = await import("character-entities");
|
||||
test("endOfLineHtmlEntityRe", (t) => {
|
||||
const entities = Object.keys(characterEntities);
|
||||
t.plan(entities.length);
|
||||
for (const entity of entities) {
|
||||
|
|
@ -428,8 +426,7 @@ test("endOfLineHtmlEntityRe", async(t) => {
|
|||
}
|
||||
});
|
||||
|
||||
test("endOfLineGemojiCodeRe", async(t) => {
|
||||
const { gemoji } = await import("gemoji");
|
||||
test("endOfLineGemojiCodeRe", (t) => {
|
||||
const emojis = gemoji.flatMap((i) => i.names);
|
||||
t.plan(emojis.length);
|
||||
for (const emoji of emojis) {
|
||||
|
|
@ -447,7 +444,7 @@ test("ellipsify", (t) => {
|
|||
|
||||
test("hasOverlap", (t) => {
|
||||
t.plan(32);
|
||||
/** @type {import("../helpers").FileRange[][]} */
|
||||
/** @type {import("../helpers/helpers.cjs").FileRange[][]} */
|
||||
const trueTestCases = [
|
||||
// Same line
|
||||
[
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
import fs from "node:fs/promises";
|
||||
import test from "ava";
|
||||
import { newLineRe } from "../helpers/helpers.js";
|
||||
import { newLineRe } from "../helpers/helpers.cjs";
|
||||
import { filterByPredicate, filterByTypes } from "../helpers/micromark-helpers.cjs";
|
||||
import { getEvents, parse } from "../helpers/micromark-parse.cjs";
|
||||
import { getEvents, parse } from "../helpers/micromark-parse.mjs";
|
||||
|
||||
const testContent = new Promise((resolve, reject) => {
|
||||
fs
|
||||
|
|
@ -49,8 +49,7 @@ test("getEvents/filterByPredicate", async(t) => {
|
|||
test("filterByTypes, htmlFlow false", async(t) => {
|
||||
t.plan(7);
|
||||
const tokens = await testTokens;
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../micromark/micromark.cjs").TokenType[] */
|
||||
/** @type {import("micromark-util-types").TokenType[]} */
|
||||
const types = [ "atxHeadingText", "codeText", "htmlText", "setextHeadingText" ];
|
||||
const filtered = filterByTypes(tokens, types);
|
||||
// Using flat tokens
|
||||
|
|
@ -67,8 +66,7 @@ test("filterByTypes, htmlFlow false", async(t) => {
|
|||
test("filterByTypes, htmlFlow true", async(t) => {
|
||||
t.plan(9);
|
||||
const tokens = await testTokens;
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../micromark/micromark.cjs").TokenType[] */
|
||||
/** @type {import("micromark-util-types").TokenType[]} */
|
||||
const types = [ "atxHeadingText", "codeText", "htmlText", "setextHeadingText" ];
|
||||
// Using flat tokens
|
||||
const filtered = filterByTypes(tokens, types, true);
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
||||
const { availableParallelism } = require("node:os");
|
||||
const { Worker } = require("node:worker_threads");
|
||||
const markdownlintSync = require("../lib/markdownlint").sync;
|
||||
import { availableParallelism } from "node:os";
|
||||
import { Worker } from "node:worker_threads";
|
||||
import { __filename } from "./esm-helpers.mjs";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
const markdownlintSync = markdownlint.sync;
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files (using multiple threads).
|
||||
*
|
||||
* @param {import("../lib/markdownlint").Options} options Configuration options.
|
||||
* @returns {Promise<import("../lib/markdownlint").LintResults>} Results object.
|
||||
* @param {import("../lib/markdownlint.mjs").Options} options Configuration options.
|
||||
* @returns {Promise<import("../lib/markdownlint.mjs").LintResults>} Results object.
|
||||
*/
|
||||
function markdownlintParallel(options) {
|
||||
export function markdownlintParallel(options) {
|
||||
const workerCount = availableParallelism();
|
||||
const files = options.files || [];
|
||||
const chunkSize = Math.ceil(files.length / workerCount);
|
||||
|
|
@ -24,7 +24,7 @@ function markdownlintParallel(options) {
|
|||
...options,
|
||||
"files": files.slice(i * chunkSize, (i + 1) * chunkSize)
|
||||
};
|
||||
const worker = new Worker(__filename.replace(/parallel\.js$/, "worker.js"), { workerData });
|
||||
const worker = new Worker(__filename(import.meta).replace(/parallel\.mjs$/, "worker.mjs"), { workerData });
|
||||
worker.on("message", resolve);
|
||||
worker.on("error", reject);
|
||||
}));
|
||||
|
|
@ -40,5 +40,3 @@ function markdownlintParallel(options) {
|
|||
return combinedResults;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = markdownlintParallel;
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { join } = require("node:path").posix;
|
||||
const test = require("ava").default;
|
||||
const { lintTestRepo } = require("./markdownlint-test-repos");
|
||||
import path from "node:path";
|
||||
const { join } = path.posix;
|
||||
import test from "ava";
|
||||
import { lintTestRepo } from "./markdownlint-test-repos.mjs";
|
||||
|
||||
test("https://github.com/dotnet/docs", (t) => {
|
||||
const rootDir = "./test-repos/dotnet-docs";
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { join } = require("node:path").posix;
|
||||
const test = require("ava").default;
|
||||
const { lintTestRepo } = require("./markdownlint-test-repos");
|
||||
import path from "node:path";
|
||||
const { join } = path.posix;
|
||||
import test from "ava";
|
||||
import { lintTestRepo } from "./markdownlint-test-repos.mjs";
|
||||
|
||||
test("https://github.com/mdn/content", (t) => {
|
||||
const rootDir = "./test-repos/mdn-content";
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { join } = require("node:path").posix;
|
||||
const test = require("ava").default;
|
||||
const { excludeGlobs, lintTestRepo } = require("./markdownlint-test-repos");
|
||||
import path from "node:path";
|
||||
const { join } = path.posix;
|
||||
import test from "ava";
|
||||
import { excludeGlobs, lintTestRepo } from "./markdownlint-test-repos.mjs";
|
||||
|
||||
// Run markdownlint the same way the corresponding repositories do
|
||||
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { join } = require("node:path").posix;
|
||||
const jsoncParser = require("jsonc-parser");
|
||||
const jsYaml = require("js-yaml");
|
||||
const { markdownlint, readConfig } = require("../lib/markdownlint").promises;
|
||||
const markdownlintParallel = require("./markdownlint-test-parallel");
|
||||
import path from "node:path";
|
||||
const { join } = path.posix;
|
||||
import { globby } from "globby";
|
||||
import jsoncParser from "jsonc-parser";
|
||||
import jsYaml from "js-yaml";
|
||||
import library from "../lib/markdownlint.mjs";
|
||||
const { markdownlint, readConfig } = library.promises;
|
||||
import { markdownlintParallel } from "./markdownlint-test-parallel.mjs";
|
||||
|
||||
/**
|
||||
* Lints a test repository.
|
||||
|
|
@ -17,9 +18,8 @@ const markdownlintParallel = require("./markdownlint-test-parallel");
|
|||
* @param {boolean} [parallel] True to lint in parallel.
|
||||
* @returns {Promise} Test result.
|
||||
*/
|
||||
async function lintTestRepo(t, globPatterns, configPath, parallel) {
|
||||
export function lintTestRepo(t, globPatterns, configPath, parallel) {
|
||||
t.plan(1);
|
||||
const { globby } = await import("globby");
|
||||
const jsoncParse = (json) => {
|
||||
const config = jsoncParser.parse(json, [], { "allowTrailingComma": true });
|
||||
return config.config || config;
|
||||
|
|
@ -59,11 +59,6 @@ async function lintTestRepo(t, globPatterns, configPath, parallel) {
|
|||
* @param {...string} globs Globs to exclude.
|
||||
* @returns {string[]} Array of excluded globs.
|
||||
*/
|
||||
function excludeGlobs(rootDir, ...globs) {
|
||||
export function excludeGlobs(rootDir, ...globs) {
|
||||
return globs.map((glob) => "!" + join(rootDir, glob));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
excludeGlobs,
|
||||
lintTestRepo
|
||||
};
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const test = require("ava").default;
|
||||
const packageJson = require("../package.json");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const homepage = packageJson.homepage;
|
||||
const version = packageJson.version;
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
import { importWithTypeJson } from "./esm-helpers.mjs";
|
||||
const packageJson = await importWithTypeJson(import.meta, "../package.json");
|
||||
const { homepage, version } = packageJson;
|
||||
|
||||
test("resultObjectToStringNotEnumerable", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
|
|
@ -1,15 +1,13 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs").promises;
|
||||
const path = require("node:path");
|
||||
const test = require("ava").default;
|
||||
const libMarkdownlint = require("../lib/markdownlint");
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import test from "ava";
|
||||
import libMarkdownlint from "../lib/markdownlint.mjs";
|
||||
const { applyFixes, promises } = libMarkdownlint;
|
||||
const { markdownlint } = promises;
|
||||
const helpers = require("../helpers");
|
||||
const constants = require("../lib/constants");
|
||||
import helpers from "../helpers/helpers.cjs";
|
||||
import { fixableRuleNames } from "../lib/constants.mjs";
|
||||
|
||||
const numericalSortCompareFn = (a, b) => a - b;
|
||||
|
||||
|
|
@ -75,7 +73,7 @@ function createTestForFile(file) {
|
|||
indices.push(error.lineNumber);
|
||||
}
|
||||
t.true(
|
||||
!error.fixInfo || constants.fixableRuleNames.includes(rule),
|
||||
!error.fixInfo || fixableRuleNames.includes(rule),
|
||||
`Fixable rule ${rule} is not tagged as such.`
|
||||
);
|
||||
}
|
||||
|
|
@ -104,9 +102,8 @@ function createTestForFile(file) {
|
|||
);
|
||||
}
|
||||
|
||||
const files = require("node:fs")
|
||||
.readdirSync("./test")
|
||||
.filter((file) => /\.md$/.test(file));
|
||||
const dir = await fs.readdir("./test");
|
||||
const files = dir.filter((file) => /\.md$/.test(file));
|
||||
for (const file of files) {
|
||||
// @ts-ignore
|
||||
test(
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { parentPort, workerData } = require("node:worker_threads");
|
||||
const markdownlint = require("../lib/markdownlint").promises.markdownlint;
|
||||
|
||||
// eslint-disable-next-line unicorn/prefer-top-level-await
|
||||
markdownlint(workerData).then((lintResults) => {
|
||||
// @ts-ignore
|
||||
parentPort
|
||||
// eslint-disable-next-line unicorn/require-post-message-target-origin
|
||||
.postMessage(lintResults);
|
||||
// eslint-disable-next-line n/no-process-exit
|
||||
process.exit();
|
||||
});
|
||||
13
test/markdownlint-test-worker.mjs
Normal file
13
test/markdownlint-test-worker.mjs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// @ts-check
|
||||
|
||||
import { parentPort, workerData } from "node:worker_threads";
|
||||
import library from "../lib/markdownlint.mjs";
|
||||
const { markdownlint } = library.promises;
|
||||
|
||||
const lintResults = await markdownlint(workerData);
|
||||
// @ts-ignore
|
||||
parentPort
|
||||
// eslint-disable-next-line unicorn/require-post-message-target-origin
|
||||
.postMessage(lintResults);
|
||||
// eslint-disable-next-line n/no-process-exit
|
||||
process.exit();
|
||||
|
|
@ -1,24 +1,26 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const Ajv = require("ajv");
|
||||
const jsoncParser = require("jsonc-parser");
|
||||
const jsYaml = require("js-yaml");
|
||||
const md = require("markdown-it")();
|
||||
const pluginInline = require("markdown-it-for-inline");
|
||||
const pluginSub = require("markdown-it-sub");
|
||||
const pluginSup = require("markdown-it-sup");
|
||||
const test = require("ava").default;
|
||||
const { "exports": packageExports, homepage, name, version } = require("../package.json");
|
||||
const markdownlint = require("../lib/markdownlint");
|
||||
const constants = require("../lib/constants");
|
||||
const rules = require("../lib/rules");
|
||||
const customRules = require("./rules/rules.js");
|
||||
const configSchema = require("../schema/markdownlint-config-schema.json");
|
||||
const configSchemaStrict = require("../schema/markdownlint-config-schema-strict.json");
|
||||
import fs from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
const require = createRequire(import.meta.url);
|
||||
import path from "node:path";
|
||||
import Ajv from "ajv";
|
||||
import { globby } from "globby";
|
||||
import jsoncParser from "jsonc-parser";
|
||||
import jsYaml from "js-yaml";
|
||||
import markdownIt from "markdown-it";
|
||||
import pluginInline from "markdown-it-for-inline";
|
||||
import pluginSub from "markdown-it-sub";
|
||||
import pluginSup from "markdown-it-sup";
|
||||
import test from "ava";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
import * as constants from "../lib/constants.mjs";
|
||||
import rules from "../lib/rules.mjs";
|
||||
import customRules from "./rules/rules.cjs";
|
||||
import { __dirname, importWithTypeJson } from "./esm-helpers.mjs";
|
||||
const packageJson = await importWithTypeJson(import.meta, "../package.json");
|
||||
const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
|
||||
const configSchemaStrict = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema-strict.json");
|
||||
|
||||
const deprecatedRuleNames = new Set(constants.deprecatedRuleNames);
|
||||
const ajvOptions = {
|
||||
|
|
@ -82,7 +84,7 @@ test("projectFiles", (t) => {
|
|||
return import("globby")
|
||||
.then((module) => module.globby(projectFiles))
|
||||
.then((files) => {
|
||||
t.is(files.length, 61);
|
||||
t.is(files.length, 60);
|
||||
const options = {
|
||||
files,
|
||||
"config": require("../.markdownlint.json")
|
||||
|
|
@ -109,7 +111,7 @@ test("projectFilesExtendedAscii", (t) => {
|
|||
"!doc/md036.md"
|
||||
]))
|
||||
.then((files) => {
|
||||
t.is(files.length, 57);
|
||||
t.is(files.length, 56);
|
||||
const options = {
|
||||
files,
|
||||
"config": require("../.markdownlint.json"),
|
||||
|
|
@ -450,7 +452,7 @@ test("styleFiles", async(t) => {
|
|||
t.truthy(require(path.join("../style", file)), "Unable to load/parse.");
|
||||
const exportValue = `./style/${file}`;
|
||||
const exportKey = exportValue.replace(/\.json$/, "");
|
||||
t.is(packageExports[exportKey], exportValue);
|
||||
t.is(packageJson.exports[exportKey], exportValue);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -884,7 +886,7 @@ test("readme", async(t) => {
|
|||
let seenTags = false;
|
||||
let inTags = false;
|
||||
// @ts-ignore
|
||||
for (const token of md.parse(contents, {})) {
|
||||
for (const token of markdownIt().parse(contents, {})) {
|
||||
if (
|
||||
(token.type === "bullet_list_open") &&
|
||||
(token.level === 0)
|
||||
|
|
@ -954,7 +956,6 @@ test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
|||
"test/invalid-ul-style-style.md",
|
||||
"test/wrong-types-in-config-file.md"
|
||||
]);
|
||||
const { globby } = await import("globby");
|
||||
const files = await globby([
|
||||
"*.md",
|
||||
"doc/*.md",
|
||||
|
|
@ -1035,14 +1036,14 @@ test("validateConfigExampleJson", (t) => {
|
|||
const validateSchema = ajv.compile(configSchema);
|
||||
t.is(
|
||||
configSchema.$id.replace(/^.*\/v(?<ver>\d+\.\d+\.\d+)\/.*$/u, "$<ver>"),
|
||||
version
|
||||
packageJson.version
|
||||
);
|
||||
t.is(configSchema.$id, configSchema.properties.$schema.default);
|
||||
|
||||
// Validate JSONC
|
||||
const fileJson = ".markdownlint.jsonc";
|
||||
const dataJson = fs.readFileSync(
|
||||
path.join(__dirname, "../schema", fileJson),
|
||||
path.join(__dirname(import.meta), "../schema", fileJson),
|
||||
"utf8"
|
||||
);
|
||||
const jsonObject = jsoncParser.parse(dataJson);
|
||||
|
|
@ -1055,7 +1056,7 @@ test("validateConfigExampleJson", (t) => {
|
|||
// Validate YAML
|
||||
const fileYaml = ".markdownlint.yaml";
|
||||
const dataYaml = fs.readFileSync(
|
||||
path.join(__dirname, "../schema", fileYaml),
|
||||
path.join(__dirname(import.meta), "../schema", fileYaml),
|
||||
"utf8"
|
||||
);
|
||||
const yamlObject = jsYaml.load(dataYaml);
|
||||
|
|
@ -1074,7 +1075,7 @@ test("allBuiltInRulesHaveValidUrl", (t) => {
|
|||
t.is(
|
||||
// @ts-ignore
|
||||
rule.information.href,
|
||||
`${homepage}/blob/v${version}/doc/${ruleName}.md`
|
||||
`${packageJson.homepage}/blob/v${packageJson.version}/doc/${ruleName}.md`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
@ -1087,12 +1088,12 @@ test("someCustomRulesHaveValidUrl", (t) => {
|
|||
if (rule === customRules.anyBlockquote) {
|
||||
t.is(
|
||||
rule.information?.href,
|
||||
`${homepage}/blob/main/test/rules/any-blockquote.js`
|
||||
`${packageJson.homepage}/blob/main/test/rules/any-blockquote.js`
|
||||
);
|
||||
} else if (rule === customRules.lettersEX) {
|
||||
t.is(
|
||||
rule.information?.href,
|
||||
`${homepage}/blob/main/test/rules/letters-E-X.js`
|
||||
`${packageJson.homepage}/blob/main/test/rules/letters-E-X.js`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1205,8 +1206,7 @@ Text with: [^footnote]
|
|||
|
||||
test("token-map-spans", (t) => {
|
||||
t.plan(38);
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("../lib/markdownlint").Options */
|
||||
/** @type {import("../lib/markdownlint.mjs").Options} */
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
|
|
@ -1351,21 +1351,21 @@ test("configParsersTOML", async(t) => {
|
|||
test("getVersion", (t) => {
|
||||
t.plan(1);
|
||||
const actual = markdownlint.getVersion();
|
||||
const expected = version;
|
||||
const expected = packageJson.version;
|
||||
t.is(actual, expected, "Version string not correct.");
|
||||
});
|
||||
|
||||
test("constants", (t) => {
|
||||
t.plan(2);
|
||||
// @ts-ignore
|
||||
t.is(constants.homepage, homepage);
|
||||
t.is(constants.homepage, packageJson.homepage);
|
||||
// @ts-ignore
|
||||
t.is(constants.version, version);
|
||||
t.is(constants.version, packageJson.version);
|
||||
});
|
||||
|
||||
const exportMappings = new Map([
|
||||
[ ".", "../lib/markdownlint.js" ],
|
||||
[ "./helpers", "../helpers/helpers.js" ],
|
||||
[ ".", "../lib/markdownlint.mjs" ],
|
||||
[ "./helpers", "../helpers/helpers.cjs" ],
|
||||
[ "./style/all", "../style/all.json" ],
|
||||
[ "./style/cirosantilli", "../style/cirosantilli.json" ],
|
||||
[ "./style/prettier", "../style/prettier.json" ],
|
||||
|
|
@ -1374,16 +1374,22 @@ const exportMappings = new Map([
|
|||
|
||||
test("exportMappings", (t) => {
|
||||
t.deepEqual(
|
||||
Object.keys(packageExports),
|
||||
Object.keys(packageJson.exports),
|
||||
[ ...exportMappings.keys() ]
|
||||
);
|
||||
});
|
||||
|
||||
// const commonJsRe = /\.js$/u;
|
||||
const jsonRe = /\.json$/u;
|
||||
const importOptionsJson = { "with": { "type": "json" } };
|
||||
|
||||
for (const [ exportName, exportPath ] of exportMappings) {
|
||||
test(exportName, (t) => {
|
||||
t.is(
|
||||
require(exportName.replace(/^\./u, name)),
|
||||
require(exportPath)
|
||||
);
|
||||
test(exportName, async(t) => {
|
||||
// const commonJs = !commonJsRe.test(exportPath);
|
||||
const json = jsonRe.test(exportPath);
|
||||
const importOptions = json ? importOptionsJson : undefined;
|
||||
const importExportName = await import(exportName.replace(/^\./u, packageJson.name), importOptions);
|
||||
const importExportPath = await import(exportPath, importOptions);
|
||||
t.is(importExportName, importExportPath);
|
||||
});
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import library from "../lib/markdownlint.js";
|
||||
import library from "../lib/markdownlint.mjs";
|
||||
const markdownlint = library.promises.markdownlint;
|
||||
|
||||
const strings = {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule[] */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule[]} */
|
||||
module.exports = [
|
||||
|
||||
// micromark parser (preferred)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "every-n-lines" ],
|
||||
"description": "Rule that reports an error every N lines",
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "first-line" ],
|
||||
"description": "Rule that reports an error for the first line",
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||
"description": "Rule that reports an error for lines with the letters 'EX'",
|
||||
|
|
@ -7,7 +7,7 @@ const eslint = require("eslint");
|
|||
const linter = new eslint.Linter();
|
||||
const languageJavaScript = /js|javascript/i;
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "lint-javascript" ],
|
||||
"description": "Rule that lints JavaScript code",
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
"name": "markdownlint-rule-sample",
|
||||
"version": "0.0.1",
|
||||
"description": "Package for markdownlint custom rule sample",
|
||||
"type": "commonjs",
|
||||
"main": "sample-rule.js",
|
||||
"author": "David Anson (https://dlaa.me/)",
|
||||
"homepage": "https://github.com/DavidAnson/markdownlint",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "sample-rule" ],
|
||||
"description": "Sample rule",
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const anyBlockquote = require("./any-blockquote");
|
||||
const anyBlockquote = require("./any-blockquote.cjs");
|
||||
module.exports.anyBlockquote = anyBlockquote[1];
|
||||
|
||||
const everyNLines = require("./every-n-lines");
|
||||
const everyNLines = require("./every-n-lines.cjs");
|
||||
module.exports.everyNLines = everyNLines;
|
||||
|
||||
const firstLine = require("./first-line");
|
||||
const firstLine = require("./first-line.cjs");
|
||||
module.exports.firstLine = firstLine;
|
||||
|
||||
const lettersEX = require("./letters-E-X");
|
||||
const lettersEX = require("./letters-E-X.cjs");
|
||||
module.exports.lettersEX = lettersEX;
|
||||
|
||||
const lintJavaScript = require("./lint-javascript");
|
||||
const lintJavaScript = require("./lint-javascript.cjs");
|
||||
module.exports.lintJavaScript = lintJavaScript;
|
||||
|
||||
const validateJson = require("./validate-json");
|
||||
const validateJson = require("./validate-json.cjs");
|
||||
module.exports.validateJson = validateJson;
|
||||
|
||||
module.exports.all = [
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
const { parse, printParseErrorCode } = require("jsonc-parser");
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
/** @type {import("../../lib/markdownlint.mjs").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "validate-json" ],
|
||||
"description": "Rule that validates JSON code",
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Snapshot report for `test/markdownlint-test-custom-rules.js`
|
||||
# Snapshot report for `test/markdownlint-test-custom-rules.mjs`
|
||||
|
||||
The actual snapshot is saved in `markdownlint-test-custom-rules.js.snap`.
|
||||
The actual snapshot is saved in `markdownlint-test-custom-rules.mjs.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Snapshot report for `test/markdownlint-test-repos-dotnet-docs.js`
|
||||
# Snapshot report for `test/markdownlint-test-repos-dotnet-docs.mjs`
|
||||
|
||||
The actual snapshot is saved in `markdownlint-test-repos-dotnet-docs.js.snap`.
|
||||
The actual snapshot is saved in `markdownlint-test-repos-dotnet-docs.mjs.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Snapshot report for `test/markdownlint-test-repos-mdn-content.js`
|
||||
# Snapshot report for `test/markdownlint-test-repos-mdn-content.mjs`
|
||||
|
||||
The actual snapshot is saved in `markdownlint-test-repos-mdn-content.js.snap`.
|
||||
The actual snapshot is saved in `markdownlint-test-repos-mdn-content.mjs.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Snapshot report for `test/markdownlint-test-repos-small.js`
|
||||
# Snapshot report for `test/markdownlint-test-repos-small.mjs`
|
||||
|
||||
The actual snapshot is saved in `markdownlint-test-repos-small.js.snap`.
|
||||
The actual snapshot is saved in `markdownlint-test-repos-small.mjs.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Snapshot report for `test/markdownlint-test-scenarios.js`
|
||||
# Snapshot report for `test/markdownlint-test-scenarios.mjs`
|
||||
|
||||
The actual snapshot is saved in `markdownlint-test-scenarios.js.snap`.
|
||||
The actual snapshot is saved in `markdownlint-test-scenarios.mjs.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue