@alexlit/lint-kit 107.0.0 → 107.2.0
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 -11
- package/packages/config-commitlint/package.json +2 -2
- package/packages/config-eslint/package.json +4 -4
- package/packages/config-hooks/package.json +3 -3
- package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +22 -0
- package/packages/config-markdownlint/node_modules/markdown-it/README.md +309 -0
- package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +117 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +8441 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +3 -0
- package/packages/config-markdownlint/node_modules/markdown-it/index.js +4 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +6 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +70 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +28 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +317 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +7 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +80 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +48 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +582 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +131 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +61 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +192 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +81 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +341 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +352 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +226 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +34 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +98 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +74 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +83 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +362 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +51 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +198 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +231 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +221 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +16 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +13 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +142 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +21 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +105 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +20 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +76 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +71 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +58 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +152 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +150 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +62 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +46 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +158 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +89 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/package.json +87 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +428 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
- package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/README.md +1026 -0
- package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +6814 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +376 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2335 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +70 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +1025 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +426 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +1152 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +14 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +406 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1476 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +76 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +73 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +96 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +108 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +79 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +91 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +97 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +64 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +107 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +89 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +172 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +65 -0
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +109 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +297 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +266 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1762 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
- package/packages/config-markdownlint/package.json +3 -3
- package/packages/config-prettier/README.md +16 -0
- package/packages/config-prettier/package.json +4 -4
- package/packages/config-stylelint/package.json +2 -2
- package/scripts/semver.sh +6 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, escapeForRegExp, filterTokens } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD042", "no-empty-links" ],
|
|
10
|
+
"description": "No empty links",
|
|
11
|
+
"tags": [ "links" ],
|
|
12
|
+
"function": function MD042(params, onError) {
|
|
13
|
+
filterTokens(params, "inline", function forToken(token) {
|
|
14
|
+
let inLink = false;
|
|
15
|
+
let linkText = "";
|
|
16
|
+
let emptyLink = false;
|
|
17
|
+
for (const child of token.children) {
|
|
18
|
+
if (child.type === "link_open") {
|
|
19
|
+
inLink = true;
|
|
20
|
+
linkText = "";
|
|
21
|
+
for (const attr of child.attrs) {
|
|
22
|
+
if (attr[0] === "href" && (!attr[1] || (attr[1] === "#"))) {
|
|
23
|
+
emptyLink = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else if (child.type === "link_close") {
|
|
27
|
+
inLink = false;
|
|
28
|
+
if (emptyLink) {
|
|
29
|
+
let context = `[${linkText}]`;
|
|
30
|
+
let range = null;
|
|
31
|
+
const match = child.line.match(
|
|
32
|
+
new RegExp(`${escapeForRegExp(context)}\\((?:|#|<>)\\)`)
|
|
33
|
+
);
|
|
34
|
+
if (match) {
|
|
35
|
+
context = match[0];
|
|
36
|
+
range = [ match.index + 1, match[0].length ];
|
|
37
|
+
}
|
|
38
|
+
addErrorContext(
|
|
39
|
+
onError, child.lineNumber, context, null, null, range
|
|
40
|
+
);
|
|
41
|
+
emptyLink = false;
|
|
42
|
+
}
|
|
43
|
+
} else if (inLink) {
|
|
44
|
+
linkText += child.content;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, addErrorDetailIf, forEachHeading } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD043", "required-headings" ],
|
|
10
|
+
"description": "Required heading structure",
|
|
11
|
+
"tags": [ "headings" ],
|
|
12
|
+
"function": function MD043(params, onError) {
|
|
13
|
+
const requiredHeadings = params.config.headings;
|
|
14
|
+
if (!Array.isArray(requiredHeadings)) {
|
|
15
|
+
// Nothing to check; avoid doing any work
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const matchCase = params.config.match_case || false;
|
|
19
|
+
const levels = {};
|
|
20
|
+
for (const level of [ 1, 2, 3, 4, 5, 6 ]) {
|
|
21
|
+
levels["h" + level] = "######".substr(-level);
|
|
22
|
+
}
|
|
23
|
+
let i = 0;
|
|
24
|
+
let matchAny = false;
|
|
25
|
+
let hasError = false;
|
|
26
|
+
let anyHeadings = false;
|
|
27
|
+
const getExpected = () => requiredHeadings[i++] || "[None]";
|
|
28
|
+
const handleCase = (str) => (matchCase ? str : str.toLowerCase());
|
|
29
|
+
forEachHeading(params, (heading, content) => {
|
|
30
|
+
if (!hasError) {
|
|
31
|
+
anyHeadings = true;
|
|
32
|
+
const actual = levels[heading.tag] + " " + content;
|
|
33
|
+
const expected = getExpected();
|
|
34
|
+
if (expected === "*") {
|
|
35
|
+
const nextExpected = getExpected();
|
|
36
|
+
if (handleCase(nextExpected) !== handleCase(actual)) {
|
|
37
|
+
matchAny = true;
|
|
38
|
+
i--;
|
|
39
|
+
}
|
|
40
|
+
} else if (expected === "+") {
|
|
41
|
+
matchAny = true;
|
|
42
|
+
} else if (handleCase(expected) === handleCase(actual)) {
|
|
43
|
+
matchAny = false;
|
|
44
|
+
} else if (matchAny) {
|
|
45
|
+
i--;
|
|
46
|
+
} else {
|
|
47
|
+
addErrorDetailIf(onError, heading.lineNumber,
|
|
48
|
+
expected, actual);
|
|
49
|
+
hasError = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const extraHeadings = requiredHeadings.length - i;
|
|
54
|
+
if (
|
|
55
|
+
!hasError &&
|
|
56
|
+
((extraHeadings > 1) ||
|
|
57
|
+
((extraHeadings === 1) && (requiredHeadings[i] !== "*"))) &&
|
|
58
|
+
(anyHeadings || !requiredHeadings.every((heading) => heading === "*"))
|
|
59
|
+
) {
|
|
60
|
+
addErrorContext(onError, params.lines.length,
|
|
61
|
+
requiredHeadings[i]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf, escapeForRegExp, withinAnyRange } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
const { filterByPredicate, filterByTypes, parse } =
|
|
8
|
+
require("../helpers/micromark.cjs");
|
|
9
|
+
|
|
10
|
+
const ignoredChildTypes = new Set(
|
|
11
|
+
[ "codeFencedFence", "definition", "reference", "resource" ]
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
"names": [ "MD044", "proper-names" ],
|
|
16
|
+
"description": "Proper names should have the correct capitalization",
|
|
17
|
+
"tags": [ "spelling" ],
|
|
18
|
+
"function": function MD044(params, onError) {
|
|
19
|
+
let names = params.config.names;
|
|
20
|
+
names = Array.isArray(names) ? names : [];
|
|
21
|
+
names.sort((a, b) => (b.length - a.length) || a.localeCompare(b));
|
|
22
|
+
if (names.length === 0) {
|
|
23
|
+
// Nothing to check; avoid doing any work
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const codeBlocks = params.config.code_blocks;
|
|
27
|
+
const includeCodeBlocks =
|
|
28
|
+
(codeBlocks === undefined) ? true : !!codeBlocks;
|
|
29
|
+
const htmlElements = params.config.html_elements;
|
|
30
|
+
const includeHtmlElements =
|
|
31
|
+
(htmlElements === undefined) ? true : !!htmlElements;
|
|
32
|
+
const scannedTypes = new Set([ "data" ]);
|
|
33
|
+
if (includeCodeBlocks) {
|
|
34
|
+
scannedTypes.add("codeFlowValue");
|
|
35
|
+
scannedTypes.add("codeTextData");
|
|
36
|
+
}
|
|
37
|
+
if (includeHtmlElements) {
|
|
38
|
+
scannedTypes.add("htmlFlowData");
|
|
39
|
+
scannedTypes.add("htmlTextData");
|
|
40
|
+
}
|
|
41
|
+
const contentTokens =
|
|
42
|
+
filterByPredicate(
|
|
43
|
+
params.parsers.micromark.tokens,
|
|
44
|
+
(token) => scannedTypes.has(token.type),
|
|
45
|
+
(token) => (
|
|
46
|
+
token.children.filter((t) => !ignoredChildTypes.has(t.type))
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
const exclusions = [];
|
|
50
|
+
const autoLinked = new Set();
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
const escapedName = escapeForRegExp(name);
|
|
53
|
+
const startNamePattern = /^\W/.test(name) ? "" : "\\b_*";
|
|
54
|
+
const endNamePattern = /\W$/.test(name) ? "" : "_*\\b";
|
|
55
|
+
const namePattern =
|
|
56
|
+
`(${startNamePattern})(${escapedName})${endNamePattern}`;
|
|
57
|
+
const nameRe = new RegExp(namePattern, "gi");
|
|
58
|
+
for (const token of contentTokens) {
|
|
59
|
+
let match = null;
|
|
60
|
+
while ((match = nameRe.exec(token.text)) !== null) {
|
|
61
|
+
const [ , leftMatch, nameMatch ] = match;
|
|
62
|
+
const index = token.startColumn - 1 + match.index + leftMatch.length;
|
|
63
|
+
const length = nameMatch.length;
|
|
64
|
+
const lineIndex = token.startLine - 1;
|
|
65
|
+
if (
|
|
66
|
+
!withinAnyRange(exclusions, lineIndex, index, length) &&
|
|
67
|
+
!names.includes(nameMatch)
|
|
68
|
+
) {
|
|
69
|
+
let urlRanges = [];
|
|
70
|
+
if (!autoLinked.has(token)) {
|
|
71
|
+
urlRanges = filterByTypes(
|
|
72
|
+
parse(token.text),
|
|
73
|
+
[ "literalAutolink" ]
|
|
74
|
+
).map(
|
|
75
|
+
(t) => [
|
|
76
|
+
lineIndex,
|
|
77
|
+
token.startColumn - 1 + t.startColumn - 1,
|
|
78
|
+
t.endColumn - t.startColumn
|
|
79
|
+
]
|
|
80
|
+
);
|
|
81
|
+
exclusions.push(...urlRanges);
|
|
82
|
+
autoLinked.add(token);
|
|
83
|
+
}
|
|
84
|
+
if (!withinAnyRange(urlRanges, lineIndex, index, length)) {
|
|
85
|
+
const column = index + 1;
|
|
86
|
+
addErrorDetailIf(
|
|
87
|
+
onError,
|
|
88
|
+
token.startLine,
|
|
89
|
+
name,
|
|
90
|
+
nameMatch,
|
|
91
|
+
null,
|
|
92
|
+
null,
|
|
93
|
+
[ column, length ],
|
|
94
|
+
{
|
|
95
|
+
"editColumn": column,
|
|
96
|
+
"deleteCount": length,
|
|
97
|
+
"insertText": name
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exclusions.push([ lineIndex, index, length ]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
|
|
6
|
+
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
const altRe = getHtmlAttributeRe("alt");
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"names": [ "MD045", "no-alt-text" ],
|
|
12
|
+
"description": "Images should have alternate text (alt text)",
|
|
13
|
+
"tags": [ "accessibility", "images" ],
|
|
14
|
+
"function": function MD045(params, onError) {
|
|
15
|
+
const { tokens } = params.parsers.micromark;
|
|
16
|
+
|
|
17
|
+
// Process Markdown images
|
|
18
|
+
const images = filterByTypes(tokens, [ "image" ]);
|
|
19
|
+
for (const image of images) {
|
|
20
|
+
const labelTexts = filterByTypes(image.children, [ "labelText" ]);
|
|
21
|
+
if (labelTexts.some((labelText) => labelText.text.length === 0)) {
|
|
22
|
+
const range = (image.startLine === image.endLine) ?
|
|
23
|
+
[ image.startColumn, image.endColumn - image.startColumn ] :
|
|
24
|
+
undefined;
|
|
25
|
+
addError(
|
|
26
|
+
onError,
|
|
27
|
+
image.startLine,
|
|
28
|
+
undefined,
|
|
29
|
+
undefined,
|
|
30
|
+
range
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Process HTML images
|
|
36
|
+
const htmlTexts = filterByTypes(tokens, [ "htmlText" ]);
|
|
37
|
+
for (const htmlText of htmlTexts) {
|
|
38
|
+
const { startColumn, startLine, text } = htmlText;
|
|
39
|
+
const htmlTagInfo = getHtmlTagInfo(htmlText);
|
|
40
|
+
if (
|
|
41
|
+
htmlTagInfo &&
|
|
42
|
+
!htmlTagInfo.close &&
|
|
43
|
+
(htmlTagInfo.name.toLowerCase() === "img") &&
|
|
44
|
+
!altRe.test(text)
|
|
45
|
+
) {
|
|
46
|
+
const range = [
|
|
47
|
+
startColumn,
|
|
48
|
+
text.replace(nextLinesRe, "").length
|
|
49
|
+
];
|
|
50
|
+
addError(
|
|
51
|
+
onError,
|
|
52
|
+
startLine,
|
|
53
|
+
undefined,
|
|
54
|
+
undefined,
|
|
55
|
+
range
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
const tokenTypeToStyle = {
|
|
8
|
+
"fence": "fenced",
|
|
9
|
+
"code_block": "indented"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
"names": [ "MD046", "code-block-style" ],
|
|
14
|
+
"description": "Code block style",
|
|
15
|
+
"tags": [ "code" ],
|
|
16
|
+
"function": function MD046(params, onError) {
|
|
17
|
+
let expectedStyle = String(params.config.style || "consistent");
|
|
18
|
+
const codeBlocksAndFences = params.parsers.markdownit.tokens.filter(
|
|
19
|
+
(token) => (token.type === "code_block") || (token.type === "fence")
|
|
20
|
+
);
|
|
21
|
+
for (const token of codeBlocksAndFences) {
|
|
22
|
+
const { lineNumber, type } = token;
|
|
23
|
+
if (expectedStyle === "consistent") {
|
|
24
|
+
expectedStyle = tokenTypeToStyle[type];
|
|
25
|
+
}
|
|
26
|
+
addErrorDetailIf(
|
|
27
|
+
onError,
|
|
28
|
+
lineNumber,
|
|
29
|
+
expectedStyle,
|
|
30
|
+
tokenTypeToStyle[type]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, isBlankLine } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD047", "single-trailing-newline" ],
|
|
9
|
+
"description": "Files should end with a single newline character",
|
|
10
|
+
"tags": [ "blank_lines" ],
|
|
11
|
+
"function": function MD047(params, onError) {
|
|
12
|
+
const lastLineNumber = params.lines.length;
|
|
13
|
+
const lastLine = params.lines[lastLineNumber - 1];
|
|
14
|
+
if (!isBlankLine(lastLine)) {
|
|
15
|
+
addError(
|
|
16
|
+
onError,
|
|
17
|
+
lastLineNumber,
|
|
18
|
+
null,
|
|
19
|
+
null,
|
|
20
|
+
[ lastLine.length, 1 ],
|
|
21
|
+
{
|
|
22
|
+
"insertText": "\n",
|
|
23
|
+
"editColumn": lastLine.length + 1
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf, fencedCodeBlockStyleFor } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD048", "code-fence-style" ],
|
|
9
|
+
"description": "Code fence style",
|
|
10
|
+
"tags": [ "code" ],
|
|
11
|
+
"function": function MD048(params, onError) {
|
|
12
|
+
const style = String(params.config.style || "consistent");
|
|
13
|
+
let expectedStyle = style;
|
|
14
|
+
const fenceTokens = params.parsers.markdownit.tokens.filter(
|
|
15
|
+
(token) => token.type === "fence"
|
|
16
|
+
);
|
|
17
|
+
for (const fenceToken of fenceTokens) {
|
|
18
|
+
const { lineNumber, markup } = fenceToken;
|
|
19
|
+
if (expectedStyle === "consistent") {
|
|
20
|
+
expectedStyle = fencedCodeBlockStyleFor(markup);
|
|
21
|
+
}
|
|
22
|
+
addErrorDetailIf(
|
|
23
|
+
onError,
|
|
24
|
+
lineNumber,
|
|
25
|
+
expectedStyle,
|
|
26
|
+
fencedCodeBlockStyleFor(markup)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
|
|
6
|
+
const { filterByPredicate, tokenIfType } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
const intrawordRe = /\w/;
|
|
9
|
+
|
|
10
|
+
const impl =
|
|
11
|
+
(params, onError, type, asterisk, underline, style = "consistent") => {
|
|
12
|
+
const { lines, parsers } = params;
|
|
13
|
+
const emphasisTokens = filterByPredicate(
|
|
14
|
+
parsers.micromark.tokens,
|
|
15
|
+
(token) => token.type === type,
|
|
16
|
+
(token) => ((token.type === "htmlFlow") ? [] : token.children)
|
|
17
|
+
);
|
|
18
|
+
for (const token of emphasisTokens) {
|
|
19
|
+
const { children } = token;
|
|
20
|
+
const childType = `${type}Sequence`;
|
|
21
|
+
const startSequence = tokenIfType(children[0], childType);
|
|
22
|
+
const endSequence = tokenIfType(children[children.length - 1], childType);
|
|
23
|
+
if (startSequence && endSequence) {
|
|
24
|
+
const markupStyle = emphasisOrStrongStyleFor(startSequence.text);
|
|
25
|
+
if (style === "consistent") {
|
|
26
|
+
style = markupStyle;
|
|
27
|
+
}
|
|
28
|
+
if (style !== markupStyle) {
|
|
29
|
+
const underscoreIntraword = (style === "underscore") && (
|
|
30
|
+
intrawordRe.test(
|
|
31
|
+
lines[startSequence.startLine - 1][startSequence.startColumn - 2]
|
|
32
|
+
) ||
|
|
33
|
+
intrawordRe.test(
|
|
34
|
+
lines[endSequence.endLine - 1][endSequence.endColumn - 1]
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
if (!underscoreIntraword) {
|
|
38
|
+
for (const sequence of [ startSequence, endSequence ]) {
|
|
39
|
+
addError(
|
|
40
|
+
onError,
|
|
41
|
+
sequence.startLine,
|
|
42
|
+
`Expected: ${style}; Actual: ${markupStyle}`,
|
|
43
|
+
undefined,
|
|
44
|
+
[ sequence.startColumn, sequence.text.length ],
|
|
45
|
+
{
|
|
46
|
+
"editColumn": sequence.startColumn,
|
|
47
|
+
"deleteCount": sequence.text.length,
|
|
48
|
+
"insertText": (style === "asterisk") ? asterisk : underline
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = [
|
|
59
|
+
{
|
|
60
|
+
"names": [ "MD049", "emphasis-style" ],
|
|
61
|
+
"description": "Emphasis style",
|
|
62
|
+
"tags": [ "emphasis" ],
|
|
63
|
+
"function": function MD049(params, onError) {
|
|
64
|
+
return impl(
|
|
65
|
+
params,
|
|
66
|
+
onError,
|
|
67
|
+
"emphasis",
|
|
68
|
+
"*",
|
|
69
|
+
"_",
|
|
70
|
+
params.config.style || undefined
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"names": [ "MD050", "strong-style" ],
|
|
76
|
+
"description": "Strong style",
|
|
77
|
+
"tags": [ "emphasis" ],
|
|
78
|
+
"function": function MD050(params, onError) {
|
|
79
|
+
return impl(
|
|
80
|
+
params,
|
|
81
|
+
onError,
|
|
82
|
+
"strong",
|
|
83
|
+
"**",
|
|
84
|
+
"__",
|
|
85
|
+
params.config.style || undefined
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
];
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, addErrorDetailIf, getHtmlAttributeRe } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
const { filterByPredicate, filterByTypes, getHtmlTagInfo } =
|
|
8
|
+
require("../helpers/micromark.cjs");
|
|
9
|
+
|
|
10
|
+
// Regular expression for identifying HTML anchor names
|
|
11
|
+
const idRe = getHtmlAttributeRe("id");
|
|
12
|
+
const nameRe = getHtmlAttributeRe("name");
|
|
13
|
+
const anchorRe = /\{(#[a-z\d]+(?:[-_][a-z\d]+)*)\}/gu;
|
|
14
|
+
|
|
15
|
+
// Sets for filtering heading tokens during conversion
|
|
16
|
+
const childrenExclude = new Set([ "image", "reference", "resource" ]);
|
|
17
|
+
const tokensInclude = new Set(
|
|
18
|
+
[ "characterEscapeValue", "codeTextData", "data" ]
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {import("../helpers/micromark.cjs").Token} Token
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts a Markdown heading into an HTML fragment according to the rules
|
|
27
|
+
* used by GitHub.
|
|
28
|
+
*
|
|
29
|
+
* @param {Token} headingText Heading text token.
|
|
30
|
+
* @returns {string} Fragment string for heading.
|
|
31
|
+
*/
|
|
32
|
+
function convertHeadingToHTMLFragment(headingText) {
|
|
33
|
+
const inlineText =
|
|
34
|
+
filterByPredicate(
|
|
35
|
+
headingText.children,
|
|
36
|
+
(token) => tokensInclude.has(token.type),
|
|
37
|
+
(token) => (childrenExclude.has(token.type) ? [] : token.children)
|
|
38
|
+
)
|
|
39
|
+
.map((token) => token.text)
|
|
40
|
+
.join("");
|
|
41
|
+
return "#" + encodeURIComponent(
|
|
42
|
+
inlineText
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
// RegExp source with Ruby's \p{Word} expanded into its General Categories
|
|
45
|
+
// https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb
|
|
46
|
+
// https://ruby-doc.org/core-3.0.2/Regexp.html
|
|
47
|
+
.replace(
|
|
48
|
+
/[^\p{Letter}\p{Mark}\p{Number}\p{Connector_Punctuation}\- ]/gu,
|
|
49
|
+
""
|
|
50
|
+
)
|
|
51
|
+
.replace(/ /gu, "-")
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Unescapes the text of a String-type micromark Token.
|
|
57
|
+
*
|
|
58
|
+
* @param {Token} token String-type micromark Token.
|
|
59
|
+
* @returns {string} Unescaped token text.
|
|
60
|
+
*/
|
|
61
|
+
function unescapeStringTokenText(token) {
|
|
62
|
+
return filterByTypes(token.children, [ "characterEscapeValue", "data" ])
|
|
63
|
+
.map((child) => child.text)
|
|
64
|
+
.join("");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
"names": [ "MD051", "link-fragments" ],
|
|
69
|
+
"description": "Link fragments should be valid",
|
|
70
|
+
"tags": [ "links" ],
|
|
71
|
+
"function": function MD051(params, onError) {
|
|
72
|
+
const { tokens } = params.parsers.micromark;
|
|
73
|
+
const fragments = new Map();
|
|
74
|
+
|
|
75
|
+
// Process headings
|
|
76
|
+
const headingTexts = filterByTypes(
|
|
77
|
+
tokens,
|
|
78
|
+
[ "atxHeadingText", "setextHeadingText" ]
|
|
79
|
+
);
|
|
80
|
+
for (const headingText of headingTexts) {
|
|
81
|
+
const fragment = convertHeadingToHTMLFragment(headingText);
|
|
82
|
+
if (fragment !== "#") {
|
|
83
|
+
const count = fragments.get(fragment) || 0;
|
|
84
|
+
if (count) {
|
|
85
|
+
fragments.set(`${fragment}-${count}`, 0);
|
|
86
|
+
}
|
|
87
|
+
fragments.set(fragment, count + 1);
|
|
88
|
+
let match = null;
|
|
89
|
+
while ((match = anchorRe.exec(headingText.text)) !== null) {
|
|
90
|
+
const [ , anchor ] = match;
|
|
91
|
+
if (!fragments.has(anchor)) {
|
|
92
|
+
fragments.set(anchor, 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Process HTML anchors
|
|
99
|
+
for (const token of filterByTypes(tokens, [ "htmlText" ])) {
|
|
100
|
+
const htmlTagInfo = getHtmlTagInfo(token);
|
|
101
|
+
if (htmlTagInfo && !htmlTagInfo.close) {
|
|
102
|
+
const anchorMatch = idRe.exec(token.text) ||
|
|
103
|
+
(htmlTagInfo.name.toLowerCase() === "a" && nameRe.exec(token.text));
|
|
104
|
+
if (anchorMatch && anchorMatch.length > 0) {
|
|
105
|
+
fragments.set(`#${anchorMatch[1]}`, 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Process link and definition fragments
|
|
111
|
+
const parentChilds = [
|
|
112
|
+
[ "link", "resourceDestinationString" ],
|
|
113
|
+
[ "definition", "definitionDestinationString" ]
|
|
114
|
+
];
|
|
115
|
+
for (const [ parentType, definitionType ] of parentChilds) {
|
|
116
|
+
const links = filterByTypes(tokens, [ parentType ]);
|
|
117
|
+
for (const link of links) {
|
|
118
|
+
const definitions = filterByTypes(link.children, [ definitionType ]);
|
|
119
|
+
for (const definition of definitions) {
|
|
120
|
+
const { endColumn, startColumn } = definition;
|
|
121
|
+
const text = unescapeStringTokenText(definition);
|
|
122
|
+
if (
|
|
123
|
+
(text.length > 1) &&
|
|
124
|
+
text.startsWith("#") &&
|
|
125
|
+
!fragments.has(text) &&
|
|
126
|
+
!fragments.has(`#${encodeURIComponent(text.slice(1))}`)
|
|
127
|
+
) {
|
|
128
|
+
// eslint-disable-next-line no-undef-init
|
|
129
|
+
let context = undefined;
|
|
130
|
+
// eslint-disable-next-line no-undef-init
|
|
131
|
+
let range = undefined;
|
|
132
|
+
// eslint-disable-next-line no-undef-init
|
|
133
|
+
let fixInfo = undefined;
|
|
134
|
+
if (link.startLine === link.endLine) {
|
|
135
|
+
context = link.text;
|
|
136
|
+
range = [ link.startColumn, link.endColumn - link.startColumn ];
|
|
137
|
+
fixInfo = {
|
|
138
|
+
"editColumn": startColumn,
|
|
139
|
+
"deleteCount": endColumn - startColumn
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const textLower = text.toLowerCase();
|
|
143
|
+
const mixedCaseKey = [ ...fragments.keys() ]
|
|
144
|
+
.find((key) => textLower === key.toLowerCase());
|
|
145
|
+
if (mixedCaseKey) {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
(fixInfo || {}).insertText = mixedCaseKey;
|
|
148
|
+
addErrorDetailIf(
|
|
149
|
+
onError,
|
|
150
|
+
link.startLine,
|
|
151
|
+
mixedCaseKey,
|
|
152
|
+
text,
|
|
153
|
+
undefined,
|
|
154
|
+
context,
|
|
155
|
+
range,
|
|
156
|
+
fixInfo
|
|
157
|
+
);
|
|
158
|
+
} else {
|
|
159
|
+
addError(
|
|
160
|
+
onError,
|
|
161
|
+
link.startLine,
|
|
162
|
+
undefined,
|
|
163
|
+
context,
|
|
164
|
+
range
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError } = require("../helpers");
|
|
6
|
+
const { referenceLinkImageData } = require("./cache");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD052", "reference-links-images" ],
|
|
10
|
+
"description":
|
|
11
|
+
"Reference links and images should use a label that is defined",
|
|
12
|
+
"tags": [ "images", "links" ],
|
|
13
|
+
"function": function MD052(params, onError) {
|
|
14
|
+
const { config, lines } = params;
|
|
15
|
+
const shortcutSyntax = config.shortcut_syntax || false;
|
|
16
|
+
const { definitions, references, shortcuts } = referenceLinkImageData();
|
|
17
|
+
const entries = shortcutSyntax ?
|
|
18
|
+
[ ...references.entries(), ...shortcuts.entries() ] :
|
|
19
|
+
references.entries();
|
|
20
|
+
// Look for links/images that use an undefined link reference
|
|
21
|
+
for (const reference of entries) {
|
|
22
|
+
const [ label, datas ] = reference;
|
|
23
|
+
if (!definitions.has(label)) {
|
|
24
|
+
for (const data of datas) {
|
|
25
|
+
const [ lineIndex, index, length ] = data;
|
|
26
|
+
// Context will be incomplete if reporting for a multi-line link
|
|
27
|
+
const context = lines[lineIndex].slice(index, index + length);
|
|
28
|
+
addError(
|
|
29
|
+
onError,
|
|
30
|
+
lineIndex + 1,
|
|
31
|
+
`Missing link or image reference definition: "${label}"`,
|
|
32
|
+
context,
|
|
33
|
+
[ index + 1, context.length ]
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|