2019-10-30 20:37:06 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2015-02-23 23:39:20 -08:00
|
|
|
"use strict";
|
|
|
|
|
2022-08-16 04:01:53 +00:00
|
|
|
const fs = require("node:fs");
|
|
|
|
const path = require("node:path");
|
2023-11-25 17:33:39 -08:00
|
|
|
const Ajv = require("ajv");
|
2021-01-21 19:50:57 -08:00
|
|
|
const jsYaml = require("js-yaml");
|
2018-04-27 22:05:34 -07:00
|
|
|
const md = require("markdown-it")();
|
2019-01-19 12:52:13 -08:00
|
|
|
const pluginInline = require("markdown-it-for-inline");
|
|
|
|
const pluginSub = require("markdown-it-sub");
|
|
|
|
const pluginSup = require("markdown-it-sup");
|
2021-01-10 20:46:00 -08:00
|
|
|
const test = require("ava").default;
|
2023-11-25 17:33:39 -08:00
|
|
|
const { "exports": packageExports, homepage, version } = require("../package.json");
|
2018-04-27 22:05:34 -07:00
|
|
|
const markdownlint = require("../lib/markdownlint");
|
2021-11-10 21:48:15 -08:00
|
|
|
const constants = require("../lib/constants");
|
2018-04-27 22:05:34 -07:00
|
|
|
const rules = require("../lib/rules");
|
2018-07-20 22:31:41 -07:00
|
|
|
const customRules = require("./rules/rules.js");
|
2018-04-27 22:05:34 -07:00
|
|
|
const configSchema = require("../schema/markdownlint-config-schema.json");
|
2015-02-27 22:06:54 -08:00
|
|
|
|
2021-11-11 22:37:16 -08:00
|
|
|
const deprecatedRuleNames = new Set(constants.deprecatedRuleNames);
|
2020-09-15 21:48:00 -07:00
|
|
|
const configSchemaStrict = {
|
|
|
|
...configSchema,
|
2023-11-24 15:23:36 -08:00
|
|
|
"$id": `${configSchema.$id}-strict`,
|
2020-09-15 21:48:00 -07:00
|
|
|
"additionalProperties": false
|
|
|
|
};
|
2023-11-25 17:33:39 -08:00
|
|
|
const ajvOptions = {
|
|
|
|
"allowUnionTypes": true
|
|
|
|
};
|
2019-07-08 13:10:08 -05:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("simpleAsync", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-13 12:58:09 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": "# Heading"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const expected = "content: 1: MD047/single-trailing-newline " +
|
|
|
|
"Files should end with a single newline character";
|
|
|
|
markdownlint(options, (err, actual) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2023-01-29 21:13:17 -08:00
|
|
|
// @ts-ignore
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actual.toString(), expected, "Unexpected results.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-13 12:58:09 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-13 12:58:09 -07:00
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("simpleSync", (t) => {
|
|
|
|
t.plan(1);
|
2020-09-13 12:58:09 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": "# Heading"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const expected = "content: 1: MD047/single-trailing-newline " +
|
|
|
|
"Files should end with a single newline character";
|
|
|
|
const actual = markdownlint.sync(options).toString();
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actual, expected, "Unexpected results.");
|
2020-09-13 12:58:09 -07:00
|
|
|
});
|
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("simplePromise", (t) => {
|
|
|
|
t.plan(1);
|
2020-09-13 12:58:09 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": "# Heading"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const expected = "content: 1: MD047/single-trailing-newline " +
|
|
|
|
"Files should end with a single newline character";
|
2021-01-10 20:46:00 -08:00
|
|
|
return markdownlint.promises.markdownlint(options).then((actual) => {
|
|
|
|
t.is(actual.toString(), expected, "Unexpected results.");
|
2020-09-13 12:58:09 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-16 20:41:32 -07:00
|
|
|
test("projectFiles", (t) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2023-03-16 20:41:32 -07:00
|
|
|
return import("globby")
|
|
|
|
.then((module) => module.globby([
|
|
|
|
"*.md",
|
|
|
|
"doc/*.md",
|
|
|
|
"helpers/*.md",
|
|
|
|
"micromark/*.md",
|
|
|
|
"schema/*.md"
|
|
|
|
]))
|
2022-10-29 23:21:45 -07:00
|
|
|
.then((files) => {
|
2024-01-04 23:07:55 -08:00
|
|
|
t.is(files.length, 60);
|
2022-10-29 23:21:45 -07:00
|
|
|
const options = {
|
|
|
|
files,
|
|
|
|
"config": require("../.markdownlint.json")
|
|
|
|
};
|
2023-11-09 19:47:15 -08:00
|
|
|
// @ts-ignore
|
2023-03-16 20:41:32 -07:00
|
|
|
return markdownlint.promises.markdownlint(options).then((actual) => {
|
2022-10-29 23:21:45 -07:00
|
|
|
const expected = {};
|
|
|
|
for (const file of files) {
|
|
|
|
expected[file] = [];
|
|
|
|
}
|
|
|
|
t.deepEqual(actual, expected, "Issue(s) with project files.");
|
|
|
|
});
|
|
|
|
});
|
2023-03-16 20:41:32 -07:00
|
|
|
});
|
2020-09-07 20:05:36 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("stringInputLineEndings", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-04-29 18:46:52 -07:00
|
|
|
"strings": {
|
2019-04-05 12:36:12 +02:00
|
|
|
"cr": "One\rTwo\r#Three\n",
|
|
|
|
"lf": "One\nTwo\n#Three\n",
|
|
|
|
"crlf": "One\r\nTwo\r\n#Three\n",
|
2019-09-14 13:53:35 -07:00
|
|
|
"mixed": "One\rTwo\n#Three\n"
|
2015-07-20 22:06:48 -07:00
|
|
|
},
|
2020-11-15 17:03:20 -08:00
|
|
|
"config": {
|
|
|
|
"MD041": false
|
|
|
|
},
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-04-29 18:46:52 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2015-05-02 17:41:41 -07:00
|
|
|
"cr": { "MD018": [ 3 ] },
|
2015-04-29 18:46:52 -07:00
|
|
|
"lf": { "MD018": [ 3 ] },
|
|
|
|
"crlf": { "MD018": [ 3 ] },
|
2019-09-14 13:53:35 -07:00
|
|
|
"mixed": { "MD018": [ 3 ] }
|
2015-04-29 18:46:52 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-04-29 18:46:52 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-04-29 18:46:52 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("inputOnlyNewline", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-07-22 23:17:08 -07:00
|
|
|
"strings": {
|
|
|
|
"cr": "\r",
|
|
|
|
"lf": "\n",
|
|
|
|
"crlf": "\r\n"
|
|
|
|
},
|
|
|
|
"config": {
|
|
|
|
"default": false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2017-07-05 21:53:21 -07:00
|
|
|
"cr": [],
|
|
|
|
"lf": [],
|
|
|
|
"crlf": []
|
2015-07-22 23:17:08 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-07-22 23:17:08 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-07-22 23:17:08 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("defaultTrue", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-03-16 23:25:06 -07:00
|
|
|
"MD018": [ 1 ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("defaultFalse", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": false
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {},
|
|
|
|
"./test/first_heading_bad_atx.md": {}
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("defaultUndefined", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-18 22:45:51 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-18 22:45:51 -07:00
|
|
|
],
|
2017-07-05 21:53:21 -07:00
|
|
|
"config": {},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-18 22:45:51 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-03-18 22:45:51 -07:00
|
|
|
"MD018": [ 1 ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-18 22:45:51 -07:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD041": [ 1 ]
|
2015-03-18 22:45:51 -07:00
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-18 22:45:51 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-18 22:45:51 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("disableRules", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
2023-07-27 21:42:14 -07:00
|
|
|
"./test/no_first_line_heading.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": true,
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"first-line-h1": false
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-03-16 23:25:06 -07:00
|
|
|
"MD018": [ 1 ]
|
|
|
|
},
|
2023-07-27 21:42:14 -07:00
|
|
|
"./test/no_first_line_heading.md": {}
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("enableRules", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"MD041": true,
|
2015-03-16 23:25:06 -07:00
|
|
|
"default": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"no-multiple-space-atx": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("enableRulesMixedCase", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-09-21 23:21:17 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-09-21 23:21:17 -07:00
|
|
|
],
|
|
|
|
"config": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"Md041": true,
|
2015-09-21 23:21:17 -07:00
|
|
|
"DeFaUlT": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"nO-mUlTiPlE-sPaCe-AtX": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-09-21 23:21:17 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-09-21 23:21:17 -07:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {
|
2023-11-09 19:47:15 -08:00
|
|
|
"MD041": [ 1 ]
|
2015-09-21 23:21:17 -07:00
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-09-21 23:21:17 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-09-21 23:21:17 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("disableTag", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": true,
|
|
|
|
"spaces": false
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("enableTag", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-16 23:25:06 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-16 23:25:06 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": false,
|
2015-09-26 16:55:33 -07:00
|
|
|
"spaces": true,
|
|
|
|
"notatag": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
|
|
|
"resultVersion": 0
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-03-16 23:25:06 -07:00
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {}
|
2015-03-16 23:25:06 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-16 23:25:06 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-16 23:25:06 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("enableTagMixedCase", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-09-21 23:21:17 -07:00
|
|
|
"files": [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-09-21 23:21:17 -07:00
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"DeFaUlT": false,
|
2015-09-26 16:55:33 -07:00
|
|
|
"SpAcEs": true,
|
|
|
|
"NoTaTaG": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
|
|
|
"resultVersion": 0
|
2015-09-21 23:21:17 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md": {
|
2015-09-21 23:21:17 -07:00
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/first_heading_bad_atx.md": {}
|
2015-09-21 23:21:17 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-09-21 23:21:17 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-09-21 23:21:17 -07:00
|
|
|
|
2023-08-22 21:39:09 -07:00
|
|
|
test("styleFiles", async(t) => {
|
|
|
|
t.plan(8);
|
|
|
|
const files = await fs.promises.readdir("./style");
|
|
|
|
for (const file of files) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2015-03-17 22:34:47 -07:00
|
|
|
|
2024-01-04 23:07:55 -08:00
|
|
|
test("styleAll", async(t) => {
|
|
|
|
t.plan(1);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-17 18:02:05 -07:00
|
|
|
"files": [ "./test/break-all-the-rules.md" ],
|
2017-07-05 21:53:21 -07:00
|
|
|
"config": require("../style/all.json"),
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-17 18:02:05 -07:00
|
|
|
};
|
2024-01-04 23:07:55 -08:00
|
|
|
const actualResult = await markdownlint.promises.markdownlint(options);
|
|
|
|
const expectedResult = {
|
|
|
|
"./test/break-all-the-rules.md": {
|
|
|
|
"MD001": [ 3 ],
|
|
|
|
"MD003": [ 5, 31 ],
|
|
|
|
"MD004": [ 8 ],
|
|
|
|
"MD005": [ 12 ],
|
|
|
|
"MD007": [ 8, 11 ],
|
|
|
|
"MD009": [ 14 ],
|
|
|
|
"MD010": [ 14 ],
|
|
|
|
"MD011": [ 16 ],
|
|
|
|
"MD012": [ 18 ],
|
|
|
|
"MD013": [ 21 ],
|
|
|
|
"MD014": [ 23 ],
|
|
|
|
"MD018": [ 25 ],
|
|
|
|
"MD019": [ 27 ],
|
|
|
|
"MD020": [ 29 ],
|
|
|
|
"MD021": [ 31 ],
|
|
|
|
"MD022": [ 86 ],
|
|
|
|
"MD023": [ 40 ],
|
|
|
|
"MD024": [ 35 ],
|
|
|
|
"MD026": [ 40 ],
|
|
|
|
"MD027": [ 42 ],
|
|
|
|
"MD028": [ 43 ],
|
|
|
|
"MD029": [ 47 ],
|
|
|
|
"MD030": [ 8 ],
|
|
|
|
"MD031": [ 50 ],
|
|
|
|
"MD032": [ 7, 8, 51 ],
|
|
|
|
"MD033": [ 55 ],
|
|
|
|
"MD034": [ 57 ],
|
|
|
|
"MD035": [ 61 ],
|
|
|
|
"MD036": [ 65 ],
|
|
|
|
"MD037": [ 67 ],
|
|
|
|
"MD038": [ 69 ],
|
|
|
|
"MD039": [ 71 ],
|
|
|
|
"MD040": [ 73 ],
|
|
|
|
"MD041": [ 1 ],
|
|
|
|
"MD042": [ 81 ],
|
|
|
|
"MD045": [ 85 ],
|
|
|
|
"MD046": [ 49, 73, 77 ],
|
|
|
|
"MD047": [ 134 ],
|
|
|
|
"MD048": [ 77 ],
|
|
|
|
"MD049": [ 90 ],
|
|
|
|
"MD050": [ 94 ],
|
|
|
|
"MD051": [ 96 ],
|
|
|
|
"MD052": [ 98 ],
|
|
|
|
"MD053": [ 100 ],
|
|
|
|
"MD055": [ 110 ],
|
|
|
|
"MD056": [ 114 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
});
|
2015-03-17 18:02:05 -07:00
|
|
|
|
2024-01-04 23:07:55 -08:00
|
|
|
test("styleRelaxed", async(t) => {
|
|
|
|
t.plan(1);
|
2018-04-27 22:05:34 -07:00
|
|
|
const options = {
|
2015-03-17 18:02:05 -07:00
|
|
|
"files": [ "./test/break-all-the-rules.md" ],
|
2017-07-05 21:53:21 -07:00
|
|
|
"config": require("../style/relaxed.json"),
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2017-07-05 21:53:21 -07:00
|
|
|
"resultVersion": 0
|
2015-03-17 18:02:05 -07:00
|
|
|
};
|
2024-01-04 23:07:55 -08:00
|
|
|
const actualResult = await markdownlint.promises.markdownlint(options);
|
|
|
|
const expectedResult = {
|
|
|
|
"./test/break-all-the-rules.md": {
|
|
|
|
"MD001": [ 3 ],
|
|
|
|
"MD003": [ 5, 31 ],
|
|
|
|
"MD004": [ 8 ],
|
|
|
|
"MD005": [ 12 ],
|
|
|
|
"MD011": [ 16 ],
|
|
|
|
"MD014": [ 23 ],
|
|
|
|
"MD018": [ 25 ],
|
|
|
|
"MD019": [ 27 ],
|
|
|
|
"MD020": [ 29 ],
|
|
|
|
"MD021": [ 31 ],
|
|
|
|
"MD022": [ 86 ],
|
|
|
|
"MD023": [ 40 ],
|
|
|
|
"MD024": [ 35 ],
|
|
|
|
"MD026": [ 40 ],
|
|
|
|
"MD029": [ 47 ],
|
|
|
|
"MD031": [ 50 ],
|
|
|
|
"MD032": [ 7, 8, 51 ],
|
|
|
|
"MD035": [ 61 ],
|
|
|
|
"MD036": [ 65 ],
|
|
|
|
"MD042": [ 81 ],
|
|
|
|
"MD045": [ 85 ],
|
|
|
|
"MD046": [ 49, 73, 77 ],
|
|
|
|
"MD047": [ 134 ],
|
|
|
|
"MD048": [ 77 ],
|
|
|
|
"MD049": [ 90 ],
|
|
|
|
"MD050": [ 94 ],
|
|
|
|
"MD051": [ 96 ],
|
|
|
|
"MD052": [ 98 ],
|
|
|
|
"MD053": [ 100 ],
|
|
|
|
"MD055": [ 110 ],
|
|
|
|
"MD056": [ 114 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
});
|
2015-03-17 18:02:05 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("nullFrontMatter", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2015-07-25 22:18:30 -07:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"content": "---\n\t\n---\n# Heading\n"
|
2015-07-25 22:18:30 -07:00
|
|
|
},
|
|
|
|
"frontMatter": null,
|
|
|
|
"config": {
|
|
|
|
"default": false,
|
|
|
|
"MD010": true
|
2017-07-05 21:53:21 -07:00
|
|
|
},
|
|
|
|
"resultVersion": 0
|
2015-07-25 22:18:30 -07:00
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2015-07-25 22:18:30 -07:00
|
|
|
"content": { "MD010": [ 2 ] }
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(result, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-07-25 22:18:30 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-07-25 22:18:30 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("customFrontMatter", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2015-07-25 22:18:30 -07:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"content": "<head>\n\t\n</head>\n# Heading\n"
|
2015-07-25 22:18:30 -07:00
|
|
|
},
|
2022-12-19 21:36:24 -08:00
|
|
|
"frontMatter": /<head>[\s\S]*<\/head>/,
|
2015-07-25 22:18:30 -07:00
|
|
|
"config": {
|
|
|
|
"default": false,
|
|
|
|
"MD010": true
|
|
|
|
}
|
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2017-07-05 21:53:21 -07:00
|
|
|
"content": []
|
2015-07-25 22:18:30 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(result, expectedResult, "Did not get empty results.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-07-25 22:18:30 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-07-25 22:18:30 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("noInlineConfig", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2017-05-21 22:58:10 -07:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"# Heading",
|
|
|
|
"",
|
|
|
|
"\tTab",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-disable-->",
|
|
|
|
"",
|
|
|
|
"\tTab",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-enable-->",
|
|
|
|
"",
|
2019-04-05 12:36:12 +02:00
|
|
|
"\tTab\n"
|
2017-05-21 22:58:10 -07:00
|
|
|
].join("\n")
|
|
|
|
},
|
2017-07-05 21:53:21 -07:00
|
|
|
"noInlineConfig": true,
|
|
|
|
"resultVersion": 0
|
2017-05-21 22:58:10 -07:00
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2017-05-21 22:58:10 -07:00
|
|
|
"content": {
|
|
|
|
"MD010": [ 3, 7, 11 ]
|
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(result, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2017-05-21 22:58:10 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2017-05-21 22:58:10 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("readmeHeadings", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2016-07-02 22:37:52 -07:00
|
|
|
markdownlint({
|
|
|
|
"files": "README.md",
|
2017-05-21 22:58:10 -07:00
|
|
|
"noInlineConfig": true,
|
2016-07-02 22:37:52 -07:00
|
|
|
"config": {
|
|
|
|
"default": false,
|
2016-10-16 21:46:02 -07:00
|
|
|
"MD013": {
|
|
|
|
"line_length": 150
|
|
|
|
},
|
2016-07-02 22:37:52 -07:00
|
|
|
"MD043": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"headings": [
|
2016-07-02 22:37:52 -07:00
|
|
|
"# markdownlint",
|
|
|
|
"## Install",
|
|
|
|
"## Overview",
|
|
|
|
"### Related",
|
2023-05-26 20:28:21 -07:00
|
|
|
"### References",
|
2016-07-02 22:37:52 -07:00
|
|
|
"## Demonstration",
|
|
|
|
"## Rules / Aliases",
|
2022-12-10 08:04:45 +05:30
|
|
|
"### Custom Rules",
|
2016-07-02 22:37:52 -07:00
|
|
|
"## Tags",
|
|
|
|
"## Configuration",
|
|
|
|
"## API",
|
2017-05-19 22:36:46 -07:00
|
|
|
"### Linting",
|
|
|
|
"#### options",
|
2022-06-04 15:06:07 -07:00
|
|
|
"##### options.config",
|
2022-06-05 22:32:22 -07:00
|
|
|
"##### options.configParsers",
|
2018-02-15 21:35:58 -08:00
|
|
|
"##### options.customRules",
|
2017-05-19 22:36:46 -07:00
|
|
|
"##### options.files",
|
2017-05-21 22:58:10 -07:00
|
|
|
"##### options.frontMatter",
|
2022-06-04 15:06:07 -07:00
|
|
|
"##### options.fs",
|
2019-05-18 12:32:52 -07:00
|
|
|
"##### options.handleRuleFailures",
|
2022-06-04 15:06:07 -07:00
|
|
|
"##### options.markdownItPlugins",
|
2017-05-21 22:58:10 -07:00
|
|
|
"##### options.noInlineConfig",
|
2017-05-19 22:36:46 -07:00
|
|
|
"##### options.resultVersion",
|
2022-06-04 15:06:07 -07:00
|
|
|
"##### options.strings",
|
2017-05-19 22:36:46 -07:00
|
|
|
"#### callback",
|
|
|
|
"#### result",
|
|
|
|
"### Config",
|
|
|
|
"#### file",
|
2018-05-23 22:24:40 -07:00
|
|
|
"#### parsers",
|
2021-08-12 19:38:03 -07:00
|
|
|
"#### fs",
|
2017-05-19 22:36:46 -07:00
|
|
|
"#### callback",
|
|
|
|
"#### result",
|
2016-07-02 22:37:52 -07:00
|
|
|
"## Usage",
|
2022-12-03 15:48:08 -05:00
|
|
|
"### Fixing",
|
2016-07-02 22:37:52 -07:00
|
|
|
"## Browser",
|
2017-11-21 21:58:42 -08:00
|
|
|
"## Examples",
|
2018-06-24 20:01:44 -07:00
|
|
|
"## Contributing",
|
2022-12-13 16:42:54 -08:00
|
|
|
"## Releasing",
|
2016-07-02 22:37:52 -07:00
|
|
|
"## History"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expected = { "README.md": [] };
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(result, expected, "Unexpected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2016-07-02 22:37:52 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2016-07-02 22:37:52 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("filesArrayNotModified", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2018-04-27 22:05:34 -07:00
|
|
|
const files = [
|
2018-03-19 23:39:42 +01:00
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
2015-03-13 18:20:56 -07:00
|
|
|
];
|
Update dependencies: c8 to 7.7.2, eslint to 7.28.0, eslint-plugin-jsdoc to 35.1.3, eslint-plugin-unicorn to 33.0.1, globby to 11.0.3, js-yaml to 4.1.0, markdown-it-texmath to 0.9.0, markdownlint-rule-helpers to 0.14.0, ts-loader to 9.2.3, typescript to 4.3.2, webpack to 5.38.1, webpack-cli to 4.7.2.
2021-06-08 22:20:13 -07:00
|
|
|
const expectedFiles = [ ...files ];
|
2015-03-13 18:20:56 -07:00
|
|
|
markdownlint({ "files": files }, function callback(err) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
|
|
|
t.deepEqual(files, expectedFiles, "Files modified.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-13 18:20:56 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-13 18:20:56 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("filesArrayAsString", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2016-01-15 22:00:34 -08:00
|
|
|
markdownlint({
|
|
|
|
"files": "README.md",
|
2017-05-21 22:58:10 -07:00
|
|
|
"noInlineConfig": true,
|
|
|
|
"config": {
|
|
|
|
"MD013": { "line_length": 150 },
|
|
|
|
"MD024": false
|
|
|
|
}
|
2016-01-15 22:00:34 -08:00
|
|
|
}, function callback(err, actual) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expected = { "README.md": [] };
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actual, expected, "Unexpected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2016-01-15 22:00:34 -08:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2016-01-15 22:00:34 -08:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("missingOptions", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2015-03-11 21:13:21 -07:00
|
|
|
markdownlint(null, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
|
|
|
t.deepEqual(
|
2020-09-05 17:24:52 -07:00
|
|
|
result,
|
|
|
|
{},
|
|
|
|
"Did not get empty result for missing options."
|
|
|
|
);
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-11 21:13:21 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-11 21:13:21 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("missingFilesAndStrings", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2015-03-11 21:13:21 -07:00
|
|
|
markdownlint({}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
|
|
|
t.truthy(result, "Did not get result for missing files/strings.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-11 21:13:21 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-11 21:13:21 -07:00
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("missingCallback", (t) => {
|
|
|
|
t.plan(0);
|
2019-10-30 20:37:06 -07:00
|
|
|
// @ts-ignore
|
2015-03-11 21:13:21 -07:00
|
|
|
markdownlint();
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
2015-03-11 21:13:21 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("badFile", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(4);
|
2015-03-11 21:13:21 -07:00
|
|
|
markdownlint({
|
|
|
|
"files": [ "./badFile" ]
|
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.truthy(err, "Did not get an error for bad file.");
|
|
|
|
t.true(err instanceof Error, "Error not instance of Error.");
|
2019-10-30 20:37:06 -07:00
|
|
|
// @ts-ignore
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(err.code, "ENOENT", "Error code for bad file not ENOENT.");
|
|
|
|
t.true(!result, "Got result for bad file.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-03-11 21:13:21 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-03-17 22:34:47 -07:00
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("badFileSync", (t) => {
|
|
|
|
t.plan(1);
|
|
|
|
t.throws(
|
2020-01-08 22:13:51 -08:00
|
|
|
function badFileCall() {
|
|
|
|
markdownlint.sync({
|
|
|
|
"files": [ "./badFile" ]
|
|
|
|
});
|
|
|
|
},
|
2021-01-10 20:46:00 -08:00
|
|
|
{
|
|
|
|
"message": /ENOENT/
|
|
|
|
},
|
2020-01-08 22:13:51 -08:00
|
|
|
"Did not get correct exception for bad file."
|
|
|
|
);
|
|
|
|
});
|
2015-03-20 00:09:55 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("badFilePromise", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(3);
|
2020-09-13 12:58:09 -07:00
|
|
|
markdownlint.promises.markdownlint({
|
|
|
|
"files": [ "./badFile" ]
|
|
|
|
}).then(
|
|
|
|
null,
|
|
|
|
(error) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.truthy(error, "Did not get an error for bad file.");
|
|
|
|
t.true(error instanceof Error, "Error not instance of Error.");
|
|
|
|
t.is(error.code, "ENOENT", "Error code for bad file not ENOENT.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-13 12:58:09 -07:00
|
|
|
}
|
|
|
|
);
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-13 12:58:09 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("missingStringValue", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2015-04-29 18:46:52 -07:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
2023-01-29 21:13:17 -08:00
|
|
|
// @ts-ignore
|
2015-04-29 18:46:52 -07:00
|
|
|
"undefined": undefined,
|
2023-01-29 21:13:17 -08:00
|
|
|
// @ts-ignore
|
2015-04-29 18:46:52 -07:00
|
|
|
"null": null,
|
|
|
|
"empty": ""
|
2020-11-15 17:03:20 -08:00
|
|
|
}
|
2015-04-29 18:46:52 -07:00
|
|
|
}, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2018-04-27 22:05:34 -07:00
|
|
|
const expectedResult = {
|
2017-07-05 21:53:21 -07:00
|
|
|
"undefined": [],
|
|
|
|
"null": [],
|
|
|
|
"empty": []
|
2015-04-29 18:46:52 -07:00
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(result, expectedResult, "Did not get empty results.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2015-04-29 18:46:52 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2015-04-29 18:46:52 -07:00
|
|
|
|
2021-08-12 19:38:03 -07:00
|
|
|
test("customFileSystemSync", (t) => {
|
|
|
|
t.plan(2);
|
|
|
|
const file = "/dir/file.md";
|
|
|
|
const fsApi = {
|
|
|
|
"readFileSync": (p) => {
|
|
|
|
t.is(p, file);
|
|
|
|
return "# Heading";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const result = markdownlint.sync({
|
|
|
|
"files": file,
|
|
|
|
"fs": fsApi
|
|
|
|
});
|
|
|
|
t.deepEqual(result[file].length, 1, "Did not report violations.");
|
|
|
|
});
|
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("customFileSystemAsync", (t) => new Promise((resolve) => {
|
2021-08-12 19:38:03 -07:00
|
|
|
t.plan(3);
|
|
|
|
const file = "/dir/file.md";
|
|
|
|
const fsApi = {
|
|
|
|
"readFile": (p, o, cb) => {
|
|
|
|
t.is(p, file);
|
|
|
|
cb(null, "# Heading");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint({
|
|
|
|
"files": file,
|
|
|
|
"fs": fsApi
|
|
|
|
}, function callback(err, result) {
|
|
|
|
t.falsy(err);
|
2023-01-29 21:13:17 -08:00
|
|
|
// @ts-ignore
|
2021-08-12 19:38:03 -07:00
|
|
|
t.deepEqual(result[file].length, 1, "Did not report violations.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2021-08-12 19:38:03 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2021-11-30 22:03:31 -08:00
|
|
|
|
2023-08-22 21:39:09 -07:00
|
|
|
test("readme", async(t) => {
|
2024-01-04 23:07:55 -08:00
|
|
|
t.plan(126);
|
2018-04-27 22:05:34 -07:00
|
|
|
const tagToRules = {};
|
2022-06-08 22:10:27 -07:00
|
|
|
for (const rule of rules) {
|
|
|
|
for (const tag of rule.tags) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const tagRules = tagToRules[tag] || [];
|
2018-01-12 23:21:06 -08:00
|
|
|
tagRules.push(rule.names[0]);
|
2015-04-14 00:01:57 -07:00
|
|
|
tagToRules[tag] = tagRules;
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
|
|
|
}
|
2023-08-22 21:39:09 -07:00
|
|
|
const contents = await fs.promises.readFile("README.md", "utf8");
|
|
|
|
const rulesLeft = [ ...rules ];
|
|
|
|
let seenRelated = false;
|
|
|
|
let seenReferences = false;
|
|
|
|
let seenRules = false;
|
|
|
|
let inRules = false;
|
|
|
|
let seenTags = false;
|
|
|
|
let inTags = false;
|
|
|
|
// @ts-ignore
|
|
|
|
for (const token of md.parse(contents, {})) {
|
|
|
|
if (
|
|
|
|
(token.type === "bullet_list_open") &&
|
|
|
|
(token.level === 0)
|
|
|
|
) {
|
|
|
|
if (!seenRelated) {
|
|
|
|
seenRelated = true;
|
|
|
|
} else if (!seenReferences) {
|
|
|
|
seenReferences = true;
|
|
|
|
} else if (!seenRules) {
|
|
|
|
seenRules = true;
|
|
|
|
inRules = true;
|
|
|
|
} else if (!seenTags) {
|
|
|
|
seenTags = true;
|
|
|
|
inTags = true;
|
|
|
|
}
|
|
|
|
} else if (
|
|
|
|
(token.type === "bullet_list_close") &&
|
|
|
|
(token.level === 0)
|
|
|
|
) {
|
|
|
|
inRules = false;
|
|
|
|
inTags = false;
|
|
|
|
} else if (token.type === "inline") {
|
|
|
|
if (inRules) {
|
|
|
|
const rule = rulesLeft.shift();
|
|
|
|
t.truthy(rule,
|
|
|
|
"Missing rule implementation for " + token.content + ".");
|
|
|
|
if (rule) {
|
|
|
|
const ruleName = rule.names[0];
|
|
|
|
const ruleAliases = rule.names.slice(1);
|
|
|
|
let expected = "**[" + ruleName + "](doc/" +
|
|
|
|
ruleName.toLowerCase() + ".md)** *" +
|
|
|
|
ruleAliases.join("/") + "* - " + rule.description;
|
|
|
|
if (deprecatedRuleNames.has(ruleName)) {
|
|
|
|
expected = "~~" + expected + "~~";
|
2015-03-17 22:34:47 -07:00
|
|
|
}
|
2023-08-22 21:39:09 -07:00
|
|
|
t.is(token.content, expected, "Rule mismatch.");
|
2015-03-17 22:34:47 -07:00
|
|
|
}
|
2023-08-22 21:39:09 -07:00
|
|
|
} else if (inTags) {
|
|
|
|
const parts =
|
|
|
|
token.content.replace(/[`*]/g, "").split(/ - |, |,\n/);
|
|
|
|
const tag = parts.shift();
|
|
|
|
t.deepEqual(parts, tagToRules[tag] || [],
|
|
|
|
"Rule mismatch for tag " + tag + ".");
|
|
|
|
delete tagToRules[tag];
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2023-08-22 21:39:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const ruleLeft = rulesLeft.shift();
|
|
|
|
t.true(!ruleLeft,
|
|
|
|
"Missing rule documentation for " +
|
|
|
|
(ruleLeft || "[NO RULE]").toString() + ".");
|
|
|
|
const tagLeft = Object.keys(tagToRules).shift();
|
|
|
|
t.true(!tagLeft, "Undocumented tag " + tagLeft + ".");
|
|
|
|
});
|
2015-03-17 22:34:47 -07:00
|
|
|
|
2023-09-27 22:48:01 -07:00
|
|
|
test("validateJsonUsingConfigSchemaStrict", async(t) => {
|
2023-12-30 18:15:38 -08:00
|
|
|
t.plan(178);
|
2023-11-25 17:33:39 -08:00
|
|
|
// @ts-ignore
|
|
|
|
const ajv = new Ajv(ajvOptions);
|
|
|
|
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
2023-03-16 20:41:32 -07:00
|
|
|
const configRe =
|
|
|
|
/^[\s\S]*<!-- markdownlint-configure-file ([\s\S]*) -->[\s\S]*$/;
|
|
|
|
const ignoreFiles = new Set([
|
|
|
|
"README.md",
|
|
|
|
"test/inline-configure-file-invalid.md",
|
|
|
|
"test/inline-configure-file-violations.md",
|
|
|
|
"test/invalid-ul-style-style.md",
|
|
|
|
"test/wrong-types-in-config-file.md"
|
|
|
|
]);
|
2023-09-27 22:48:01 -07:00
|
|
|
const { globby } = await import("globby");
|
|
|
|
const files = await globby([
|
|
|
|
"*.md",
|
|
|
|
"doc/*.md",
|
|
|
|
"helpers/*.md",
|
|
|
|
"micromark/*.md",
|
|
|
|
"schema/*.md",
|
|
|
|
"test/*.md"
|
|
|
|
]);
|
|
|
|
const testFiles = files.filter((file) => !ignoreFiles.has(file));
|
|
|
|
for (const file of testFiles) {
|
|
|
|
const data = fs.readFileSync(file, "utf8");
|
|
|
|
if (configRe.test(data)) {
|
|
|
|
const config = data.replace(configRe, "$1");
|
2023-11-25 17:33:39 -08:00
|
|
|
const result = validateSchemaStrict(JSON.parse(config));
|
|
|
|
t.truthy(
|
|
|
|
result,
|
|
|
|
`${file}\n${JSON.stringify(validateSchemaStrict.errors, null, 2)}`
|
2023-09-27 22:48:01 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 20:41:32 -07:00
|
|
|
});
|
|
|
|
|
2023-11-25 17:33:39 -08:00
|
|
|
test("validateConfigSchemaAllowsUnknownProperties", (t) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(4);
|
2023-11-25 17:33:39 -08:00
|
|
|
// @ts-ignore
|
|
|
|
const ajv = new Ajv(ajvOptions);
|
|
|
|
const validateSchema = ajv.compile(configSchema);
|
|
|
|
const validateSchemaStrict = ajv.compile(configSchemaStrict);
|
2020-09-15 21:48:00 -07:00
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
"property": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"property": {
|
|
|
|
"object": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2022-06-08 22:10:27 -07:00
|
|
|
for (const testCase of testCases) {
|
2023-11-25 17:33:39 -08:00
|
|
|
const result = validateSchema(testCase);
|
|
|
|
t.truthy(
|
|
|
|
result,
|
|
|
|
"Unknown property blocked by default: " + JSON.stringify(validateSchema.errors, null, 2)
|
2023-09-27 22:48:01 -07:00
|
|
|
);
|
2023-11-25 17:33:39 -08:00
|
|
|
const resultStrict = validateSchemaStrict(testCase);
|
|
|
|
t.falsy(
|
|
|
|
resultStrict,
|
|
|
|
"Unknown property allowed when strict: " + JSON.stringify(validateSchemaStrict.errors, null, 2)
|
2023-09-27 22:48:01 -07:00
|
|
|
);
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2020-09-15 21:48:00 -07:00
|
|
|
});
|
|
|
|
|
2023-11-25 17:33:39 -08:00
|
|
|
test("validateConfigSchemaAppliesToUnknownProperties", (t) => {
|
2021-06-15 22:25:51 -07:00
|
|
|
t.plan(4);
|
2023-11-25 17:33:39 -08:00
|
|
|
// @ts-ignore
|
|
|
|
const ajv = new Ajv(ajvOptions);
|
|
|
|
const validateSchema = ajv.compile(configSchema);
|
2021-06-15 22:25:51 -07:00
|
|
|
for (const allowed of [ true, {} ]) {
|
2023-11-25 17:33:39 -08:00
|
|
|
t.truthy(
|
|
|
|
validateSchema({ "property": allowed }),
|
2023-09-27 22:48:01 -07:00
|
|
|
`Unknown property value ${allowed} blocked`
|
|
|
|
);
|
2021-06-15 22:25:51 -07:00
|
|
|
}
|
|
|
|
for (const blocked of [ 2, "string" ]) {
|
2023-11-25 17:33:39 -08:00
|
|
|
t.falsy(
|
|
|
|
validateSchema({ "property": blocked }),
|
2023-09-27 22:48:01 -07:00
|
|
|
`Unknown property value ${blocked} allowed`
|
|
|
|
);
|
2021-06-15 22:25:51 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-27 21:59:56 +00:00
|
|
|
test("validateConfigExampleJson", async(t) => {
|
2023-11-25 17:38:13 -08:00
|
|
|
t.plan(3);
|
2021-12-27 21:59:56 +00:00
|
|
|
const { "default": stripJsonComments } = await import("strip-json-comments");
|
2023-09-27 22:48:01 -07:00
|
|
|
|
|
|
|
// Validate schema
|
2023-11-25 17:33:39 -08:00
|
|
|
// @ts-ignore
|
|
|
|
const ajv = new Ajv(ajvOptions);
|
|
|
|
const validateSchema = ajv.compile(configSchema);
|
2023-11-25 17:38:13 -08:00
|
|
|
t.is(configSchema.$id, configSchema.properties.$schema.default);
|
2023-09-27 22:48:01 -07:00
|
|
|
|
2021-01-21 19:50:57 -08:00
|
|
|
// Validate JSONC
|
|
|
|
const fileJson = ".markdownlint.jsonc";
|
|
|
|
const dataJson = fs.readFileSync(
|
|
|
|
path.join(__dirname, "../schema", fileJson),
|
2021-01-19 20:41:04 -08:00
|
|
|
"utf8"
|
|
|
|
);
|
2021-01-21 19:50:57 -08:00
|
|
|
const jsonObject = JSON.parse(stripJsonComments(dataJson));
|
2023-11-25 17:33:39 -08:00
|
|
|
const result = validateSchema(jsonObject);
|
|
|
|
t.truthy(
|
|
|
|
result,
|
|
|
|
`${fileJson}\n${JSON.stringify(validateSchema.errors, null, 2)}`
|
2023-09-27 22:48:01 -07:00
|
|
|
);
|
|
|
|
|
2021-01-21 19:50:57 -08:00
|
|
|
// Validate YAML
|
|
|
|
const fileYaml = ".markdownlint.yaml";
|
|
|
|
const dataYaml = fs.readFileSync(
|
|
|
|
path.join(__dirname, "../schema", fileYaml),
|
|
|
|
"utf8"
|
|
|
|
);
|
2021-02-06 19:23:55 -08:00
|
|
|
const yamlObject = jsYaml.load(dataYaml);
|
2021-01-21 19:50:57 -08:00
|
|
|
t.deepEqual(yamlObject, jsonObject,
|
|
|
|
"YAML example does not match JSON example.");
|
2021-01-19 20:41:04 -08:00
|
|
|
});
|
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("allBuiltInRulesHaveValidUrl", (t) => {
|
2024-01-04 23:07:55 -08:00
|
|
|
t.plan(150);
|
2022-06-08 22:10:27 -07:00
|
|
|
for (const rule of rules) {
|
|
|
|
// @ts-ignore
|
2021-01-10 20:46:00 -08:00
|
|
|
t.truthy(rule.information);
|
2022-06-08 22:10:27 -07:00
|
|
|
// @ts-ignore
|
2021-01-10 20:46:00 -08:00
|
|
|
t.true(Object.getPrototypeOf(rule.information) === URL.prototype);
|
2020-01-08 22:13:51 -08:00
|
|
|
const name = rule.names[0].toLowerCase();
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(
|
2022-06-08 22:10:27 -07:00
|
|
|
// @ts-ignore
|
2020-01-08 22:13:51 -08:00
|
|
|
rule.information.href,
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/${name}.md`
|
2020-01-08 22:13:51 -08:00
|
|
|
);
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("someCustomRulesHaveValidUrl", (t) => {
|
2022-01-11 23:08:53 -08:00
|
|
|
t.plan(8);
|
2022-06-08 22:10:27 -07:00
|
|
|
for (const rule of customRules.all) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.true(!rule.information ||
|
2020-01-08 22:13:51 -08:00
|
|
|
(Object.getPrototypeOf(rule.information) === URL.prototype));
|
|
|
|
if (rule === customRules.anyBlockquote) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(
|
2019-01-15 21:56:38 -08:00
|
|
|
rule.information.href,
|
2020-08-11 22:52:29 -07:00
|
|
|
`${homepage}/blob/main/test/rules/any-blockquote.js`
|
2019-01-15 21:56:38 -08:00
|
|
|
);
|
2020-01-08 22:13:51 -08:00
|
|
|
} else if (rule === customRules.lettersEX) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(
|
2020-01-08 22:13:51 -08:00
|
|
|
rule.information.href,
|
2020-08-11 22:52:29 -07:00
|
|
|
`${homepage}/blob/main/test/rules/letters-E-X.js`
|
2020-01-08 22:13:51 -08:00
|
|
|
);
|
|
|
|
}
|
2022-06-08 22:10:27 -07:00
|
|
|
}
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
2019-01-15 21:56:38 -08:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("markdownItPluginsSingle", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-01-08 22:13:51 -08:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"string": "# Heading\n\nText [ link ](https://example.com)\n"
|
|
|
|
},
|
|
|
|
"markdownItPlugins": [
|
|
|
|
[
|
|
|
|
pluginInline,
|
|
|
|
"trim_text_plugin",
|
|
|
|
"text",
|
|
|
|
function iterator(tokens, index) {
|
|
|
|
tokens[index].content = tokens[index].content.trim();
|
|
|
|
}
|
2019-01-19 12:52:13 -08:00
|
|
|
]
|
2020-01-08 22:13:51 -08:00
|
|
|
]
|
|
|
|
}, function callback(err, actual) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-01-08 22:13:51 -08:00
|
|
|
const expected = { "string": [] };
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actual, expected, "Unexpected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2019-01-19 12:52:13 -08:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("markdownItPluginsMultiple", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(4);
|
2020-01-08 22:13:51 -08:00
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"string": "# Heading\n\nText H~2~0 text 29^th^ text\n"
|
|
|
|
},
|
|
|
|
"markdownItPlugins": [
|
|
|
|
[ pluginSub ],
|
|
|
|
[ pluginSup ],
|
2021-01-10 20:46:00 -08:00
|
|
|
[ pluginInline, "check_sub_plugin", "sub_open", () => t.true(true) ],
|
|
|
|
[ pluginInline, "check_sup_plugin", "sup_open", () => t.true(true) ]
|
2020-01-08 22:13:51 -08:00
|
|
|
]
|
|
|
|
}, function callback(err, actual) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-01-08 22:13:51 -08:00
|
|
|
const expected = { "string": [] };
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actual, expected, "Unexpected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-01-08 22:13:51 -08:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-01-08 22:13:51 -08:00
|
|
|
|
2023-01-29 20:36:53 -08:00
|
|
|
test("Pandoc footnote", (t) => new Promise((resolve) => {
|
2022-10-19 21:12:51 -07:00
|
|
|
t.plan(2);
|
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"string":
|
|
|
|
`# Heading
|
|
|
|
|
|
|
|
Text with: [^footnote]
|
|
|
|
|
|
|
|
[^footnote]: Footnote text on multiple
|
|
|
|
|
|
|
|
lines including a [reference][]
|
|
|
|
|
|
|
|
[reference]: https://example.com
|
|
|
|
`
|
|
|
|
},
|
|
|
|
"resultVersion": 0
|
|
|
|
}, (err, actual) => {
|
|
|
|
t.falsy(err);
|
|
|
|
const expected = { "string": {} };
|
|
|
|
t.deepEqual(actual, expected, "Unexpected issues.");
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2021-11-26 04:26:15 +00:00
|
|
|
test("token-map-spans", (t) => {
|
|
|
|
t.plan(38);
|
|
|
|
const options = {
|
|
|
|
"customRules": [
|
|
|
|
{
|
|
|
|
"names": [ "token-map-spans" ],
|
|
|
|
"description": "token-map-spans",
|
|
|
|
"tags": [ "tms" ],
|
|
|
|
"function": function tokenMapSpans(params) {
|
|
|
|
const tokenLines = [];
|
|
|
|
let lastLineNumber = -1;
|
2023-02-18 21:41:07 -08:00
|
|
|
const inlines = params.parsers.markdownit.tokens.filter(
|
|
|
|
(c) => c.type === "inline"
|
|
|
|
);
|
2021-11-26 04:26:15 +00:00
|
|
|
for (const token of inlines) {
|
|
|
|
t.truthy(token.map);
|
|
|
|
for (let i = token.map[0]; i < token.map[1]; i++) {
|
|
|
|
if (tokenLines.includes(i)) {
|
|
|
|
t.true(
|
|
|
|
lastLineNumber === token.lineNumber,
|
|
|
|
`Line ${i + 1} is part of token maps from multiple lines.`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
tokenLines.push(i);
|
|
|
|
}
|
|
|
|
lastLineNumber = token.lineNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"files": [ "./test/token-map-spans.md" ]
|
|
|
|
};
|
|
|
|
markdownlint.sync(options);
|
|
|
|
});
|
|
|
|
|
2022-06-05 22:32:22 -07:00
|
|
|
test("configParsersInvalid", async(t) => {
|
|
|
|
t.plan(1);
|
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"Text",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-configure-file",
|
|
|
|
" \"first-line-heading\": false",
|
|
|
|
"-->",
|
|
|
|
""
|
|
|
|
].join("\n")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const expected = "content: 1: MD041/first-line-heading/first-line-h1 " +
|
|
|
|
"First line in a file should be a top-level heading [Context: \"Text\"]";
|
|
|
|
const actual = await markdownlint.promises.markdownlint(options);
|
|
|
|
t.is(actual.toString(), expected, "Unexpected results.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("configParsersJSON", async(t) => {
|
|
|
|
t.plan(1);
|
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"Text",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-configure-file",
|
|
|
|
"{",
|
|
|
|
" \"first-line-heading\": false",
|
|
|
|
"}",
|
|
|
|
"-->",
|
|
|
|
""
|
|
|
|
].join("\n")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const actual = await markdownlint.promises.markdownlint(options);
|
|
|
|
t.is(actual.toString(), "", "Unexpected results.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("configParsersJSONC", async(t) => {
|
|
|
|
t.plan(1);
|
|
|
|
const { "default": stripJsonComments } = await import("strip-json-comments");
|
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"Text",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-configure-file",
|
|
|
|
"/* Comment */",
|
|
|
|
"{",
|
|
|
|
" \"first-line-heading\": false // Comment",
|
|
|
|
"}",
|
|
|
|
"-->",
|
|
|
|
""
|
|
|
|
].join("\n")
|
|
|
|
},
|
|
|
|
"configParsers": [ (content) => JSON.parse(stripJsonComments(content)) ]
|
|
|
|
};
|
|
|
|
const actual = await markdownlint.promises.markdownlint(options);
|
|
|
|
t.is(actual.toString(), "", "Unexpected results.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("configParsersYAML", async(t) => {
|
|
|
|
t.plan(1);
|
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"Text",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-configure-file",
|
|
|
|
"# Comment",
|
|
|
|
"first-line-heading: false",
|
|
|
|
"-->",
|
|
|
|
""
|
|
|
|
].join("\n")
|
|
|
|
},
|
|
|
|
"configParsers": [ jsYaml.load ]
|
|
|
|
};
|
2023-01-29 21:13:17 -08:00
|
|
|
// @ts-ignore
|
2022-06-05 22:32:22 -07:00
|
|
|
const actual = await markdownlint.promises.markdownlint(options);
|
|
|
|
t.is(actual.toString(), "", "Unexpected results.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("configParsersTOML", async(t) => {
|
|
|
|
t.plan(1);
|
|
|
|
const { "default": stripJsonComments } = await import("strip-json-comments");
|
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"content": [
|
|
|
|
"Text",
|
|
|
|
"",
|
|
|
|
"<!-- markdownlint-configure-file",
|
|
|
|
"# Comment",
|
|
|
|
"first-line-heading = false",
|
|
|
|
"-->",
|
|
|
|
""
|
|
|
|
].join("\n")
|
|
|
|
},
|
|
|
|
"configParsers": [
|
|
|
|
(content) => JSON.parse(stripJsonComments(content)),
|
|
|
|
require("toml").parse
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const actual = await markdownlint.promises.markdownlint(options);
|
|
|
|
t.is(actual.toString(), "", "Unexpected results.");
|
|
|
|
});
|
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("getVersion", (t) => {
|
|
|
|
t.plan(1);
|
2020-10-17 14:17:35 -07:00
|
|
|
const actual = markdownlint.getVersion();
|
2020-11-15 17:03:20 -08:00
|
|
|
const expected = version;
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actual, expected, "Version string not correct.");
|
2020-10-17 14:17:35 -07:00
|
|
|
});
|
2021-11-10 21:48:15 -08:00
|
|
|
|
|
|
|
test("constants", (t) => {
|
|
|
|
t.plan(2);
|
2022-10-02 19:28:54 -07:00
|
|
|
// @ts-ignore
|
2021-11-10 21:48:15 -08:00
|
|
|
t.is(constants.homepage, homepage);
|
2022-10-02 19:28:54 -07:00
|
|
|
// @ts-ignore
|
2021-11-10 21:48:15 -08:00
|
|
|
t.is(constants.version, version);
|
|
|
|
});
|