mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Centralize handling of newlines in error detail/context to always replace (consecutive) newlines with a single space.
This commit is contained in:
parent
db967fd387
commit
cdfa934d8d
5 changed files with 21 additions and 45 deletions
|
|
@ -310,7 +310,7 @@ module.exports.addErrorDetailIf = addErrorDetailIf;
|
||||||
*/
|
*/
|
||||||
function addErrorContext(
|
function addErrorContext(
|
||||||
onError, lineNumber, context, start, end, range, fixInfo) {
|
onError, lineNumber, context, start, end, range, fixInfo) {
|
||||||
context = ellipsify(context.replace(newLineRe, "\n"), start, end);
|
context = ellipsify(context, start, end);
|
||||||
addError(onError, lineNumber, undefined, context, range, fixInfo);
|
addError(onError, lineNumber, undefined, context, range, fixInfo);
|
||||||
}
|
}
|
||||||
module.exports.addErrorContext = addErrorContext;
|
module.exports.addErrorContext = addErrorContext;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");
|
const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.cjs");
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
/** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
|
||||||
|
|
@ -216,12 +216,11 @@ function getHeadingStyle(heading) {
|
||||||
* @returns {string} Heading text.
|
* @returns {string} Heading text.
|
||||||
*/
|
*/
|
||||||
function getHeadingText(heading) {
|
function getHeadingText(heading) {
|
||||||
const headingText = getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ])
|
return getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ])
|
||||||
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
|
.flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
|
||||||
.map((data) => data.text)
|
.map((data) => data.text)
|
||||||
.join("")
|
.join("")
|
||||||
.replace(/[\r\n]+/g, " ");
|
.replace(newLineRe, " ");
|
||||||
return headingText || "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -627,8 +627,8 @@ function lintContent(
|
||||||
"ruleNames": rule.names,
|
"ruleNames": rule.names,
|
||||||
"ruleDescription": rule.description,
|
"ruleDescription": rule.description,
|
||||||
"ruleInformation": information ? information.href : null,
|
"ruleInformation": information ? information.href : null,
|
||||||
"errorDetail": errorInfo.detail || null,
|
"errorDetail": errorInfo.detail?.replace(helpers.newLineRe, " ") || null,
|
||||||
"errorContext": errorInfo.context || null,
|
"errorContext": errorInfo.context?.replace(helpers.newLineRe, " ") || null,
|
||||||
"errorRange": errorInfo.range ? [ ...errorInfo.range ] : null,
|
"errorRange": errorInfo.range ? [ ...errorInfo.range ] : null,
|
||||||
"fixInfo": fixInfo ? cleanFixInfo : null
|
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1383,8 +1383,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\` code {MD038}␊
|
errorContext: '` code {MD038} span`',
|
||||||
span\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
7,
|
7,
|
||||||
|
|
@ -1403,8 +1402,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`code␊
|
errorContext: '`code span `',
|
||||||
span \``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
5,
|
5,
|
||||||
|
|
@ -1423,9 +1421,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `...\`\`code␊
|
errorContext: '...``code span code span code ```',
|
||||||
span code␊
|
|
||||||
span code \`\`\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
10,
|
10,
|
||||||
|
|
@ -1444,9 +1440,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`\`\`\` code {MD038}␊
|
errorContext: '```` code {MD038} span code sp...',
|
||||||
span code␊
|
|
||||||
sp...`,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
15,
|
15,
|
||||||
|
|
@ -11211,8 +11205,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `[click␊
|
errorContext: '[click here]',
|
||||||
here]`,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: null,
|
errorRange: null,
|
||||||
fixInfo: null,
|
fixInfo: null,
|
||||||
|
|
@ -25099,8 +25092,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
{
|
{
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
errorContext: `\` code {MD038}␊
|
errorContext: '` code {MD038} span`',
|
||||||
span\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
7,
|
7,
|
||||||
|
|
@ -25119,8 +25111,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`code␊
|
errorContext: '`code span `',
|
||||||
span \``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
5,
|
5,
|
||||||
|
|
@ -25139,9 +25130,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\` code {MD038}␊
|
errorContext: '` code {MD038} span code span`',
|
||||||
span code␊
|
|
||||||
span\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
7,
|
7,
|
||||||
|
|
@ -25160,9 +25149,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`code␊
|
errorContext: '`code span code span `',
|
||||||
span code␊
|
|
||||||
span \``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
5,
|
5,
|
||||||
|
|
@ -25181,9 +25168,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`code␊
|
errorContext: '`code span code span `',
|
||||||
span code␊
|
|
||||||
span \``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
5,
|
5,
|
||||||
|
|
@ -25202,9 +25187,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\` code {MD038}␊
|
errorContext: '` code {MD038} span code span`',
|
||||||
span code␊
|
|
||||||
span\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
7,
|
7,
|
||||||
|
|
@ -25223,8 +25206,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`code␊
|
errorContext: '`code code code `',
|
||||||
code code \``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
10,
|
10,
|
||||||
|
|
@ -52171,8 +52153,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `...iling spaces␊
|
errorContext: '...iling spaces not allowed ` ``',
|
||||||
not allowed \` \`\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
15,
|
15,
|
||||||
|
|
@ -52191,9 +52172,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`\`\`␊
|
errorContext: '``` Code {MD038} ```',
|
||||||
Code {MD038}␊
|
|
||||||
\`\`\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
1,
|
1,
|
||||||
|
|
@ -52212,9 +52191,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorContext: `\`\`\`␊
|
errorContext: '``` Code {MD038} ```',
|
||||||
Code {MD038}␊
|
|
||||||
\`\`\``,
|
|
||||||
errorDetail: null,
|
errorDetail: null,
|
||||||
errorRange: [
|
errorRange: [
|
||||||
1,
|
1,
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue