mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
69
lib/md005.mjs
Normal file
69
lib/md005.mjs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// @ts-check
|
||||
|
||||
import { addError, addErrorDetailIf } from "../helpers/helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD005", "list-indent" ],
|
||||
"description": "Inconsistent indentation for list items at the same level",
|
||||
"tags": [ "bullet", "ul", "indentation" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD005(params, onError) {
|
||||
for (const list of filterByTypesCached([ "listOrdered", "listUnordered" ])) {
|
||||
const expectedIndent = list.startColumn - 1;
|
||||
let expectedEnd = 0;
|
||||
let endMatching = false;
|
||||
const listItemPrefixes =
|
||||
list.children.filter((token) => (token.type === "listItemPrefix"));
|
||||
for (const listItemPrefix of listItemPrefixes) {
|
||||
const lineNumber = listItemPrefix.startLine;
|
||||
const actualIndent = listItemPrefix.startColumn - 1;
|
||||
const range = [ 1, listItemPrefix.endColumn - 1 ];
|
||||
if (list.type === "listUnordered") {
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineNumber,
|
||||
expectedIndent,
|
||||
actualIndent,
|
||||
undefined,
|
||||
undefined,
|
||||
range
|
||||
// No fixInfo; MD007 handles this scenario better
|
||||
);
|
||||
} else {
|
||||
const markerLength = listItemPrefix.text.trim().length;
|
||||
const actualEnd = listItemPrefix.startColumn + markerLength - 1;
|
||||
expectedEnd = expectedEnd || actualEnd;
|
||||
if ((expectedIndent !== actualIndent) || endMatching) {
|
||||
if (expectedEnd === actualEnd) {
|
||||
endMatching = true;
|
||||
} else {
|
||||
const detail = endMatching ?
|
||||
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
|
||||
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
|
||||
const expected = endMatching ?
|
||||
expectedEnd - markerLength :
|
||||
expectedIndent;
|
||||
const actual = endMatching ?
|
||||
actualEnd - markerLength :
|
||||
actualIndent;
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
detail,
|
||||
undefined,
|
||||
range,
|
||||
{
|
||||
"editColumn": Math.min(actual, expected) + 1,
|
||||
"deleteCount": Math.max(actual - expected, 0),
|
||||
"insertText": "".padEnd(Math.max(expected - actual, 0))
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue