@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,34 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, forEachLine } = require("../helpers");
|
|
6
|
+
const { lineMetadata } = require("./cache");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD018", "no-missing-space-atx" ],
|
|
10
|
+
"description": "No space after hash on atx style heading",
|
|
11
|
+
"tags": [ "headings", "atx", "spaces" ],
|
|
12
|
+
"function": function MD018(params, onError) {
|
|
13
|
+
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
|
14
|
+
if (!inCode &&
|
|
15
|
+
/^#+[^# \t]/.test(line) &&
|
|
16
|
+
!/#\s*$/.test(line) &&
|
|
17
|
+
!line.startsWith("#️⃣")) {
|
|
18
|
+
const hashCount = /^#+/.exec(line)[0].length;
|
|
19
|
+
addErrorContext(
|
|
20
|
+
onError,
|
|
21
|
+
lineIndex + 1,
|
|
22
|
+
line.trim(),
|
|
23
|
+
null,
|
|
24
|
+
null,
|
|
25
|
+
[ 1, hashCount + 1 ],
|
|
26
|
+
{
|
|
27
|
+
"editColumn": hashCount + 1,
|
|
28
|
+
"insertText": " "
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, filterTokens, headingStyleFor } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD019", "no-multiple-space-atx" ],
|
|
10
|
+
"description": "Multiple spaces after hash on atx style heading",
|
|
11
|
+
"tags": [ "headings", "atx", "spaces" ],
|
|
12
|
+
"function": function MD019(params, onError) {
|
|
13
|
+
filterTokens(params, "heading_open", (token) => {
|
|
14
|
+
if (headingStyleFor(token) === "atx") {
|
|
15
|
+
const { line, lineNumber } = token;
|
|
16
|
+
const match = /^(#+)([ \t]{2,})\S/.exec(line);
|
|
17
|
+
if (match) {
|
|
18
|
+
const [
|
|
19
|
+
,
|
|
20
|
+
{ "length": hashLength },
|
|
21
|
+
{ "length": spacesLength }
|
|
22
|
+
] = match;
|
|
23
|
+
addErrorContext(
|
|
24
|
+
onError,
|
|
25
|
+
lineNumber,
|
|
26
|
+
line.trim(),
|
|
27
|
+
null,
|
|
28
|
+
null,
|
|
29
|
+
[ 1, hashLength + spacesLength + 1 ],
|
|
30
|
+
{
|
|
31
|
+
"editColumn": hashLength + 1,
|
|
32
|
+
"deleteCount": spacesLength - 1
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, forEachLine } = require("../helpers");
|
|
6
|
+
const { lineMetadata } = require("./cache");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD020", "no-missing-space-closed-atx" ],
|
|
10
|
+
"description": "No space inside hashes on closed atx style heading",
|
|
11
|
+
"tags": [ "headings", "atx_closed", "spaces" ],
|
|
12
|
+
"function": function MD020(params, onError) {
|
|
13
|
+
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
|
14
|
+
if (!inCode) {
|
|
15
|
+
const match =
|
|
16
|
+
/^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
|
|
17
|
+
if (match) {
|
|
18
|
+
const [
|
|
19
|
+
,
|
|
20
|
+
leftHash,
|
|
21
|
+
{ "length": leftSpaceLength },
|
|
22
|
+
content,
|
|
23
|
+
{ "length": rightSpaceLength },
|
|
24
|
+
rightEscape,
|
|
25
|
+
rightHash,
|
|
26
|
+
{ "length": trailSpaceLength }
|
|
27
|
+
] = match;
|
|
28
|
+
const leftHashLength = leftHash.length;
|
|
29
|
+
const rightHashLength = rightHash.length;
|
|
30
|
+
const left = !leftSpaceLength;
|
|
31
|
+
const right = !rightSpaceLength || rightEscape;
|
|
32
|
+
const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : "";
|
|
33
|
+
if (left || right) {
|
|
34
|
+
const range = left ?
|
|
35
|
+
[
|
|
36
|
+
1,
|
|
37
|
+
leftHashLength + 1
|
|
38
|
+
] :
|
|
39
|
+
[
|
|
40
|
+
line.length - trailSpaceLength - rightHashLength,
|
|
41
|
+
rightHashLength + 1
|
|
42
|
+
];
|
|
43
|
+
addErrorContext(
|
|
44
|
+
onError,
|
|
45
|
+
lineIndex + 1,
|
|
46
|
+
line.trim(),
|
|
47
|
+
left,
|
|
48
|
+
right,
|
|
49
|
+
range,
|
|
50
|
+
{
|
|
51
|
+
"editColumn": 1,
|
|
52
|
+
"deleteCount": line.length,
|
|
53
|
+
"insertText":
|
|
54
|
+
`${leftHash} ${content} ${rightEscapeReplacement}${rightHash}`
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, filterTokens, headingStyleFor } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
|
|
8
|
+
const closedAtxRe = /^(#+)([ \t]+)([^ \t]|[^ \t].*[^ \t])([ \t]+)(#+)(\s*)$/;
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
|
12
|
+
"description": "Multiple spaces inside hashes on closed atx style heading",
|
|
13
|
+
"tags": [ "headings", "atx_closed", "spaces" ],
|
|
14
|
+
"function": function MD021(params, onError) {
|
|
15
|
+
filterTokens(params, "heading_open", (token) => {
|
|
16
|
+
if (headingStyleFor(token) === "atx_closed") {
|
|
17
|
+
const { line, lineNumber } = token;
|
|
18
|
+
const match = closedAtxRe.exec(line);
|
|
19
|
+
if (match) {
|
|
20
|
+
const [
|
|
21
|
+
,
|
|
22
|
+
leftHash,
|
|
23
|
+
{ "length": leftSpaceLength },
|
|
24
|
+
content,
|
|
25
|
+
{ "length": rightSpaceLength },
|
|
26
|
+
rightHash,
|
|
27
|
+
{ "length": trailSpaceLength }
|
|
28
|
+
] = match;
|
|
29
|
+
const left = leftSpaceLength > 1;
|
|
30
|
+
const right = rightSpaceLength > 1;
|
|
31
|
+
if (left || right) {
|
|
32
|
+
const length = line.length;
|
|
33
|
+
const leftHashLength = leftHash.length;
|
|
34
|
+
const rightHashLength = rightHash.length;
|
|
35
|
+
const range = left ?
|
|
36
|
+
[
|
|
37
|
+
1,
|
|
38
|
+
leftHashLength + leftSpaceLength + 1
|
|
39
|
+
] :
|
|
40
|
+
[
|
|
41
|
+
length - trailSpaceLength - rightHashLength - rightSpaceLength,
|
|
42
|
+
rightSpaceLength + rightHashLength + 1
|
|
43
|
+
];
|
|
44
|
+
addErrorContext(
|
|
45
|
+
onError,
|
|
46
|
+
lineNumber,
|
|
47
|
+
line.trim(),
|
|
48
|
+
left,
|
|
49
|
+
right,
|
|
50
|
+
range,
|
|
51
|
+
{
|
|
52
|
+
"editColumn": 1,
|
|
53
|
+
"deleteCount": length,
|
|
54
|
+
"insertText": `${leftHash} ${content} ${rightHash}`
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
const { filterByTypes, getHeadingLevel, inHtmlFlow } =
|
|
8
|
+
require("../helpers/micromark.cjs");
|
|
9
|
+
|
|
10
|
+
const defaultLines = 1;
|
|
11
|
+
|
|
12
|
+
const getLinesFunction = (linesParam) => {
|
|
13
|
+
if (Array.isArray(linesParam)) {
|
|
14
|
+
const linesArray = new Array(6).fill(defaultLines);
|
|
15
|
+
for (const [ index, value ] of [ ...linesParam.entries() ].slice(0, 6)) {
|
|
16
|
+
linesArray[index] = value;
|
|
17
|
+
}
|
|
18
|
+
return (heading) => linesArray[getHeadingLevel(heading) - 1];
|
|
19
|
+
}
|
|
20
|
+
// Coerce linesParam to a number
|
|
21
|
+
const lines = (linesParam === undefined) ? defaultLines : Number(linesParam);
|
|
22
|
+
return () => lines;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getBlockQuote = (str, count) => (
|
|
26
|
+
(str || "")
|
|
27
|
+
.match(blockquotePrefixRe)[0]
|
|
28
|
+
.trimEnd()
|
|
29
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
30
|
+
.concat("\n")
|
|
31
|
+
.repeat(count)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
"names": [ "MD022", "blanks-around-headings" ],
|
|
36
|
+
"description": "Headings should be surrounded by blank lines",
|
|
37
|
+
"tags": [ "headings", "blank_lines" ],
|
|
38
|
+
"function": function MD022(params, onError) {
|
|
39
|
+
const getLinesAbove = getLinesFunction(params.config.lines_above);
|
|
40
|
+
const getLinesBelow = getLinesFunction(params.config.lines_below);
|
|
41
|
+
const { lines, parsers } = params;
|
|
42
|
+
const headings = filterByTypes(
|
|
43
|
+
parsers.micromark.tokens,
|
|
44
|
+
[ "atxHeading", "setextHeading" ]
|
|
45
|
+
).filter((heading) => !inHtmlFlow(heading));
|
|
46
|
+
for (const heading of headings) {
|
|
47
|
+
const { startLine, endLine } = heading;
|
|
48
|
+
const line = lines[startLine - 1].trim();
|
|
49
|
+
|
|
50
|
+
// Check lines above
|
|
51
|
+
const linesAbove = getLinesAbove(heading);
|
|
52
|
+
if (linesAbove >= 0) {
|
|
53
|
+
let actualAbove = 0;
|
|
54
|
+
for (
|
|
55
|
+
let i = 0;
|
|
56
|
+
(i < linesAbove) && isBlankLine(lines[startLine - 2 - i]);
|
|
57
|
+
i++
|
|
58
|
+
) {
|
|
59
|
+
actualAbove++;
|
|
60
|
+
}
|
|
61
|
+
addErrorDetailIf(
|
|
62
|
+
onError,
|
|
63
|
+
startLine,
|
|
64
|
+
linesAbove,
|
|
65
|
+
actualAbove,
|
|
66
|
+
"Above",
|
|
67
|
+
line,
|
|
68
|
+
null,
|
|
69
|
+
{
|
|
70
|
+
"insertText": getBlockQuote(
|
|
71
|
+
lines[startLine - 2],
|
|
72
|
+
linesAbove - actualAbove
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Check lines below
|
|
79
|
+
const linesBelow = getLinesBelow(heading);
|
|
80
|
+
if (linesBelow >= 0) {
|
|
81
|
+
let actualBelow = 0;
|
|
82
|
+
for (
|
|
83
|
+
let i = 0;
|
|
84
|
+
(i < linesBelow) && isBlankLine(lines[endLine + i]);
|
|
85
|
+
i++
|
|
86
|
+
) {
|
|
87
|
+
actualBelow++;
|
|
88
|
+
}
|
|
89
|
+
addErrorDetailIf(
|
|
90
|
+
onError,
|
|
91
|
+
startLine,
|
|
92
|
+
linesBelow,
|
|
93
|
+
actualBelow,
|
|
94
|
+
"Below",
|
|
95
|
+
line,
|
|
96
|
+
null,
|
|
97
|
+
{
|
|
98
|
+
"lineNumber": endLine + 1,
|
|
99
|
+
"insertText": getBlockQuote(
|
|
100
|
+
lines[endLine],
|
|
101
|
+
linesBelow - actualBelow
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, filterTokens } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
const spaceBeforeHeadingRe = /^(\s+|[>\s]+\s\s)[^>\s]/;
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
"names": [ "MD023", "heading-start-left" ],
|
|
11
|
+
"description": "Headings must start at the beginning of the line",
|
|
12
|
+
"tags": [ "headings", "spaces" ],
|
|
13
|
+
"function": function MD023(params, onError) {
|
|
14
|
+
filterTokens(params, "heading_open", function forToken(token) {
|
|
15
|
+
const { lineNumber, line } = token;
|
|
16
|
+
const match = line.match(spaceBeforeHeadingRe);
|
|
17
|
+
if (match) {
|
|
18
|
+
const [ prefixAndFirstChar, prefix ] = match;
|
|
19
|
+
let deleteCount = prefix.length;
|
|
20
|
+
const prefixLengthNoSpace = prefix.trimEnd().length;
|
|
21
|
+
if (prefixLengthNoSpace) {
|
|
22
|
+
deleteCount -= prefixLengthNoSpace - 1;
|
|
23
|
+
}
|
|
24
|
+
addErrorContext(
|
|
25
|
+
onError,
|
|
26
|
+
lineNumber,
|
|
27
|
+
line,
|
|
28
|
+
null,
|
|
29
|
+
null,
|
|
30
|
+
[ 1, prefixAndFirstChar.length ],
|
|
31
|
+
{
|
|
32
|
+
"editColumn": prefixLengthNoSpace + 1,
|
|
33
|
+
"deleteCount": deleteCount
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, forEachHeading } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD024", "no-duplicate-heading" ],
|
|
9
|
+
"description": "Multiple headings with the same content",
|
|
10
|
+
"tags": [ "headings" ],
|
|
11
|
+
"function": function MD024(params, onError) {
|
|
12
|
+
const siblingsOnly = !!params.config.siblings_only ||
|
|
13
|
+
!!params.config.allow_different_nesting || false;
|
|
14
|
+
const knownContents = [ null, [] ];
|
|
15
|
+
let lastLevel = 1;
|
|
16
|
+
let knownContent = knownContents[lastLevel];
|
|
17
|
+
forEachHeading(params, (heading, content) => {
|
|
18
|
+
if (siblingsOnly) {
|
|
19
|
+
const newLevel = heading.tag.slice(1);
|
|
20
|
+
while (lastLevel < newLevel) {
|
|
21
|
+
lastLevel++;
|
|
22
|
+
knownContents[lastLevel] = [];
|
|
23
|
+
}
|
|
24
|
+
while (lastLevel > newLevel) {
|
|
25
|
+
knownContents[lastLevel] = [];
|
|
26
|
+
lastLevel--;
|
|
27
|
+
}
|
|
28
|
+
knownContent = knownContents[newLevel];
|
|
29
|
+
}
|
|
30
|
+
if (knownContent.includes(content)) {
|
|
31
|
+
addErrorContext(onError, heading.lineNumber,
|
|
32
|
+
heading.line.trim());
|
|
33
|
+
} else {
|
|
34
|
+
knownContent.push(content);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, filterTokens, frontMatterHasTitle } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD025", "single-title", "single-h1" ],
|
|
10
|
+
"description": "Multiple top-level headings in the same document",
|
|
11
|
+
"tags": [ "headings" ],
|
|
12
|
+
"function": function MD025(params, onError) {
|
|
13
|
+
const level = Number(params.config.level || 1);
|
|
14
|
+
const tag = "h" + level;
|
|
15
|
+
const foundFrontMatterTitle =
|
|
16
|
+
frontMatterHasTitle(
|
|
17
|
+
params.frontMatterLines,
|
|
18
|
+
params.config.front_matter_title
|
|
19
|
+
);
|
|
20
|
+
let hasTopLevelHeading = false;
|
|
21
|
+
filterTokens(params, "heading_open", function forToken(token) {
|
|
22
|
+
if (token.tag === tag) {
|
|
23
|
+
if (hasTopLevelHeading || foundFrontMatterTitle) {
|
|
24
|
+
addErrorContext(onError, token.lineNumber,
|
|
25
|
+
token.line.trim());
|
|
26
|
+
} else if (token.lineNumber === 1) {
|
|
27
|
+
hasTopLevelHeading = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
|
|
6
|
+
endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers");
|
|
7
|
+
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"names": [ "MD026", "no-trailing-punctuation" ],
|
|
12
|
+
"description": "Trailing punctuation in heading",
|
|
13
|
+
"tags": [ "headings" ],
|
|
14
|
+
"function": function MD026(params, onError) {
|
|
15
|
+
let punctuation = params.config.punctuation;
|
|
16
|
+
punctuation = String(
|
|
17
|
+
(punctuation === undefined) ? allPunctuationNoQuestion : punctuation
|
|
18
|
+
);
|
|
19
|
+
const trailingPunctuationRe =
|
|
20
|
+
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
|
|
21
|
+
const headings = filterByTypes(
|
|
22
|
+
params.parsers.micromark.tokens,
|
|
23
|
+
[ "atxHeadingText", "setextHeadingText" ]
|
|
24
|
+
);
|
|
25
|
+
for (const heading of headings) {
|
|
26
|
+
const { endLine, startColumn, text } = heading;
|
|
27
|
+
const match = trailingPunctuationRe.exec(text);
|
|
28
|
+
if (
|
|
29
|
+
match &&
|
|
30
|
+
!endOfLineHtmlEntityRe.test(text) &&
|
|
31
|
+
!endOfLineGemojiCodeRe.test(text)
|
|
32
|
+
) {
|
|
33
|
+
const fullMatch = match[0];
|
|
34
|
+
const column = startColumn + match.index;
|
|
35
|
+
const length = fullMatch.length;
|
|
36
|
+
addError(
|
|
37
|
+
onError,
|
|
38
|
+
endLine,
|
|
39
|
+
`Punctuation: '${fullMatch}'`,
|
|
40
|
+
undefined,
|
|
41
|
+
[ column, length ],
|
|
42
|
+
{
|
|
43
|
+
"editColumn": column,
|
|
44
|
+
"deleteCount": length
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, newLineRe } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
const spaceAfterBlockQuoteRe = /^((?:\s*>)+)(\s{2,})\S/;
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
|
11
|
+
"description": "Multiple spaces after blockquote symbol",
|
|
12
|
+
"tags": [ "blockquote", "whitespace", "indentation" ],
|
|
13
|
+
"function": function MD027(params, onError) {
|
|
14
|
+
let blockquoteNesting = 0;
|
|
15
|
+
let listItemNesting = 0;
|
|
16
|
+
for (const token of params.parsers.markdownit.tokens) {
|
|
17
|
+
const { content, lineNumber, type } = token;
|
|
18
|
+
if (type === "blockquote_open") {
|
|
19
|
+
blockquoteNesting++;
|
|
20
|
+
} else if (type === "blockquote_close") {
|
|
21
|
+
blockquoteNesting--;
|
|
22
|
+
} else if (type === "list_item_open") {
|
|
23
|
+
listItemNesting++;
|
|
24
|
+
} else if (type === "list_item_close") {
|
|
25
|
+
listItemNesting--;
|
|
26
|
+
} else if ((type === "inline") && blockquoteNesting) {
|
|
27
|
+
const lineCount = content.split(newLineRe).length;
|
|
28
|
+
for (let i = 0; i < lineCount; i++) {
|
|
29
|
+
const line = params.lines[lineNumber + i - 1];
|
|
30
|
+
const match = line.match(spaceAfterBlockQuoteRe);
|
|
31
|
+
if (match) {
|
|
32
|
+
const [
|
|
33
|
+
fullMatch,
|
|
34
|
+
{ "length": blockquoteLength },
|
|
35
|
+
{ "length": spaceLength }
|
|
36
|
+
] = match;
|
|
37
|
+
if (!listItemNesting || (fullMatch[fullMatch.length - 1] === ">")) {
|
|
38
|
+
addErrorContext(
|
|
39
|
+
onError,
|
|
40
|
+
lineNumber + i,
|
|
41
|
+
line,
|
|
42
|
+
null,
|
|
43
|
+
null,
|
|
44
|
+
[ 1, fullMatch.length ],
|
|
45
|
+
{
|
|
46
|
+
"editColumn": blockquoteLength + 1,
|
|
47
|
+
"deleteCount": spaceLength - 1
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD028", "no-blanks-blockquote" ],
|
|
9
|
+
"description": "Blank line inside blockquote",
|
|
10
|
+
"tags": [ "blockquote", "whitespace" ],
|
|
11
|
+
"function": function MD028(params, onError) {
|
|
12
|
+
let prevToken = {};
|
|
13
|
+
let prevLineNumber = null;
|
|
14
|
+
for (const token of params.parsers.markdownit.tokens) {
|
|
15
|
+
if ((token.type === "blockquote_open") &&
|
|
16
|
+
(prevToken.type === "blockquote_close")) {
|
|
17
|
+
for (
|
|
18
|
+
let lineNumber = prevLineNumber;
|
|
19
|
+
lineNumber < token.lineNumber;
|
|
20
|
+
lineNumber++) {
|
|
21
|
+
addError(onError, lineNumber);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
prevToken = token;
|
|
25
|
+
if (token.type === "blockquote_open") {
|
|
26
|
+
prevLineNumber = token.map[1] + 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf, listItemMarkerRe, orderedListItemMarkerRe,
|
|
6
|
+
rangeFromRegExp } = require("../helpers");
|
|
7
|
+
const { flattenedLists } = require("./cache");
|
|
8
|
+
|
|
9
|
+
const listStyleExamples = {
|
|
10
|
+
"one": "1/1/1",
|
|
11
|
+
"ordered": "1/2/3",
|
|
12
|
+
"zero": "0/0/0"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
"names": [ "MD029", "ol-prefix" ],
|
|
17
|
+
"description": "Ordered list item prefix",
|
|
18
|
+
"tags": [ "ol" ],
|
|
19
|
+
"function": function MD029(params, onError) {
|
|
20
|
+
const style = String(params.config.style || "one_or_ordered");
|
|
21
|
+
const filteredLists = flattenedLists().filter((list) => !list.unordered);
|
|
22
|
+
for (const list of filteredLists) {
|
|
23
|
+
const { items } = list;
|
|
24
|
+
let current = 1;
|
|
25
|
+
let incrementing = false;
|
|
26
|
+
// Check for incrementing number pattern 1/2/3 or 0/1/2
|
|
27
|
+
if (items.length >= 2) {
|
|
28
|
+
const first = orderedListItemMarkerRe.exec(items[0].line);
|
|
29
|
+
const second = orderedListItemMarkerRe.exec(items[1].line);
|
|
30
|
+
if (first && second) {
|
|
31
|
+
const [ , firstNumber ] = first;
|
|
32
|
+
const [ , secondNumber ] = second;
|
|
33
|
+
if ((secondNumber !== "1") || (firstNumber === "0")) {
|
|
34
|
+
incrementing = true;
|
|
35
|
+
if (firstNumber === "0") {
|
|
36
|
+
current = 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Determine effective style
|
|
42
|
+
let listStyle = style;
|
|
43
|
+
if (listStyle === "one_or_ordered") {
|
|
44
|
+
listStyle = incrementing ? "ordered" : "one";
|
|
45
|
+
}
|
|
46
|
+
// Force expected value for 0/0/0 and 1/1/1 patterns
|
|
47
|
+
if (listStyle === "zero") {
|
|
48
|
+
current = 0;
|
|
49
|
+
} else if (listStyle === "one") {
|
|
50
|
+
current = 1;
|
|
51
|
+
}
|
|
52
|
+
// Validate each list item marker
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
const match = orderedListItemMarkerRe.exec(item.line);
|
|
55
|
+
if (match) {
|
|
56
|
+
addErrorDetailIf(onError, item.lineNumber,
|
|
57
|
+
String(current), match[1],
|
|
58
|
+
"Style: " + listStyleExamples[listStyle], null,
|
|
59
|
+
rangeFromRegExp(item.line, listItemMarkerRe));
|
|
60
|
+
if (listStyle === "ordered") {
|
|
61
|
+
current++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
+
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD030", "list-marker-space" ],
|
|
10
|
+
"description": "Spaces after list markers",
|
|
11
|
+
"tags": [ "ol", "ul", "whitespace" ],
|
|
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
|
+
const lists = filterByTypes(
|
|
18
|
+
params.parsers.micromark.tokens,
|
|
19
|
+
[ "listOrdered", "listUnordered" ]
|
|
20
|
+
);
|
|
21
|
+
for (const list of lists) {
|
|
22
|
+
const ordered = (list.type === "listOrdered");
|
|
23
|
+
const listItemPrefixes =
|
|
24
|
+
list.children.filter((token) => (token.type === "listItemPrefix"));
|
|
25
|
+
const allSingleLine =
|
|
26
|
+
(list.endLine - list.startLine + 1) === listItemPrefixes.length;
|
|
27
|
+
const expectedSpaces = ordered ?
|
|
28
|
+
(allSingleLine ? olSingle : olMulti) :
|
|
29
|
+
(allSingleLine ? ulSingle : ulMulti);
|
|
30
|
+
for (const listItemPrefix of listItemPrefixes) {
|
|
31
|
+
const range = [
|
|
32
|
+
listItemPrefix.startColumn,
|
|
33
|
+
listItemPrefix.endColumn - listItemPrefix.startColumn
|
|
34
|
+
];
|
|
35
|
+
const listItemPrefixWhitespaces = listItemPrefix.children.filter(
|
|
36
|
+
(token) => (token.type === "listItemPrefixWhitespace")
|
|
37
|
+
);
|
|
38
|
+
for (const listItemPrefixWhitespace of listItemPrefixWhitespaces) {
|
|
39
|
+
const { endColumn, startColumn, startLine } =
|
|
40
|
+
listItemPrefixWhitespace;
|
|
41
|
+
const actualSpaces = endColumn - startColumn;
|
|
42
|
+
const fixInfo = {
|
|
43
|
+
"editColumn": startColumn,
|
|
44
|
+
"deleteCount": actualSpaces,
|
|
45
|
+
"insertText": "".padEnd(expectedSpaces)
|
|
46
|
+
};
|
|
47
|
+
addErrorDetailIf(
|
|
48
|
+
onError,
|
|
49
|
+
startLine,
|
|
50
|
+
expectedSpaces,
|
|
51
|
+
actualSpaces,
|
|
52
|
+
null,
|
|
53
|
+
null,
|
|
54
|
+
range,
|
|
55
|
+
fixInfo
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|