2020-09-12 12:11:14 -07:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
const test = require("ava").default;
|
2020-09-12 12:11:14 -07:00
|
|
|
const packageJson = require("../package.json");
|
|
|
|
const markdownlint = require("../lib/markdownlint");
|
|
|
|
const homepage = packageJson.homepage;
|
|
|
|
const version = packageJson.version;
|
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("resultObjectToStringNotEnumerable", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"string": "# Heading"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
// eslint-disable-next-line guard-for-in
|
|
|
|
for (const property in result) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.not(property, "toString", "Function should not enumerate.");
|
2020-09-12 12:11:14 -07:00
|
|
|
}
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("resultFormattingV0", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(4);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": true,
|
|
|
|
"MD041": false
|
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2020-09-12 12:11:14 -07:00
|
|
|
"resultVersion": 0
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"./test/atx_heading_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_heading_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2020-09-12 12:11:14 -07:00
|
|
|
let actualMessage = actualResult.toString();
|
|
|
|
let expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD002" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading\n" +
|
2020-09-12 12:11:14 -07:00
|
|
|
"./test/atx_heading_spacing.md: 1: MD018" +
|
|
|
|
" No space after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1: MD002" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
|
2020-09-12 12:11:14 -07:00
|
|
|
// @ts-ignore
|
|
|
|
actualMessage = actualResult.toString(true);
|
|
|
|
expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3: first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading\n" +
|
2020-09-12 12:11:14 -07:00
|
|
|
"./test/atx_heading_spacing.md: 1: no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1: first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2021-01-10 20:46:00 -08:00
|
|
|
test("resultFormattingSyncV0", (t) => {
|
|
|
|
t.plan(3);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": true,
|
|
|
|
"MD041": false
|
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2020-09-12 12:11:14 -07:00
|
|
|
"resultVersion": 0
|
|
|
|
};
|
|
|
|
const actualResult = markdownlint.sync(options);
|
|
|
|
const expectedResult = {
|
|
|
|
"./test/atx_heading_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_heading_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2020-09-12 12:11:14 -07:00
|
|
|
let actualMessage = actualResult.toString();
|
|
|
|
let expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD002" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading\n" +
|
2020-09-12 12:11:14 -07:00
|
|
|
"./test/atx_heading_spacing.md: 1: MD018" +
|
|
|
|
" No space after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1: MD002" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message (name).");
|
2020-09-12 12:11:14 -07:00
|
|
|
// @ts-ignore
|
|
|
|
actualMessage = actualResult.toString(true);
|
|
|
|
expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3: first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading\n" +
|
2020-09-12 12:11:14 -07:00
|
|
|
"./test/atx_heading_spacing.md: 1: no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1: first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message (alias).");
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("resultFormattingV1", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(3);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"truncate":
|
|
|
|
"# Multiple spaces inside hashes on closed atx style heading #\n"
|
|
|
|
},
|
|
|
|
"files": [
|
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": true,
|
|
|
|
"MD041": false
|
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2020-09-12 12:11:14 -07:00
|
|
|
"resultVersion": 1
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"truncate": [
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleName": "MD021",
|
|
|
|
"ruleAlias": "no-multiple-space-closed-atx",
|
|
|
|
"ruleDescription":
|
|
|
|
"Multiple spaces inside hashes on closed atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md021.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "# Multiple spa...tyle heading #",
|
|
|
|
"errorRange": [ 1, 4 ] }
|
|
|
|
],
|
|
|
|
"./test/atx_heading_spacing.md": [
|
|
|
|
{ "lineNumber": 3,
|
|
|
|
"ruleName": "MD002",
|
|
|
|
"ruleAlias": "first-heading-h1",
|
2020-12-28 13:28:38 -08:00
|
|
|
"ruleDescription": "First heading should be a top-level heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md002.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: h1; Actual: h2",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": null },
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleName": "MD018",
|
|
|
|
"ruleAlias": "no-missing-space-atx",
|
|
|
|
"ruleDescription": "No space after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md018.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "#Heading 1 {MD018}",
|
|
|
|
"errorRange": [ 1, 2 ] },
|
|
|
|
{ "lineNumber": 3,
|
|
|
|
"ruleName": "MD019",
|
|
|
|
"ruleAlias": "no-multiple-space-atx",
|
|
|
|
"ruleDescription": "Multiple spaces after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md019.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "## Heading 2 {MD019}",
|
|
|
|
"errorRange": [ 1, 5 ] },
|
|
|
|
{ "lineNumber": 5,
|
|
|
|
"ruleName": "MD019",
|
|
|
|
"ruleAlias": "no-multiple-space-atx",
|
|
|
|
"ruleDescription": "Multiple spaces after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md019.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "## Heading 3 {MD019}",
|
|
|
|
"errorRange": [ 1, 6 ] }
|
|
|
|
],
|
|
|
|
"./test/first_heading_bad_atx.md": [
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleName": "MD002",
|
|
|
|
"ruleAlias": "first-heading-h1",
|
2020-12-28 13:28:38 -08:00
|
|
|
"ruleDescription": "First heading should be a top-level heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md002.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: h1; Actual: h2",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": null }
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
// @ts-ignore
|
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2020-09-12 12:11:14 -07:00
|
|
|
const actualMessage = actualResult.toString();
|
|
|
|
const expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD002/first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading" +
|
2020-09-12 12:11:14 -07:00
|
|
|
" [Expected: h1; Actual: h2]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 1: MD018/no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style heading" +
|
|
|
|
" [Context: \"#Heading 1 {MD018}\"]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD019/no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading" +
|
|
|
|
" [Context: \"## Heading 2 {MD019}\"]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: MD019/no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading" +
|
|
|
|
" [Context: \"## Heading 3 {MD019}\"]\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1: MD002/first-heading-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading" +
|
2020-09-12 12:11:14 -07:00
|
|
|
" [Expected: h1; Actual: h2]\n" +
|
|
|
|
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
|
|
|
" Multiple spaces inside hashes on closed atx style heading" +
|
|
|
|
" [Context: \"# Multiple spa...tyle heading #\"]";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("resultFormattingV2", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(3);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"truncate":
|
|
|
|
"# Multiple spaces inside hashes on closed atx style heading #\n"
|
|
|
|
},
|
|
|
|
"files": [
|
|
|
|
"./test/atx_heading_spacing.md",
|
|
|
|
"./test/first_heading_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": true,
|
|
|
|
"MD041": false
|
2022-04-21 21:30:56 -07:00
|
|
|
},
|
2023-03-15 21:26:22 -07:00
|
|
|
"noInlineConfig": true,
|
2022-04-21 21:30:56 -07:00
|
|
|
"resultVersion": 2
|
2020-09-12 12:11:14 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"truncate": [
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD021", "no-multiple-space-closed-atx" ],
|
|
|
|
"ruleDescription":
|
|
|
|
"Multiple spaces inside hashes on closed atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md021.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "# Multiple spa...tyle heading #",
|
|
|
|
"errorRange": [ 1, 4 ] }
|
|
|
|
],
|
|
|
|
"./test/atx_heading_spacing.md": [
|
|
|
|
{ "lineNumber": 3,
|
|
|
|
"ruleNames": [ "MD002", "first-heading-h1", "first-header-h1" ],
|
2020-12-28 13:28:38 -08:00
|
|
|
"ruleDescription": "First heading should be a top-level heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md002.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: h1; Actual: h2",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": null },
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD018", "no-missing-space-atx" ],
|
|
|
|
"ruleDescription": "No space after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md018.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "#Heading 1 {MD018}",
|
|
|
|
"errorRange": [ 1, 2 ] },
|
|
|
|
{ "lineNumber": 3,
|
|
|
|
"ruleNames": [ "MD019", "no-multiple-space-atx" ],
|
|
|
|
"ruleDescription": "Multiple spaces after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md019.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "## Heading 2 {MD019}",
|
|
|
|
"errorRange": [ 1, 5 ] },
|
|
|
|
{ "lineNumber": 5,
|
|
|
|
"ruleNames": [ "MD019", "no-multiple-space-atx" ],
|
|
|
|
"ruleDescription": "Multiple spaces after hash on atx style heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md019.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "## Heading 3 {MD019}",
|
|
|
|
"errorRange": [ 1, 6 ] }
|
|
|
|
],
|
|
|
|
"./test/first_heading_bad_atx.md": [
|
|
|
|
{ "lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD002", "first-heading-h1", "first-header-h1" ],
|
2020-12-28 13:28:38 -08:00
|
|
|
"ruleDescription": "First heading should be a top-level heading",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md002.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: h1; Actual: h2",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": null }
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2020-09-12 12:11:14 -07:00
|
|
|
const actualMessage = actualResult.toString();
|
|
|
|
const expectedMessage =
|
|
|
|
"./test/atx_heading_spacing.md: 3:" +
|
|
|
|
" MD002/first-heading-h1/first-header-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading" +
|
2020-09-12 12:11:14 -07:00
|
|
|
" [Expected: h1; Actual: h2]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 1: MD018/no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style heading" +
|
|
|
|
" [Context: \"#Heading 1 {MD018}\"]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 3: MD019/no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading" +
|
|
|
|
" [Context: \"## Heading 2 {MD019}\"]\n" +
|
|
|
|
"./test/atx_heading_spacing.md: 5: MD019/no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style heading" +
|
|
|
|
" [Context: \"## Heading 3 {MD019}\"]\n" +
|
|
|
|
"./test/first_heading_bad_atx.md: 1:" +
|
|
|
|
" MD002/first-heading-h1/first-header-h1" +
|
2020-12-28 13:28:38 -08:00
|
|
|
" First heading should be a top-level heading" +
|
2020-09-12 12:11:14 -07:00
|
|
|
" [Expected: h1; Actual: h2]\n" +
|
|
|
|
"truncate: 1: MD021/no-multiple-space-closed-atx" +
|
|
|
|
" Multiple spaces inside hashes on closed atx style heading" +
|
|
|
|
" [Context: \"# Multiple spa...tyle heading #\"]";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("resultFormattingV3", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(3);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input":
|
|
|
|
"# Heading \n" +
|
|
|
|
"\n" +
|
|
|
|
"Text\ttext\t\ttext\n" +
|
|
|
|
"Text * emphasis * text"
|
|
|
|
},
|
|
|
|
"resultVersion": 3
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": [
|
|
|
|
{
|
|
|
|
"lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD009", "no-trailing-spaces" ],
|
|
|
|
"ruleDescription": "Trailing spaces",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md009.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: 0 or 2; Actual: 3",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 10, 3 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 10,
|
|
|
|
"deleteCount": 3
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 3,
|
|
|
|
"ruleNames": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"ruleDescription": "Hard tabs",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 5",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 5, 1 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 5,
|
|
|
|
"deleteCount": 1,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 3,
|
|
|
|
"ruleNames": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"ruleDescription": "Hard tabs",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 10",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 10, 2 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 10,
|
|
|
|
"deleteCount": 2,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 4,
|
|
|
|
"ruleNames": [ "MD037", "no-space-in-emphasis" ],
|
|
|
|
"ruleDescription": "Spaces inside emphasis markers",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md037.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
2023-07-24 21:36:55 -07:00
|
|
|
"errorContext": "* e",
|
|
|
|
"errorRange": [ 6, 3 ],
|
2020-09-12 12:11:14 -07:00
|
|
|
"fixInfo": {
|
2023-07-24 21:36:55 -07:00
|
|
|
"editColumn": 7,
|
|
|
|
"deleteCount": 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 4,
|
|
|
|
"ruleNames": [ "MD037", "no-space-in-emphasis" ],
|
|
|
|
"ruleDescription": "Spaces inside emphasis markers",
|
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md037.md`,
|
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": "s *",
|
|
|
|
"errorRange": [ 15, 3 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 16,
|
|
|
|
"deleteCount": 1
|
2020-09-12 12:11:14 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 4,
|
|
|
|
"ruleNames": [ "MD047", "single-trailing-newline" ],
|
|
|
|
"ruleDescription": "Files should end with a single newline character",
|
2022-10-30 14:58:45 -07:00
|
|
|
"ruleInformation": `${homepage}/blob/v${version}/doc/md047.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": null,
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 22, 1 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"insertText": "\n",
|
|
|
|
"editColumn": 23
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2020-09-12 12:11:14 -07:00
|
|
|
const actualMessage = actualResult.toString();
|
|
|
|
const expectedMessage =
|
|
|
|
"input: 1: MD009/no-trailing-spaces" +
|
|
|
|
" Trailing spaces [Expected: 0 or 2; Actual: 3]\n" +
|
|
|
|
"input: 3: MD010/no-hard-tabs" +
|
|
|
|
" Hard tabs [Column: 5]\n" +
|
|
|
|
"input: 3: MD010/no-hard-tabs" +
|
|
|
|
" Hard tabs [Column: 10]\n" +
|
|
|
|
"input: 4: MD037/no-space-in-emphasis" +
|
2023-07-24 21:36:55 -07:00
|
|
|
" Spaces inside emphasis markers [Context: \"* e\"]\n" +
|
|
|
|
"input: 4: MD037/no-space-in-emphasis" +
|
|
|
|
" Spaces inside emphasis markers [Context: \"s *\"]\n" +
|
2020-09-12 12:11:14 -07:00
|
|
|
"input: 4: MD047/single-trailing-newline" +
|
|
|
|
" Files should end with a single newline character";
|
2021-01-10 20:46:00 -08:00
|
|
|
t.is(actualMessage, expectedMessage, "Incorrect message.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("onePerLineResultVersion0", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input": "# Heading\theading\t\theading\n"
|
|
|
|
},
|
|
|
|
"resultVersion": 0
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": {
|
|
|
|
"MD010": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
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();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("onePerLineResultVersion1", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input": "# Heading\theading\t\theading\n"
|
|
|
|
},
|
|
|
|
"resultVersion": 1
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": [
|
|
|
|
{
|
|
|
|
"lineNumber": 1,
|
|
|
|
"ruleName": "MD010",
|
|
|
|
"ruleAlias": "no-hard-tabs",
|
|
|
|
"ruleDescription": "Hard tabs",
|
|
|
|
"ruleInformation":
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 10",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 10, 1 ]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
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();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("onePerLineResultVersion2", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input": "# Heading\theading\t\theading\n"
|
|
|
|
},
|
|
|
|
"resultVersion": 2
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": [
|
|
|
|
{
|
|
|
|
"lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"ruleDescription": "Hard tabs",
|
|
|
|
"ruleInformation":
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 10",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 10, 1 ]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("manyPerLineResultVersion3", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input": "# Heading\theading\t\theading\n"
|
|
|
|
},
|
|
|
|
"resultVersion": 3
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": [
|
|
|
|
{
|
|
|
|
"lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"ruleDescription": "Hard tabs",
|
|
|
|
"ruleInformation":
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 10",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 10, 1 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 10,
|
|
|
|
"deleteCount": 1,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"lineNumber": 1,
|
|
|
|
"ruleNames": [ "MD010", "no-hard-tabs" ],
|
|
|
|
"ruleDescription": "Hard tabs",
|
|
|
|
"ruleInformation":
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/md010.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Column: 18",
|
|
|
|
"errorContext": null,
|
|
|
|
"errorRange": [ 18, 2 ],
|
|
|
|
"fixInfo": {
|
|
|
|
"editColumn": 18,
|
|
|
|
"deleteCount": 2,
|
|
|
|
"insertText": " "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|
2020-09-12 12:11:14 -07:00
|
|
|
|
2022-06-21 04:40:38 +00:00
|
|
|
test("frontMatterResultVersion3", (t) => new Promise((resolve) => {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.plan(2);
|
2020-09-12 12:11:14 -07:00
|
|
|
const options = {
|
|
|
|
"strings": {
|
|
|
|
"input": "---\n---\n# Heading\nText\n"
|
|
|
|
},
|
|
|
|
"resultVersion": 3
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
2021-01-10 20:46:00 -08:00
|
|
|
t.falsy(err);
|
2020-09-12 12:11:14 -07:00
|
|
|
const expectedResult = {
|
|
|
|
"input": [
|
|
|
|
{
|
|
|
|
"lineNumber": 3,
|
|
|
|
"ruleNames":
|
|
|
|
[ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
|
|
|
"ruleDescription": "Headings should be surrounded by blank lines",
|
|
|
|
"ruleInformation":
|
2022-10-30 14:58:45 -07:00
|
|
|
`${homepage}/blob/v${version}/doc/md022.md`,
|
2020-09-12 12:11:14 -07:00
|
|
|
"errorDetail": "Expected: 1; Actual: 0; Below",
|
|
|
|
"errorContext": "# Heading",
|
|
|
|
"errorRange": null,
|
|
|
|
"fixInfo": {
|
|
|
|
"lineNumber": 4,
|
|
|
|
"insertText": "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2021-01-10 20:46:00 -08:00
|
|
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
2022-06-21 04:40:38 +00:00
|
|
|
resolve();
|
2020-09-12 12:11:14 -07:00
|
|
|
});
|
2022-06-21 04:40:38 +00:00
|
|
|
}));
|