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