@alexlit/lint-kit 190.0.1 → 191.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/config-eslint/package.json +3 -3
- package/packages/config-eslint/plugins/unicorn.js +10 -1
- package/packages/config-markdownlint/package.json +2 -2
- package/packages/config-markdownlint/node_modules/ansi-regex/index.d.ts +0 -33
- package/packages/config-markdownlint/node_modules/ansi-regex/index.js +0 -14
- package/packages/config-markdownlint/node_modules/ansi-regex/license +0 -9
- package/packages/config-markdownlint/node_modules/ansi-regex/package.json +0 -61
- package/packages/config-markdownlint/node_modules/ansi-regex/readme.md +0 -66
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +0 -529
- package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +0 -92
- package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +0 -21
- package/packages/config-markdownlint/node_modules/markdownlint/README.md +0 -1112
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +0 -194
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +0 -27
- package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +0 -20
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +0 -2858
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +0 -51
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +0 -59
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +0 -50
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +0 -53
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +0 -52
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +0 -50
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +0 -62
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +0 -30
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +0 -38
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +0 -58
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +0 -54
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +0 -27
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +0 -28
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +0 -29
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +0 -31
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +0 -67
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +0 -33
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +0 -44
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +0 -49
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +0 -40
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +0 -32
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +0 -44
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +0 -100
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +0 -82
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +0 -50
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +0 -55
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +0 -33
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +0 -55
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +0 -44
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +0 -45
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +0 -37
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +0 -52
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +0 -21
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +0 -52
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +0 -64
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +0 -38
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +0 -87
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +0 -45
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +0 -48
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +0 -40
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +0 -34
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +0 -42
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +0 -36
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +0 -35
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +0 -117
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +0 -52
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +0 -38
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +0 -100
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md055.md +0 -55
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +0 -37
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +0 -48
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md059.md +0 -33
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md060.md +0 -130
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +0 -21
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +0 -29
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.cjs +0 -695
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark-helpers.cjs +0 -332
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +0 -26
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.cjs +0 -16
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.mjs +0 -80
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +0 -2417
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +0 -8
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.mjs +0 -14
- package/packages/config-markdownlint/node_modules/markdownlint/lib/defer-require.cjs +0 -18
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.d.mts +0 -1
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.mjs +0 -3
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.d.mts +0 -1
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.mjs +0 -3
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.d.mts +0 -1
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.mjs +0 -3
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.d.mts +0 -30
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.mjs +0 -33
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownit.cjs +0 -171
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.mts +0 -615
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.mjs +0 -1592
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.mjs +0 -32
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.mjs +0 -47
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.mjs +0 -72
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.mjs +0 -69
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.mjs +0 -84
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.mjs +0 -96
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.mjs +0 -78
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.mjs +0 -56
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.mjs +0 -40
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.mjs +0 -91
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.mjs +0 -47
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.mjs +0 -43
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.mjs +0 -77
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.mjs +0 -68
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.mjs +0 -103
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.mjs +0 -37
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.mjs +0 -45
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.mjs +0 -45
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.mjs +0 -46
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.mjs +0 -50
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.mjs +0 -39
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.mjs +0 -84
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.mjs +0 -57
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.mjs +0 -61
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.mjs +0 -78
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.mjs +0 -46
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.mjs +0 -92
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.mjs +0 -23
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.mjs +0 -55
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.mjs +0 -94
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.mjs +0 -73
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.mjs +0 -59
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.mjs +0 -32
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.mjs +0 -71
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.mjs +0 -58
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.mjs +0 -72
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.mjs +0 -110
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.mjs +0 -61
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.mjs +0 -31
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.mjs +0 -28
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.mjs +0 -47
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.mjs +0 -115
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.mjs +0 -173
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.mjs +0 -40
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.mjs +0 -60
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.mjs +0 -122
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.mjs +0 -72
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.mjs +0 -50
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.mjs +0 -57
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md059.mjs +0 -71
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md060.mjs +0 -209
- package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-parse.mjs +0 -337
- package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-types.d.mts +0 -11
- package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-browser.mjs +0 -22
- package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-node.mjs +0 -11
- package/packages/config-markdownlint/node_modules/markdownlint/lib/parse-configuration.mjs +0 -47
- package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.cjs +0 -52
- package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.d.cts +0 -34
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.mjs +0 -122
- package/packages/config-markdownlint/node_modules/markdownlint/lib/types.d.mts +0 -13
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +0 -120
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +0 -349
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +0 -310
- package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +0 -26
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +0 -5138
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +0 -5143
- package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +0 -5
- package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +0 -22
- package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +0 -27
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +0 -12
- package/packages/config-markdownlint/node_modules/string-width/index.d.ts +0 -39
- package/packages/config-markdownlint/node_modules/string-width/index.js +0 -203
- package/packages/config-markdownlint/node_modules/string-width/license +0 -9
- package/packages/config-markdownlint/node_modules/string-width/package.json +0 -65
- package/packages/config-markdownlint/node_modules/string-width/readme.md +0 -66
- package/packages/config-markdownlint/node_modules/strip-ansi/index.d.ts +0 -15
- package/packages/config-markdownlint/node_modules/strip-ansi/index.js +0 -19
- package/packages/config-markdownlint/node_modules/strip-ansi/license +0 -9
- package/packages/config-markdownlint/node_modules/strip-ansi/package.json +0 -59
- package/packages/config-markdownlint/node_modules/strip-ansi/readme.md +0 -37
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
const listStyleExamples = {
|
|
8
|
-
"one": "1/1/1",
|
|
9
|
-
"ordered": "1/2/3",
|
|
10
|
-
"zero": "0/0/0"
|
|
11
|
-
};
|
|
12
|
-
const listStyles = Object.keys(listStyleExamples);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Gets the column and text of an ordered list item prefix token.
|
|
16
|
-
*
|
|
17
|
-
* @param {import("markdownlint").MicromarkToken} listItemPrefix List item prefix token.
|
|
18
|
-
* @returns {{column: number, value: number}} List item value column and text.
|
|
19
|
-
*/
|
|
20
|
-
function getOrderedListItemValue(listItemPrefix) {
|
|
21
|
-
const listItemValue = getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0];
|
|
22
|
-
return {
|
|
23
|
-
"column": listItemValue.startColumn,
|
|
24
|
-
"value": Number(listItemValue.text)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** @type {import("markdownlint").Rule} */
|
|
29
|
-
export default {
|
|
30
|
-
"names": [ "MD029", "ol-prefix" ],
|
|
31
|
-
"description": "Ordered list item prefix",
|
|
32
|
-
"tags": [ "ol" ],
|
|
33
|
-
"parser": "micromark",
|
|
34
|
-
"function": function MD029(params, onError) {
|
|
35
|
-
const style = String(params.config.style);
|
|
36
|
-
for (const listOrdered of filterByTypesCached([ "listOrdered" ])) {
|
|
37
|
-
const listItemPrefixes = getDescendantsByType(listOrdered, [ "listItemPrefix" ]);
|
|
38
|
-
let expected = 1;
|
|
39
|
-
let incrementing = false;
|
|
40
|
-
// Check for incrementing number pattern 1/2/3 or 0/1/2
|
|
41
|
-
if (listItemPrefixes.length >= 2) {
|
|
42
|
-
const first = getOrderedListItemValue(listItemPrefixes[0]);
|
|
43
|
-
const second = getOrderedListItemValue(listItemPrefixes[1]);
|
|
44
|
-
if ((second.value !== 1) || (first.value === 0)) {
|
|
45
|
-
incrementing = true;
|
|
46
|
-
if (first.value === 0) {
|
|
47
|
-
expected = 0;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Determine effective style
|
|
52
|
-
const listStyle = listStyles.includes(style) ? style : (incrementing ? "ordered" : "one");
|
|
53
|
-
if (listStyle === "zero") {
|
|
54
|
-
expected = 0;
|
|
55
|
-
} else if (listStyle === "one") {
|
|
56
|
-
expected = 1;
|
|
57
|
-
}
|
|
58
|
-
// Validate each list item marker
|
|
59
|
-
for (const listItemPrefix of listItemPrefixes) {
|
|
60
|
-
const orderedListItemValue = getOrderedListItemValue(listItemPrefix);
|
|
61
|
-
const actual = orderedListItemValue.value;
|
|
62
|
-
const fixInfo = {
|
|
63
|
-
"editColumn": orderedListItemValue.column,
|
|
64
|
-
"deleteCount": orderedListItemValue.value.toString().length,
|
|
65
|
-
"insertText": expected.toString()
|
|
66
|
-
};
|
|
67
|
-
addErrorDetailIf(
|
|
68
|
-
onError,
|
|
69
|
-
listItemPrefix.startLine,
|
|
70
|
-
expected,
|
|
71
|
-
actual,
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
"Style: " + listStyleExamples[listStyle],
|
|
74
|
-
undefined,
|
|
75
|
-
[ listItemPrefix.startColumn, listItemPrefix.endColumn - listItemPrefix.startColumn ],
|
|
76
|
-
fixInfo
|
|
77
|
-
);
|
|
78
|
-
if (listStyle === "ordered") {
|
|
79
|
-
expected++;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
5
|
-
|
|
6
|
-
/** @type {import("markdownlint").Rule} */
|
|
7
|
-
export default {
|
|
8
|
-
"names": [ "MD030", "list-marker-space" ],
|
|
9
|
-
"description": "Spaces after list markers",
|
|
10
|
-
"tags": [ "ol", "ul", "whitespace" ],
|
|
11
|
-
"parser": "micromark",
|
|
12
|
-
"function": function MD030(params, onError) {
|
|
13
|
-
const ulSingle = Number(params.config.ul_single || 1);
|
|
14
|
-
const olSingle = Number(params.config.ol_single || 1);
|
|
15
|
-
const ulMulti = Number(params.config.ul_multi || 1);
|
|
16
|
-
const olMulti = Number(params.config.ol_multi || 1);
|
|
17
|
-
for (const list of filterByTypesCached([ "listOrdered", "listUnordered" ])) {
|
|
18
|
-
const ordered = (list.type === "listOrdered");
|
|
19
|
-
const listItemPrefixes =
|
|
20
|
-
list.children.filter((token) => (token.type === "listItemPrefix"));
|
|
21
|
-
const allSingleLine =
|
|
22
|
-
(list.endLine - list.startLine + 1) === listItemPrefixes.length;
|
|
23
|
-
const expectedSpaces = ordered ?
|
|
24
|
-
(allSingleLine ? olSingle : olMulti) :
|
|
25
|
-
(allSingleLine ? ulSingle : ulMulti);
|
|
26
|
-
for (const listItemPrefix of listItemPrefixes) {
|
|
27
|
-
const range = [
|
|
28
|
-
listItemPrefix.startColumn,
|
|
29
|
-
listItemPrefix.endColumn - listItemPrefix.startColumn
|
|
30
|
-
];
|
|
31
|
-
const listItemPrefixWhitespaces = listItemPrefix.children.filter(
|
|
32
|
-
(token) => (token.type === "listItemPrefixWhitespace")
|
|
33
|
-
);
|
|
34
|
-
for (const listItemPrefixWhitespace of listItemPrefixWhitespaces) {
|
|
35
|
-
const { endColumn, startColumn, startLine } =
|
|
36
|
-
listItemPrefixWhitespace;
|
|
37
|
-
const actualSpaces = endColumn - startColumn;
|
|
38
|
-
const fixInfo = {
|
|
39
|
-
"editColumn": startColumn,
|
|
40
|
-
"deleteCount": actualSpaces,
|
|
41
|
-
"insertText": "".padEnd(expectedSpaces)
|
|
42
|
-
};
|
|
43
|
-
addErrorDetailIf(
|
|
44
|
-
onError,
|
|
45
|
-
startLine,
|
|
46
|
-
expectedSpaces,
|
|
47
|
-
actualSpaces,
|
|
48
|
-
undefined,
|
|
49
|
-
undefined,
|
|
50
|
-
range,
|
|
51
|
-
fixInfo
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
const codeFencePrefixRe = /^(.*?)[`~]/;
|
|
8
|
-
|
|
9
|
-
/** @typedef {readonly string[]} ReadonlyStringArray */
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Adds an error for the top or bottom of a code fence.
|
|
13
|
-
*
|
|
14
|
-
* @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
|
|
15
|
-
* @param {ReadonlyStringArray} lines Lines of Markdown content.
|
|
16
|
-
* @param {number} lineNumber Line number.
|
|
17
|
-
* @param {boolean} top True iff top fence.
|
|
18
|
-
* @returns {void}
|
|
19
|
-
*/
|
|
20
|
-
function addError(onError, lines, lineNumber, top) {
|
|
21
|
-
const line = lines[lineNumber - 1];
|
|
22
|
-
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
|
|
23
|
-
const fixInfo = (prefix === undefined) ?
|
|
24
|
-
undefined :
|
|
25
|
-
{
|
|
26
|
-
"lineNumber": lineNumber + (top ? 0 : 1),
|
|
27
|
-
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
|
|
28
|
-
};
|
|
29
|
-
addErrorContext(
|
|
30
|
-
onError,
|
|
31
|
-
lineNumber,
|
|
32
|
-
line.trim(),
|
|
33
|
-
undefined,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
fixInfo
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** @type {import("markdownlint").Rule} */
|
|
41
|
-
export default {
|
|
42
|
-
"names": [ "MD031", "blanks-around-fences" ],
|
|
43
|
-
"description": "Fenced code blocks should be surrounded by blank lines",
|
|
44
|
-
"tags": [ "code", "blank_lines" ],
|
|
45
|
-
"parser": "micromark",
|
|
46
|
-
"function": function MD031(params, onError) {
|
|
47
|
-
const listItems = params.config.list_items;
|
|
48
|
-
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
|
49
|
-
const { lines } = params;
|
|
50
|
-
for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
|
|
51
|
-
if (includeListItems || !(getParentOfType(codeBlock, [ "listOrdered", "listUnordered" ]))) {
|
|
52
|
-
if (!isBlankLine(lines[codeBlock.startLine - 2])) {
|
|
53
|
-
addError(onError, lines, codeBlock.startLine, true);
|
|
54
|
-
}
|
|
55
|
-
if (!isBlankLine(lines[codeBlock.endLine]) && !isBlankLine(lines[codeBlock.endLine - 1])) {
|
|
56
|
-
addError(onError, lines, codeBlock.endLine, false);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
|
|
4
|
-
import { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
8
|
-
|
|
9
|
-
const isList = (/** @type {MicromarkToken} */ token) => (
|
|
10
|
-
(token.type === "listOrdered") || (token.type === "listUnordered")
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
/** @type {import("markdownlint").Rule} */
|
|
14
|
-
export default {
|
|
15
|
-
"names": [ "MD032", "blanks-around-lists" ],
|
|
16
|
-
"description": "Lists should be surrounded by blank lines",
|
|
17
|
-
"tags": [ "bullet", "ul", "ol", "blank_lines" ],
|
|
18
|
-
"parser": "micromark",
|
|
19
|
-
"function": function MD032(params, onError) {
|
|
20
|
-
const { lines, parsers } = params;
|
|
21
|
-
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
|
22
|
-
|
|
23
|
-
// For every top-level list...
|
|
24
|
-
const topLevelLists = filterByPredicate(
|
|
25
|
-
parsers.micromark.tokens,
|
|
26
|
-
isList,
|
|
27
|
-
(token) => (
|
|
28
|
-
(isList(token) || (token.type === "htmlFlow")) ? [] : token.children
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
for (const list of topLevelLists) {
|
|
32
|
-
|
|
33
|
-
// Look for a blank line above the list
|
|
34
|
-
const firstLineNumber = list.startLine;
|
|
35
|
-
if (!isBlankLine(lines[firstLineNumber - 2])) {
|
|
36
|
-
addErrorContext(
|
|
37
|
-
onError,
|
|
38
|
-
firstLineNumber,
|
|
39
|
-
lines[firstLineNumber - 1].trim(),
|
|
40
|
-
undefined,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
{
|
|
44
|
-
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, firstLineNumber)
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Find the "visual" end of the list
|
|
50
|
-
const flattenedChildren = filterByPredicate(
|
|
51
|
-
list.children,
|
|
52
|
-
(token) => !nonContentTokens.has(token.type),
|
|
53
|
-
(token) => nonContentTokens.has(token.type) ? [] : token.children
|
|
54
|
-
);
|
|
55
|
-
let endLine = list.endLine;
|
|
56
|
-
if (flattenedChildren.length > 0) {
|
|
57
|
-
endLine = flattenedChildren[flattenedChildren.length - 1].endLine;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Look for a blank line below the list
|
|
61
|
-
const lastLineNumber = endLine;
|
|
62
|
-
if (!isBlankLine(lines[lastLineNumber])) {
|
|
63
|
-
addErrorContext(
|
|
64
|
-
onError,
|
|
65
|
-
lastLineNumber,
|
|
66
|
-
lines[lastLineNumber - 1].trim(),
|
|
67
|
-
undefined,
|
|
68
|
-
undefined,
|
|
69
|
-
undefined,
|
|
70
|
-
{
|
|
71
|
-
"lineNumber": lastLineNumber + 1,
|
|
72
|
-
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, lastLineNumber)
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addError, nextLinesRe } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getHtmlTagInfo, getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line jsdoc/reject-any-type
|
|
10
|
-
const toLowerCaseStringArray = (/** @type {any} */ arr) => Array.isArray(arr) ? arr.map((elm) => String(elm).toLowerCase()) : [];
|
|
11
|
-
|
|
12
|
-
/** @type {import("markdownlint").Rule} */
|
|
13
|
-
export default {
|
|
14
|
-
"names": [ "MD033", "no-inline-html" ],
|
|
15
|
-
"description": "Inline HTML",
|
|
16
|
-
"tags": [ "html" ],
|
|
17
|
-
"parser": "micromark",
|
|
18
|
-
"function": function MD033(params, onError) {
|
|
19
|
-
const allowedElements = toLowerCaseStringArray(params.config.allowed_elements);
|
|
20
|
-
// If not defined, use allowedElements for backward compatibility
|
|
21
|
-
const tableAllowedElements = toLowerCaseStringArray(params.config.table_allowed_elements || params.config.allowed_elements);
|
|
22
|
-
for (const token of filterByTypesCached([ "htmlText" ], true)) {
|
|
23
|
-
const htmlTagInfo = getHtmlTagInfo(token);
|
|
24
|
-
if (htmlTagInfo && !htmlTagInfo.close) {
|
|
25
|
-
const elementName = htmlTagInfo?.name.toLowerCase();
|
|
26
|
-
const inTable = !!getParentOfType(token, [ "table" ]);
|
|
27
|
-
if (
|
|
28
|
-
(inTable || !allowedElements.includes(elementName)) &&
|
|
29
|
-
(!inTable || !tableAllowedElements.includes(elementName))
|
|
30
|
-
) {
|
|
31
|
-
const range = [
|
|
32
|
-
token.startColumn,
|
|
33
|
-
token.text.replace(nextLinesRe, "").length
|
|
34
|
-
];
|
|
35
|
-
addError(
|
|
36
|
-
onError,
|
|
37
|
-
token.startLine,
|
|
38
|
-
"Element: " + htmlTagInfo.name,
|
|
39
|
-
undefined,
|
|
40
|
-
range
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorContext } from "../helpers/helpers.cjs";
|
|
4
|
-
import { filterByPredicate, getHtmlTagInfo, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
|
|
6
|
-
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
7
|
-
/** @typedef {import("micromark-extension-gfm-autolink-literal")} */
|
|
8
|
-
|
|
9
|
-
/** @type {import("markdownlint").Rule} */
|
|
10
|
-
export default {
|
|
11
|
-
"names": [ "MD034", "no-bare-urls" ],
|
|
12
|
-
"description": "Bare URL used",
|
|
13
|
-
"tags": [ "links", "url" ],
|
|
14
|
-
"parser": "micromark",
|
|
15
|
-
"function": function MD034(params, onError) {
|
|
16
|
-
const literalAutolinks = (/** @type {MicromarkToken[]} */ tokens) => (
|
|
17
|
-
filterByPredicate(
|
|
18
|
-
tokens,
|
|
19
|
-
(token) => {
|
|
20
|
-
if ((token.type === "literalAutolink") && !inHtmlFlow(token)) {
|
|
21
|
-
// Detect and ignore https://github.com/micromark/micromark/issues/164
|
|
22
|
-
const siblings = token.parent?.children;
|
|
23
|
-
const index = siblings?.indexOf(token);
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const prev = siblings?.at(index - 1);
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
const next = siblings?.at(index + 1);
|
|
28
|
-
return !(
|
|
29
|
-
prev &&
|
|
30
|
-
next &&
|
|
31
|
-
(prev.type === "data") &&
|
|
32
|
-
(next.type === "data") &&
|
|
33
|
-
prev.text.endsWith("<") &&
|
|
34
|
-
next.text.startsWith(">")
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
},
|
|
39
|
-
(token) => {
|
|
40
|
-
// Ignore content of inline HTML tags
|
|
41
|
-
const { children } = token;
|
|
42
|
-
const result = [];
|
|
43
|
-
for (let i = 0; i < children.length; i++) {
|
|
44
|
-
const current = children[i];
|
|
45
|
-
const openTagInfo = getHtmlTagInfo(current);
|
|
46
|
-
if (openTagInfo && !openTagInfo.close) {
|
|
47
|
-
let count = 1;
|
|
48
|
-
for (let j = i + 1; j < children.length; j++) {
|
|
49
|
-
const candidate = children[j];
|
|
50
|
-
const closeTagInfo = getHtmlTagInfo(candidate);
|
|
51
|
-
if (closeTagInfo && (openTagInfo.name === closeTagInfo.name)) {
|
|
52
|
-
if (closeTagInfo.close) {
|
|
53
|
-
count--;
|
|
54
|
-
if (count === 0) {
|
|
55
|
-
i = j;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
count++;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
result.push(current);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
for (const token of literalAutolinks(params.parsers.micromark.tokens)) {
|
|
72
|
-
const range = [
|
|
73
|
-
token.startColumn,
|
|
74
|
-
token.endColumn - token.startColumn
|
|
75
|
-
];
|
|
76
|
-
const fixInfo = {
|
|
77
|
-
"editColumn": range[0],
|
|
78
|
-
"deleteCount": range[1],
|
|
79
|
-
"insertText": `<${token.text}>`
|
|
80
|
-
};
|
|
81
|
-
addErrorContext(
|
|
82
|
-
onError,
|
|
83
|
-
token.startLine,
|
|
84
|
-
token.text,
|
|
85
|
-
undefined,
|
|
86
|
-
undefined,
|
|
87
|
-
range,
|
|
88
|
-
fixInfo
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
5
|
-
|
|
6
|
-
/** @type {import("markdownlint").Rule} */
|
|
7
|
-
export default {
|
|
8
|
-
"names": [ "MD035", "hr-style" ],
|
|
9
|
-
"description": "Horizontal rule style",
|
|
10
|
-
"tags": [ "hr" ],
|
|
11
|
-
"parser": "micromark",
|
|
12
|
-
"function": function MD035(params, onError) {
|
|
13
|
-
let style = String(params.config.style || "consistent").trim();
|
|
14
|
-
const thematicBreaks = filterByTypesCached([ "thematicBreak" ]);
|
|
15
|
-
for (const token of thematicBreaks) {
|
|
16
|
-
const { startLine, text } = token;
|
|
17
|
-
if (style === "consistent") {
|
|
18
|
-
style = text;
|
|
19
|
-
}
|
|
20
|
-
addErrorDetailIf(onError, startLine, style, text);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorContext, allPunctuation } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
|
|
8
|
-
/** @typedef {import("markdownlint").MicromarkTokenType} MicromarkTokenType */
|
|
9
|
-
|
|
10
|
-
/** @type {MicromarkTokenType[][]} */
|
|
11
|
-
const emphasisTypes = [
|
|
12
|
-
[ "emphasis", "emphasisText" ],
|
|
13
|
-
[ "strong", "strongText" ]
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const isParagraphChildMeaningful = (/** @type {MicromarkToken} */ token) => !(
|
|
17
|
-
(token.type === "htmlText") ||
|
|
18
|
-
((token.type === "data") && (token.text.trim().length === 0))
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
/** @type {import("markdownlint").Rule} */
|
|
22
|
-
export default {
|
|
23
|
-
"names": [ "MD036", "no-emphasis-as-heading" ],
|
|
24
|
-
"description": "Emphasis used instead of a heading",
|
|
25
|
-
"tags": [ "headings", "emphasis" ],
|
|
26
|
-
"parser": "micromark",
|
|
27
|
-
"function": function MD036(params, onError) {
|
|
28
|
-
let punctuation = params.config.punctuation;
|
|
29
|
-
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
|
30
|
-
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
|
31
|
-
const paragraphTokens =
|
|
32
|
-
filterByTypesCached([ "paragraph" ], true)
|
|
33
|
-
.filter((token) =>
|
|
34
|
-
(token.parent?.type === "content") &&
|
|
35
|
-
(
|
|
36
|
-
!token.parent?.parent ||
|
|
37
|
-
((token.parent?.parent?.type === "htmlFlow") && !token.parent?.parent?.parent)
|
|
38
|
-
) &&
|
|
39
|
-
(token.children.filter(isParagraphChildMeaningful).length === 1)
|
|
40
|
-
);
|
|
41
|
-
for (const emphasisType of emphasisTypes) {
|
|
42
|
-
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
|
43
|
-
for (const textToken of textTokens) {
|
|
44
|
-
if (
|
|
45
|
-
(textToken.children.length === 1) &&
|
|
46
|
-
// eslint-disable-next-line unicorn/better-dom-traversing
|
|
47
|
-
(textToken.children[0].type === "data") &&
|
|
48
|
-
!punctuationRe.test(textToken.text)
|
|
49
|
-
) {
|
|
50
|
-
addErrorContext(onError, textToken.startLine, textToken.text);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addError } from "../helpers/helpers.cjs";
|
|
4
|
-
import { filterByPredicate, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
|
|
6
|
-
/** @type {import("markdownlint").Rule} */
|
|
7
|
-
export default {
|
|
8
|
-
"names": [ "MD037", "no-space-in-emphasis" ],
|
|
9
|
-
"description": "Spaces inside emphasis markers",
|
|
10
|
-
"tags": [ "whitespace", "emphasis" ],
|
|
11
|
-
"parser": "micromark",
|
|
12
|
-
"function": function MD037(params, onError) {
|
|
13
|
-
|
|
14
|
-
// Initialize variables
|
|
15
|
-
const { lines, parsers } = params;
|
|
16
|
-
const emphasisTokensByMarker = new Map();
|
|
17
|
-
for (const marker of [ "_", "__", "___", "*", "**", "***" ]) {
|
|
18
|
-
emphasisTokensByMarker.set(marker, []);
|
|
19
|
-
}
|
|
20
|
-
const tokens = filterByPredicate(
|
|
21
|
-
parsers.micromark.tokens,
|
|
22
|
-
(token) => token.children.some((child) => child.type === "data")
|
|
23
|
-
);
|
|
24
|
-
for (const token of tokens) {
|
|
25
|
-
|
|
26
|
-
// Build lists of bare tokens for each emphasis marker type
|
|
27
|
-
for (const emphasisTokens of emphasisTokensByMarker.values()) {
|
|
28
|
-
emphasisTokens.length = 0;
|
|
29
|
-
}
|
|
30
|
-
for (const child of token.children) {
|
|
31
|
-
const { text, type } = child;
|
|
32
|
-
if ((type === "data") && (text.length <= 3)) {
|
|
33
|
-
const emphasisTokens = emphasisTokensByMarker.get(text);
|
|
34
|
-
if (emphasisTokens && !inHtmlFlow(child)) {
|
|
35
|
-
emphasisTokens.push(child);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Process bare tokens for each emphasis marker type
|
|
41
|
-
for (const entry of emphasisTokensByMarker.entries()) {
|
|
42
|
-
const [ marker, emphasisTokens ] = entry;
|
|
43
|
-
for (let i = 0; i + 1 < emphasisTokens.length; i += 2) {
|
|
44
|
-
|
|
45
|
-
// Process start token of start/end pair
|
|
46
|
-
const startToken = emphasisTokens[i];
|
|
47
|
-
const startLine = lines[startToken.startLine - 1];
|
|
48
|
-
const startSlice = startLine.slice(startToken.endColumn - 1);
|
|
49
|
-
const startMatch = startSlice.match(/^\s+\S/);
|
|
50
|
-
if (startMatch) {
|
|
51
|
-
const [ startSpaceCharacter ] = startMatch;
|
|
52
|
-
const startContext = `${marker}${startSpaceCharacter}`;
|
|
53
|
-
const column = startToken.endColumn;
|
|
54
|
-
const count = startSpaceCharacter.length - 1;
|
|
55
|
-
addError(
|
|
56
|
-
onError,
|
|
57
|
-
startToken.startLine,
|
|
58
|
-
undefined,
|
|
59
|
-
startContext,
|
|
60
|
-
[ column, count ],
|
|
61
|
-
{
|
|
62
|
-
"editColumn": column,
|
|
63
|
-
"deleteCount": count
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Process end token of start/end pair
|
|
69
|
-
const endToken = emphasisTokens[i + 1];
|
|
70
|
-
const endLine = lines[endToken.startLine - 1];
|
|
71
|
-
const endSlice = endLine.slice(0, endToken.startColumn - 1);
|
|
72
|
-
const endMatch = endSlice.match(/\S\s+$/);
|
|
73
|
-
if (endMatch) {
|
|
74
|
-
const [ endSpaceCharacter ] = endMatch;
|
|
75
|
-
const endContext = `${endSpaceCharacter}${marker}`;
|
|
76
|
-
const column = endToken.startColumn - (endSpaceCharacter.length - 1);
|
|
77
|
-
const count = endSpaceCharacter.length - 1;
|
|
78
|
-
addError(
|
|
79
|
-
onError,
|
|
80
|
-
endToken.startLine,
|
|
81
|
-
undefined,
|
|
82
|
-
endContext,
|
|
83
|
-
[ column, count ],
|
|
84
|
-
{
|
|
85
|
-
"editColumn": column,
|
|
86
|
-
"deleteCount": count
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { addErrorContext } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
-
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
-
|
|
7
|
-
/** @type {import("markdownlint").Rule} */
|
|
8
|
-
export default {
|
|
9
|
-
"names": [ "MD038", "no-space-in-code" ],
|
|
10
|
-
"description": "Spaces inside code span elements",
|
|
11
|
-
"tags": [ "whitespace", "code" ],
|
|
12
|
-
"parser": "micromark",
|
|
13
|
-
"function": function MD038(params, onError) {
|
|
14
|
-
const codeTexts = filterByTypesCached([ "codeText" ]);
|
|
15
|
-
for (const codeText of codeTexts) {
|
|
16
|
-
const datas = getDescendantsByType(codeText, [ "codeTextData" ]);
|
|
17
|
-
if (datas.length > 0) {
|
|
18
|
-
const paddings = getDescendantsByType(codeText, [ "codeTextPadding" ]);
|
|
19
|
-
// Check for extra space at start of code
|
|
20
|
-
const startPadding = paddings[0];
|
|
21
|
-
const startData = datas[0];
|
|
22
|
-
const startMatch = /^(\s+)(\S)/.exec(startData.text) || [ null, "", "" ];
|
|
23
|
-
const startBacktick = (startMatch[2] === "`");
|
|
24
|
-
const startCount = startMatch[1].length - ((startBacktick && !startPadding) ? 1 : 0);
|
|
25
|
-
const startSpaces = startCount > 0;
|
|
26
|
-
// Check for extra space at end of code
|
|
27
|
-
const endPadding = paddings[paddings.length - 1];
|
|
28
|
-
const endData = datas[datas.length - 1];
|
|
29
|
-
const endMatch = /(\S)(\s+)$/.exec(endData.text) || [ null, "", "" ];
|
|
30
|
-
const endBacktick = (endMatch[1] === "`");
|
|
31
|
-
const endCount = endMatch[2].length - ((endBacktick && !endPadding) ? 1 : 0);
|
|
32
|
-
const endSpaces = endCount > 0;
|
|
33
|
-
// Check if safe to remove 1-space padding
|
|
34
|
-
const removePadding = startSpaces && endSpaces && startPadding && endPadding && !startBacktick && !endBacktick;
|
|
35
|
-
const context = codeText.text;
|
|
36
|
-
// If extra space at start, report violation
|
|
37
|
-
if (startSpaces) {
|
|
38
|
-
const startColumn = (removePadding ? startPadding : startData).startColumn;
|
|
39
|
-
const length = startCount + (removePadding ? startPadding.text.length : 0);
|
|
40
|
-
addErrorContext(
|
|
41
|
-
onError,
|
|
42
|
-
startData.startLine,
|
|
43
|
-
context,
|
|
44
|
-
true,
|
|
45
|
-
false,
|
|
46
|
-
[ startColumn, length ],
|
|
47
|
-
{
|
|
48
|
-
"editColumn": startColumn,
|
|
49
|
-
"deleteCount": length
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
// If extra space at end, report violation
|
|
54
|
-
if (endSpaces) {
|
|
55
|
-
const endColumn = (removePadding ? endPadding : endData).endColumn;
|
|
56
|
-
const length = endCount + (removePadding ? endPadding.text.length : 0);
|
|
57
|
-
addErrorContext(
|
|
58
|
-
onError,
|
|
59
|
-
endData.endLine,
|
|
60
|
-
context,
|
|
61
|
-
false,
|
|
62
|
-
true,
|
|
63
|
-
[ endColumn - length, length ],
|
|
64
|
-
{
|
|
65
|
-
"editColumn": endColumn - length,
|
|
66
|
-
"deleteCount": length
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|