mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Convert params.parsers.name to params.parsers.name.tokens for clarity/flexibility.
This commit is contained in:
parent
80235711f4
commit
c1df46f607
4 changed files with 28 additions and 8 deletions
|
@ -2377,8 +2377,12 @@ function lintContent(ruleList, name, content, md, config, configParsers, frontMa
|
||||||
annotateAndFreezeTokens(markdownitTokens, lines);
|
annotateAndFreezeTokens(markdownitTokens, lines);
|
||||||
// Create (frozen) parameters for rules
|
// Create (frozen) parameters for rules
|
||||||
var parsers = Object.freeze({
|
var parsers = Object.freeze({
|
||||||
"markdownit": markdownitTokens,
|
"markdownit": Object.freeze({
|
||||||
"micromark": micromarkTokens
|
"tokens": markdownitTokens
|
||||||
|
}),
|
||||||
|
"micromark": Object.freeze({
|
||||||
|
"tokens": micromarkTokens
|
||||||
|
})
|
||||||
});
|
});
|
||||||
var paramsBase = {
|
var paramsBase = {
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -4925,7 +4929,7 @@ module.exports = {
|
||||||
allowedElements = allowedElements.map(function (element) {
|
allowedElements = allowedElements.map(function (element) {
|
||||||
return element.toLowerCase();
|
return element.toLowerCase();
|
||||||
});
|
});
|
||||||
var pending = [[0, params.parsers.micromark]];
|
var pending = [[0, params.parsers.micromark.tokens]];
|
||||||
var current = null;
|
var current = null;
|
||||||
while (current = pending.shift()) {
|
while (current = pending.shift()) {
|
||||||
var _current = current,
|
var _current = current,
|
||||||
|
|
|
@ -560,8 +560,12 @@ function lintContent(
|
||||||
annotateAndFreezeTokens(markdownitTokens, lines);
|
annotateAndFreezeTokens(markdownitTokens, lines);
|
||||||
// Create (frozen) parameters for rules
|
// Create (frozen) parameters for rules
|
||||||
const parsers = Object.freeze({
|
const parsers = Object.freeze({
|
||||||
"markdownit": markdownitTokens,
|
"markdownit": Object.freeze({
|
||||||
"micromark": micromarkTokens
|
"tokens": markdownitTokens
|
||||||
|
}),
|
||||||
|
"micromark": Object.freeze({
|
||||||
|
"tokens": micromarkTokens
|
||||||
|
})
|
||||||
});
|
});
|
||||||
const paramsBase = {
|
const paramsBase = {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -16,7 +16,7 @@ module.exports = {
|
||||||
let allowedElements = params.config.allowed_elements;
|
let allowedElements = params.config.allowed_elements;
|
||||||
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
||||||
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
||||||
const pending = [ [ 0, params.parsers.micromark ] ];
|
const pending = [ [ 0, params.parsers.micromark.tokens ] ];
|
||||||
let current = null;
|
let current = null;
|
||||||
while ((current = pending.shift())) {
|
while ((current = pending.shift())) {
|
||||||
const [ offset, tokens ] = current;
|
const [ offset, tokens ] = current;
|
||||||
|
|
|
@ -26,6 +26,7 @@ test("customRulesV0", (t) => new Promise((resolve) => {
|
||||||
"letters-E-X": [ 3, 7 ]
|
"letters-E-X": [ 3, 7 ]
|
||||||
};
|
};
|
||||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
// @ts-ignore
|
||||||
let actualMessage = actualResult.toString();
|
let actualMessage = actualResult.toString();
|
||||||
let expectedMessage =
|
let expectedMessage =
|
||||||
"./test/custom-rules.md: 12: any-blockquote" +
|
"./test/custom-rules.md: 12: any-blockquote" +
|
||||||
|
@ -162,6 +163,7 @@ test("customRulesV1", (t) => new Promise((resolve) => {
|
||||||
"errorRange": null }
|
"errorRange": null }
|
||||||
];
|
];
|
||||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
// @ts-ignore
|
||||||
const actualMessage = actualResult.toString();
|
const actualMessage = actualResult.toString();
|
||||||
const expectedMessage =
|
const expectedMessage =
|
||||||
"./test/custom-rules.md: 12: any-blockquote/any-blockquote" +
|
"./test/custom-rules.md: 12: any-blockquote/any-blockquote" +
|
||||||
|
@ -270,6 +272,7 @@ test("customRulesV2", (t) => new Promise((resolve) => {
|
||||||
"errorRange": null }
|
"errorRange": null }
|
||||||
];
|
];
|
||||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
// @ts-ignore
|
||||||
const actualMessage = actualResult.toString();
|
const actualMessage = actualResult.toString();
|
||||||
const expectedMessage =
|
const expectedMessage =
|
||||||
"./test/custom-rules.md: 12: any-blockquote" +
|
"./test/custom-rules.md: 12: any-blockquote" +
|
||||||
|
@ -413,6 +416,7 @@ test("customRulesUsedNameName", (t) => new Promise((resolve) => {
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for duplicate name.");
|
t.truthy(err, "Did not get an error for duplicate name.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message,
|
t.is(err.message,
|
||||||
"Name 'NO-missing-SPACE-atx' of custom rule at index 0 is " +
|
"Name 'NO-missing-SPACE-atx' of custom rule at index 0 is " +
|
||||||
"already used as a name or tag.",
|
"already used as a name or tag.",
|
||||||
|
@ -436,6 +440,7 @@ test("customRulesUsedNameTag", (t) => new Promise((resolve) => {
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for duplicate name.");
|
t.truthy(err, "Did not get an error for duplicate name.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message,
|
t.is(err.message,
|
||||||
"Name 'HtMl' of custom rule at index 0 is already used as a name or tag.",
|
"Name 'HtMl' of custom rule at index 0 is already used as a name or tag.",
|
||||||
"Incorrect message for duplicate name.");
|
"Incorrect message for duplicate name.");
|
||||||
|
@ -464,6 +469,7 @@ test("customRulesUsedTagName", (t) => new Promise((resolve) => {
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for duplicate tag.");
|
t.truthy(err, "Did not get an error for duplicate tag.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message,
|
t.is(err.message,
|
||||||
"Tag 'NO-missing-SPACE-atx' of custom rule at index 1 is " +
|
"Tag 'NO-missing-SPACE-atx' of custom rule at index 1 is " +
|
||||||
"already used as a name.",
|
"already used as a name.",
|
||||||
|
@ -491,6 +497,7 @@ test("customRulesThrowForFile", (t) => new Promise((resolve) => {
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for function thrown.");
|
t.truthy(err, "Did not get an error for function thrown.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message, exceptionMessage,
|
t.is(err.message, exceptionMessage,
|
||||||
"Incorrect message for function thrown.");
|
"Incorrect message for function thrown.");
|
||||||
t.true(!result, "Got result for function thrown.");
|
t.true(!result, "Got result for function thrown.");
|
||||||
|
@ -544,6 +551,7 @@ test("customRulesThrowForString", (t) => new Promise((resolve) => {
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for function thrown.");
|
t.truthy(err, "Did not get an error for function thrown.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message, exceptionMessage,
|
t.is(err.message, exceptionMessage,
|
||||||
"Incorrect message for function thrown.");
|
"Incorrect message for function thrown.");
|
||||||
t.true(!result, "Got result for function thrown.");
|
t.true(!result, "Got result for function thrown.");
|
||||||
|
@ -588,6 +596,7 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
|
||||||
"description": "description",
|
"description": "description",
|
||||||
"tags": [ "tag" ],
|
"tags": [ "tag" ],
|
||||||
"function": function onErrorNull(params, onError) {
|
"function": function onErrorNull(params, onError) {
|
||||||
|
// @ts-ignore
|
||||||
onError(null);
|
onError(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,6 +609,7 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
|
||||||
t.truthy(err, "Did not get an error for function thrown.");
|
t.truthy(err, "Did not get an error for function thrown.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
t.is(
|
t.is(
|
||||||
|
// @ts-ignore
|
||||||
err.message,
|
err.message,
|
||||||
"Property 'lineNumber' of onError parameter is incorrect.",
|
"Property 'lineNumber' of onError parameter is incorrect.",
|
||||||
"Did not get correct exception for null object."
|
"Did not get correct exception for null object."
|
||||||
|
@ -1210,7 +1220,7 @@ test("customRulesParamsTokensSameObject", (t) => {
|
||||||
"tags": [ "tag" ],
|
"tags": [ "tag" ],
|
||||||
"function":
|
"function":
|
||||||
(params) => {
|
(params) => {
|
||||||
t.is(params.tokens, params.parsers.markdownit);
|
t.is(params.tokens, params.parsers.markdownit.tokens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -1418,7 +1428,7 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
|
||||||
"asynchronous": true,
|
"asynchronous": true,
|
||||||
"function": (params, onError) => new Promise((resolve) => {
|
"function": (params, onError) => new Promise((resolve) => {
|
||||||
onError({ "lineNumber": 1 });
|
onError({ "lineNumber": 1 });
|
||||||
resolve();
|
resolve(null);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -1523,6 +1533,7 @@ for (const flavor of [
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for exception.");
|
t.truthy(err, "Did not get an error for exception.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message, errorMessage, "Incorrect message for exception.");
|
t.is(err.message, errorMessage, "Incorrect message for exception.");
|
||||||
t.true(!result, "Got result for exception.");
|
t.true(!result, "Got result for exception.");
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -1641,6 +1652,7 @@ for (const flavor of [
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
t.truthy(err, "Did not get an error for rejection.");
|
t.truthy(err, "Did not get an error for rejection.");
|
||||||
t.true(err instanceof Error, "Error not instance of Error.");
|
t.true(err instanceof Error, "Error not instance of Error.");
|
||||||
|
// @ts-ignore
|
||||||
t.is(err.message, errorMessage, "Incorrect message for rejection.");
|
t.is(err.message, errorMessage, "Incorrect message for rejection.");
|
||||||
t.true(!result, "Got result for rejection.");
|
t.true(!result, "Got result for rejection.");
|
||||||
resolve();
|
resolve();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue