mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD037/no-space-in-emphasis to report left+right errors only once.
This commit is contained in:
parent
737126cf93
commit
dc8e746cd2
2 changed files with 47 additions and 24 deletions
44
lib/md037.js
44
lib/md037.js
|
|
@ -13,31 +13,37 @@ module.exports = {
|
||||||
"tags": [ "whitespace", "emphasis" ],
|
"tags": [ "whitespace", "emphasis" ],
|
||||||
"function": function MD037(params, onError) {
|
"function": function MD037(params, onError) {
|
||||||
forEachInlineChild(params, "text", (token) => {
|
forEachInlineChild(params, "text", (token) => {
|
||||||
|
const { content, lineNumber } = token;
|
||||||
|
const columnsReported = [];
|
||||||
[ leftSpaceRe, rightSpaceRe ].forEach((spaceRe, index) => {
|
[ leftSpaceRe, rightSpaceRe ].forEach((spaceRe, index) => {
|
||||||
let match = null;
|
let match = null;
|
||||||
while ((match = spaceRe.exec(token.content)) !== null) {
|
while ((match = spaceRe.exec(content)) !== null) {
|
||||||
const [ fullText, marker ] = match;
|
const [ fullText, marker ] = match;
|
||||||
const line = params.lines[token.lineNumber - 1];
|
const line = params.lines[lineNumber - 1];
|
||||||
if (line.includes(fullText)) {
|
if (line.includes(fullText)) {
|
||||||
const text = fullText.trim();
|
const text = fullText.trim();
|
||||||
const column = line.indexOf(text) + 1;
|
const column = line.indexOf(text) + 1;
|
||||||
const length = text.length;
|
if (!columnsReported.includes(column)) {
|
||||||
const markerLength = marker.length;
|
const length = text.length;
|
||||||
const emphasized = text.slice(markerLength, length - markerLength);
|
const markerLength = marker.length;
|
||||||
const fixedText = `${marker}${emphasized.trim()}${marker}`;
|
const emphasized =
|
||||||
addErrorContext(
|
text.slice(markerLength, length - markerLength);
|
||||||
onError,
|
const fixedText = `${marker}${emphasized.trim()}${marker}`;
|
||||||
token.lineNumber,
|
addErrorContext(
|
||||||
text,
|
onError,
|
||||||
index === 0,
|
lineNumber,
|
||||||
index !== 0,
|
text,
|
||||||
[ column, length ],
|
index === 0,
|
||||||
{
|
index !== 0,
|
||||||
"editColumn": column,
|
[ column, length ],
|
||||||
"deleteCount": length,
|
{
|
||||||
"insertText": fixedText
|
"editColumn": column,
|
||||||
}
|
"deleteCount": length,
|
||||||
);
|
"insertText": fixedText
|
||||||
|
}
|
||||||
|
);
|
||||||
|
columnsReported.push(column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -522,7 +522,8 @@ module.exports.resultFormattingV3 = function resultFormattingV3(test) {
|
||||||
"input":
|
"input":
|
||||||
"# Heading \n" +
|
"# Heading \n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Text\ttext\t\ttext"
|
"Text\ttext\t\ttext\n" +
|
||||||
|
"Text * emphasis * text"
|
||||||
},
|
},
|
||||||
"resultVersion": 3
|
"resultVersion": 3
|
||||||
};
|
};
|
||||||
|
|
@ -572,16 +573,30 @@ module.exports.resultFormattingV3 = function resultFormattingV3(test) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 3,
|
"lineNumber": 4,
|
||||||
|
"ruleNames": [ "MD037", "no-space-in-emphasis" ],
|
||||||
|
"ruleDescription": "Spaces inside emphasis markers",
|
||||||
|
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md037`,
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": "* emphasis *",
|
||||||
|
"errorRange": [ 6, 12 ],
|
||||||
|
"fixInfo": {
|
||||||
|
"editColumn": 6,
|
||||||
|
"deleteCount": 12,
|
||||||
|
"insertText": "*emphasis*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 4,
|
||||||
"ruleNames": [ "MD047", "single-trailing-newline" ],
|
"ruleNames": [ "MD047", "single-trailing-newline" ],
|
||||||
"ruleDescription": "Files should end with a single newline character",
|
"ruleDescription": "Files should end with a single newline character",
|
||||||
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
|
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
|
||||||
"errorDetail": null,
|
"errorDetail": null,
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": [ 15, 1 ],
|
"errorRange": [ 22, 1 ],
|
||||||
"fixInfo": {
|
"fixInfo": {
|
||||||
"insertText": "\n",
|
"insertText": "\n",
|
||||||
"editColumn": 16
|
"editColumn": 23
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -595,7 +610,9 @@ module.exports.resultFormattingV3 = function resultFormattingV3(test) {
|
||||||
" Hard tabs [Column: 5]\n" +
|
" Hard tabs [Column: 5]\n" +
|
||||||
"input: 3: MD010/no-hard-tabs" +
|
"input: 3: MD010/no-hard-tabs" +
|
||||||
" Hard tabs [Column: 10]\n" +
|
" Hard tabs [Column: 10]\n" +
|
||||||
"input: 3: MD047/single-trailing-newline" +
|
"input: 4: MD037/no-space-in-emphasis" +
|
||||||
|
" Spaces inside emphasis markers [Context: \"* emphasis *\"]\n" +
|
||||||
|
"input: 4: MD047/single-trailing-newline" +
|
||||||
" Files should end with a single newline character";
|
" Files should end with a single newline character";
|
||||||
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
test.equal(actualMessage, expectedMessage, "Incorrect message.");
|
||||||
test.done();
|
test.done();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue