@alexlit/lint-kit 189.1.0 → 190.0.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 -1
- package/packages/config-eslint/package.json +4 -4
- package/packages/config-eslint/plugins/json.js +1 -1
- package/packages/config-eslint/plugins/prettier.js +1 -1
- package/packages/config-eslint/plugins/unicorn.js +2 -1
- package/packages/config-markdownlint/node_modules/ansi-regex/index.d.ts +33 -0
- package/packages/config-markdownlint/node_modules/ansi-regex/index.js +14 -0
- package/packages/config-markdownlint/node_modules/ansi-regex/license +9 -0
- package/packages/config-markdownlint/node_modules/ansi-regex/package.json +61 -0
- package/packages/config-markdownlint/node_modules/ansi-regex/readme.md +66 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +529 -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 +1112 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +194 -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 +2858 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +50 -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 +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +62 -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 +58 -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 +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +44 -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 +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +44 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +100 -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 +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +44 -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 +52 -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 +64 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +87 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +48 -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 +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +36 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +117 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +52 -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/doc/md055.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +48 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md059.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md060.md +130 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +29 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.cjs +695 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark-helpers.cjs +332 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.cjs +16 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.mjs +80 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +2417 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +8 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.mjs +14 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/defer-require.cjs +18 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.d.mts +1 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.mjs +3 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.d.mts +1 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.mjs +3 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.d.mts +1 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.mjs +3 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.d.mts +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.mjs +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownit.cjs +171 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.mts +615 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.mjs +1592 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.mjs +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.mjs +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.mjs +72 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.mjs +69 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.mjs +84 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.mjs +96 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.mjs +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.mjs +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.mjs +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.mjs +91 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.mjs +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.mjs +43 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.mjs +77 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.mjs +68 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.mjs +103 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.mjs +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.mjs +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.mjs +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.mjs +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.mjs +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.mjs +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.mjs +84 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.mjs +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.mjs +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.mjs +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.mjs +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.mjs +92 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.mjs +23 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.mjs +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.mjs +94 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.mjs +73 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.mjs +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.mjs +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.mjs +71 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.mjs +58 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.mjs +72 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.mjs +110 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.mjs +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.mjs +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.mjs +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.mjs +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.mjs +115 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.mjs +173 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.mjs +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.mjs +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.mjs +122 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.mjs +72 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.mjs +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.mjs +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md059.mjs +71 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md060.mjs +209 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-parse.mjs +337 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-types.d.mts +11 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-browser.mjs +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-node.mjs +11 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/parse-configuration.mjs +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.cjs +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.d.cts +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.mjs +122 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/types.d.mts +13 -0
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +120 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +349 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +310 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +5138 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +5143 -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 +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
- package/packages/config-markdownlint/node_modules/string-width/index.d.ts +39 -0
- package/packages/config-markdownlint/node_modules/string-width/index.js +203 -0
- package/packages/config-markdownlint/node_modules/string-width/license +9 -0
- package/packages/config-markdownlint/node_modules/string-width/package.json +65 -0
- package/packages/config-markdownlint/node_modules/string-width/readme.md +66 -0
- package/packages/config-markdownlint/node_modules/strip-ansi/index.d.ts +15 -0
- package/packages/config-markdownlint/node_modules/strip-ansi/index.js +19 -0
- package/packages/config-markdownlint/node_modules/strip-ansi/license +9 -0
- package/packages/config-markdownlint/node_modules/strip-ansi/package.json +59 -0
- package/packages/config-markdownlint/node_modules/strip-ansi/readme.md +37 -0
- package/packages/config-markdownlint/package.json +2 -2
- package/packages/config-stylelint/package.json +2 -2
- package/packages/config-stylelint/plugins/scss.js +1 -1
- package/packages/config-stylelint/plugins/selector-no-empty.js +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf, frontMatterHasTitle } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @type {import("markdownlint").Rule} */
|
|
8
|
+
export default {
|
|
9
|
+
"names": [ "MD001", "heading-increment" ],
|
|
10
|
+
"description": "Heading levels should only increment by one level at a time",
|
|
11
|
+
"tags": [ "headings" ],
|
|
12
|
+
"parser": "micromark",
|
|
13
|
+
"function": function MD001(params, onError) {
|
|
14
|
+
const hasTitle = frontMatterHasTitle(
|
|
15
|
+
params.frontMatterLines,
|
|
16
|
+
params.config.front_matter_title
|
|
17
|
+
);
|
|
18
|
+
let prevLevel = hasTitle ? 1 : Number.MAX_SAFE_INTEGER;
|
|
19
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
20
|
+
const level = getHeadingLevel(heading);
|
|
21
|
+
if (level > prevLevel) {
|
|
22
|
+
addErrorDetailIf(
|
|
23
|
+
onError,
|
|
24
|
+
heading.startLine,
|
|
25
|
+
`h${prevLevel + 1}`,
|
|
26
|
+
`h${level}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
prevLevel = level;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getHeadingLevel, getHeadingStyle } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @type {import("markdownlint").Rule} */
|
|
8
|
+
export default {
|
|
9
|
+
"names": [ "MD003", "heading-style" ],
|
|
10
|
+
"description": "Heading style",
|
|
11
|
+
"tags": [ "headings" ],
|
|
12
|
+
"parser": "micromark",
|
|
13
|
+
"function": function MD003(params, onError) {
|
|
14
|
+
let style = String(params.config.style || "consistent");
|
|
15
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
16
|
+
const styleForToken = getHeadingStyle(heading);
|
|
17
|
+
if (style === "consistent") {
|
|
18
|
+
style = styleForToken;
|
|
19
|
+
}
|
|
20
|
+
if (styleForToken !== style) {
|
|
21
|
+
const h12 = getHeadingLevel(heading) <= 2;
|
|
22
|
+
const setextWithAtx =
|
|
23
|
+
(style === "setext_with_atx") &&
|
|
24
|
+
((h12 && (styleForToken === "setext")) ||
|
|
25
|
+
(!h12 && (styleForToken === "atx")));
|
|
26
|
+
const setextWithAtxClosed =
|
|
27
|
+
(style === "setext_with_atx_closed") &&
|
|
28
|
+
((h12 && (styleForToken === "setext")) ||
|
|
29
|
+
(!h12 && (styleForToken === "atx_closed")));
|
|
30
|
+
if (!setextWithAtx && !setextWithAtxClosed) {
|
|
31
|
+
let expected = style;
|
|
32
|
+
if (style === "setext_with_atx") {
|
|
33
|
+
expected = h12 ? "setext" : "atx";
|
|
34
|
+
} else if (style === "setext_with_atx_closed") {
|
|
35
|
+
expected = h12 ? "setext" : "atx_closed";
|
|
36
|
+
}
|
|
37
|
+
addErrorDetailIf(
|
|
38
|
+
onError,
|
|
39
|
+
heading.startLine,
|
|
40
|
+
expected,
|
|
41
|
+
styleForToken
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getDescendantsByType, getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
const markerToStyle = (/** @type {string} */ marker) => (marker === "-") ? "dash" : ((marker === "+") ? "plus" : "asterisk");
|
|
8
|
+
const styleToMarker = (/** @type {string} */ style) => (style === "dash") ? "-" : ((style === "plus") ? "+" : "*");
|
|
9
|
+
const differentItemStyle = (/** @type {string} */ style) => (style === "dash") ? "plus" : ((style === "plus") ? "asterisk" : "dash");
|
|
10
|
+
const validStyles = new Set([
|
|
11
|
+
"asterisk",
|
|
12
|
+
"consistent",
|
|
13
|
+
"dash",
|
|
14
|
+
"plus",
|
|
15
|
+
"sublist"
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/** @type {import("markdownlint").Rule} */
|
|
19
|
+
export default {
|
|
20
|
+
"names": [ "MD004", "ul-style" ],
|
|
21
|
+
"description": "Unordered list style",
|
|
22
|
+
"tags": [ "bullet", "ul" ],
|
|
23
|
+
"parser": "micromark",
|
|
24
|
+
"function": function MD004(params, onError) {
|
|
25
|
+
const style = String(params.config.style || "consistent");
|
|
26
|
+
let expectedStyle = validStyles.has(style) ? style : "dash";
|
|
27
|
+
/** @type {("asterisk"|"dash"|"plus")[]} */
|
|
28
|
+
const nestingStyles = [];
|
|
29
|
+
for (const listUnordered of filterByTypesCached([ "listUnordered" ])) {
|
|
30
|
+
let nesting = 0;
|
|
31
|
+
if (style === "sublist") {
|
|
32
|
+
/** @type {import("markdownlint").MicromarkToken | null} */
|
|
33
|
+
let parent = listUnordered;
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
while ((parent = getParentOfType(parent, [ "listOrdered", "listUnordered" ]))) {
|
|
36
|
+
nesting++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const listItemMarkers = getDescendantsByType(listUnordered, [ "listItemPrefix", "listItemMarker" ]);
|
|
40
|
+
for (const listItemMarker of listItemMarkers) {
|
|
41
|
+
const itemStyle = markerToStyle(listItemMarker.text);
|
|
42
|
+
if (style === "sublist") {
|
|
43
|
+
if (!nestingStyles[nesting]) {
|
|
44
|
+
nestingStyles[nesting] =
|
|
45
|
+
(itemStyle === nestingStyles[nesting - 1]) ?
|
|
46
|
+
differentItemStyle(itemStyle) :
|
|
47
|
+
itemStyle;
|
|
48
|
+
}
|
|
49
|
+
expectedStyle = nestingStyles[nesting];
|
|
50
|
+
} else if (expectedStyle === "consistent") {
|
|
51
|
+
expectedStyle = itemStyle;
|
|
52
|
+
}
|
|
53
|
+
const column = listItemMarker.startColumn;
|
|
54
|
+
const length = listItemMarker.endColumn - listItemMarker.startColumn;
|
|
55
|
+
addErrorDetailIf(
|
|
56
|
+
onError,
|
|
57
|
+
listItemMarker.startLine,
|
|
58
|
+
expectedStyle,
|
|
59
|
+
itemStyle,
|
|
60
|
+
undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
[ column, length ],
|
|
63
|
+
{
|
|
64
|
+
"editColumn": column,
|
|
65
|
+
"deleteCount": length,
|
|
66
|
+
"insertText": styleToMarker(expectedStyle)
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addError, addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
5
|
+
|
|
6
|
+
/** @type {import("markdownlint").Rule} */
|
|
7
|
+
export default {
|
|
8
|
+
"names": [ "MD005", "list-indent" ],
|
|
9
|
+
"description": "Inconsistent indentation for list items at the same level",
|
|
10
|
+
"tags": [ "bullet", "ul", "indentation" ],
|
|
11
|
+
"parser": "micromark",
|
|
12
|
+
"function": function MD005(params, onError) {
|
|
13
|
+
for (const list of filterByTypesCached([ "listOrdered", "listUnordered" ])) {
|
|
14
|
+
const expectedIndent = list.startColumn - 1;
|
|
15
|
+
let expectedEnd = 0;
|
|
16
|
+
let endMatching = false;
|
|
17
|
+
const listItemPrefixes =
|
|
18
|
+
list.children.filter((token) => (token.type === "listItemPrefix"));
|
|
19
|
+
for (const listItemPrefix of listItemPrefixes) {
|
|
20
|
+
const lineNumber = listItemPrefix.startLine;
|
|
21
|
+
const actualIndent = listItemPrefix.startColumn - 1;
|
|
22
|
+
const range = [ 1, listItemPrefix.endColumn - 1 ];
|
|
23
|
+
if (list.type === "listUnordered") {
|
|
24
|
+
addErrorDetailIf(
|
|
25
|
+
onError,
|
|
26
|
+
lineNumber,
|
|
27
|
+
expectedIndent,
|
|
28
|
+
actualIndent,
|
|
29
|
+
undefined,
|
|
30
|
+
undefined,
|
|
31
|
+
range
|
|
32
|
+
// No fixInfo; MD007 handles this scenario better
|
|
33
|
+
);
|
|
34
|
+
} else {
|
|
35
|
+
const markerLength = listItemPrefix.text.trim().length;
|
|
36
|
+
const actualEnd = listItemPrefix.startColumn + markerLength - 1;
|
|
37
|
+
expectedEnd = expectedEnd || actualEnd;
|
|
38
|
+
if ((expectedIndent !== actualIndent) || endMatching) {
|
|
39
|
+
if (expectedEnd === actualEnd) {
|
|
40
|
+
endMatching = true;
|
|
41
|
+
} else {
|
|
42
|
+
const detail = endMatching ?
|
|
43
|
+
`Expected: (${expectedEnd}); Actual: (${actualEnd})` :
|
|
44
|
+
`Expected: ${expectedIndent}; Actual: ${actualIndent}`;
|
|
45
|
+
const expected = endMatching ?
|
|
46
|
+
expectedEnd - markerLength :
|
|
47
|
+
expectedIndent;
|
|
48
|
+
const actual = endMatching ?
|
|
49
|
+
actualEnd - markerLength :
|
|
50
|
+
actualIndent;
|
|
51
|
+
addError(
|
|
52
|
+
onError,
|
|
53
|
+
lineNumber,
|
|
54
|
+
detail,
|
|
55
|
+
undefined,
|
|
56
|
+
range,
|
|
57
|
+
{
|
|
58
|
+
"editColumn": Math.min(actual, expected) + 1,
|
|
59
|
+
"deleteCount": Math.max(actual - expected, 0),
|
|
60
|
+
"insertText": "".padEnd(Math.max(expected - actual, 0))
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @type {import("micromark-util-types").TokenType[]} */
|
|
8
|
+
const unorderedListTypes =
|
|
9
|
+
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ];
|
|
10
|
+
/** @type {import("micromark-util-types").TokenType[]} */
|
|
11
|
+
const unorderedParentTypes =
|
|
12
|
+
[ "blockQuote", "listOrdered", "listUnordered" ];
|
|
13
|
+
|
|
14
|
+
/** @type {import("markdownlint").Rule} */
|
|
15
|
+
export default {
|
|
16
|
+
"names": [ "MD007", "ul-indent" ],
|
|
17
|
+
"description": "Unordered list indentation",
|
|
18
|
+
"tags": [ "bullet", "ul", "indentation" ],
|
|
19
|
+
"parser": "micromark",
|
|
20
|
+
"function": function MD007(params, onError) {
|
|
21
|
+
const indent = Number(params.config.indent || 2);
|
|
22
|
+
const startIndented = !!params.config.start_indented;
|
|
23
|
+
const startIndent = Number(params.config.start_indent || indent);
|
|
24
|
+
const unorderedListNesting = new Map();
|
|
25
|
+
let lastBlockQuotePrefix = null;
|
|
26
|
+
const tokens = filterByTypesCached(unorderedListTypes);
|
|
27
|
+
for (const token of tokens) {
|
|
28
|
+
const { endColumn, parent, startColumn, startLine, type } = token;
|
|
29
|
+
if (type === "blockQuotePrefix") {
|
|
30
|
+
lastBlockQuotePrefix = token;
|
|
31
|
+
} else if (type === "listUnordered") {
|
|
32
|
+
let nesting = 0;
|
|
33
|
+
/** @type {import("markdownlint").MicromarkToken | null} */
|
|
34
|
+
let current = token;
|
|
35
|
+
while (
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
(current = getParentOfType(current, unorderedParentTypes))
|
|
38
|
+
) {
|
|
39
|
+
if (current.type === "listUnordered") {
|
|
40
|
+
nesting++;
|
|
41
|
+
// eslint-disable-next-line no-continue
|
|
42
|
+
continue;
|
|
43
|
+
} else if (current.type === "listOrdered") {
|
|
44
|
+
nesting = -1;
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (nesting >= 0) {
|
|
49
|
+
unorderedListNesting.set(token, nesting);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
// listItemPrefix
|
|
53
|
+
const nesting = unorderedListNesting.get(parent);
|
|
54
|
+
if (nesting !== undefined) {
|
|
55
|
+
// listItemPrefix for listUnordered
|
|
56
|
+
const baseIndent = (getParentOfType(token, [ "gfmFootnoteDefinition" ])) ? 4 : 0;
|
|
57
|
+
const expectedIndent =
|
|
58
|
+
baseIndent + (startIndented ? startIndent : 0) + (nesting * indent);
|
|
59
|
+
const blockQuoteAdjustment =
|
|
60
|
+
(lastBlockQuotePrefix?.endLine === startLine) ?
|
|
61
|
+
(lastBlockQuotePrefix.endColumn - 1) :
|
|
62
|
+
0;
|
|
63
|
+
const actualIndent = startColumn - 1 - blockQuoteAdjustment;
|
|
64
|
+
const range = [ 1, endColumn - 1 ];
|
|
65
|
+
const fixInfo = {
|
|
66
|
+
"editColumn": startColumn - actualIndent,
|
|
67
|
+
"deleteCount": Math.max(actualIndent - expectedIndent, 0),
|
|
68
|
+
"insertText": "".padEnd(Math.max(expectedIndent - actualIndent, 0))
|
|
69
|
+
};
|
|
70
|
+
addErrorDetailIf(
|
|
71
|
+
onError,
|
|
72
|
+
startLine,
|
|
73
|
+
expectedIndent,
|
|
74
|
+
actualIndent,
|
|
75
|
+
undefined,
|
|
76
|
+
undefined,
|
|
77
|
+
range,
|
|
78
|
+
fixInfo
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addError } from "../helpers/helpers.cjs";
|
|
4
|
+
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @type {import("markdownlint").Rule} */
|
|
8
|
+
export default {
|
|
9
|
+
"names": [ "MD009", "no-trailing-spaces" ],
|
|
10
|
+
"description": "Trailing spaces",
|
|
11
|
+
"tags": [ "whitespace" ],
|
|
12
|
+
"parser": "micromark",
|
|
13
|
+
"function": function MD009(params, onError) {
|
|
14
|
+
let brSpaces = params.config.br_spaces;
|
|
15
|
+
brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces);
|
|
16
|
+
const codeBlocks = params.config.code_blocks;
|
|
17
|
+
const includeCode = (codeBlocks === undefined) ? false : !!codeBlocks;
|
|
18
|
+
const listItemEmptyLines = !!params.config.list_item_empty_lines;
|
|
19
|
+
const strict = !!params.config.strict;
|
|
20
|
+
const codeBlockLineNumbers = new Set();
|
|
21
|
+
if (!includeCode) {
|
|
22
|
+
for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
|
|
23
|
+
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine + 1, codeBlock.endLine - 1);
|
|
24
|
+
}
|
|
25
|
+
for (const codeBlock of filterByTypesCached([ "codeIndented" ])) {
|
|
26
|
+
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const listItemLineNumbers = new Set();
|
|
30
|
+
if (listItemEmptyLines) {
|
|
31
|
+
for (const listBlock of filterByTypesCached([ "listOrdered", "listUnordered" ])) {
|
|
32
|
+
addRangeToSet(listItemLineNumbers, listBlock.startLine, listBlock.endLine);
|
|
33
|
+
let trailingIndent = true;
|
|
34
|
+
for (let i = listBlock.children.length - 1; i >= 0; i--) {
|
|
35
|
+
const child = listBlock.children[i];
|
|
36
|
+
switch (child.type) {
|
|
37
|
+
case "content":
|
|
38
|
+
trailingIndent = false;
|
|
39
|
+
break;
|
|
40
|
+
case "listItemIndent":
|
|
41
|
+
if (trailingIndent) {
|
|
42
|
+
listItemLineNumbers.delete(child.startLine);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "listItemPrefix":
|
|
46
|
+
trailingIndent = true;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const paragraphLineNumbers = new Set();
|
|
55
|
+
const codeInlineLineNumbers = new Set();
|
|
56
|
+
if (strict) {
|
|
57
|
+
for (const paragraph of filterByTypesCached([ "paragraph" ])) {
|
|
58
|
+
addRangeToSet(paragraphLineNumbers, paragraph.startLine, paragraph.endLine - 1);
|
|
59
|
+
}
|
|
60
|
+
for (const codeText of filterByTypesCached([ "codeText" ])) {
|
|
61
|
+
addRangeToSet(codeInlineLineNumbers, codeText.startLine, codeText.endLine - 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const expected = (brSpaces < 2) ? 0 : brSpaces;
|
|
65
|
+
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
|
66
|
+
const line = params.lines[lineIndex];
|
|
67
|
+
const lineNumber = lineIndex + 1;
|
|
68
|
+
const trailingSpaces = line.length - line.trimEnd().length;
|
|
69
|
+
if (
|
|
70
|
+
trailingSpaces &&
|
|
71
|
+
!codeBlockLineNumbers.has(lineNumber) &&
|
|
72
|
+
!listItemLineNumbers.has(lineNumber) &&
|
|
73
|
+
(
|
|
74
|
+
(expected !== trailingSpaces) ||
|
|
75
|
+
(strict &&
|
|
76
|
+
(!paragraphLineNumbers.has(lineNumber) ||
|
|
77
|
+
codeInlineLineNumbers.has(lineNumber)))
|
|
78
|
+
)
|
|
79
|
+
) {
|
|
80
|
+
const column = line.length - trailingSpaces + 1;
|
|
81
|
+
addError(
|
|
82
|
+
onError,
|
|
83
|
+
lineNumber,
|
|
84
|
+
"Expected: " + (expected === 0 ? "" : "0 or ") +
|
|
85
|
+
expected + "; Actual: " + trailingSpaces,
|
|
86
|
+
undefined,
|
|
87
|
+
[ column, trailingSpaces ],
|
|
88
|
+
{
|
|
89
|
+
"editColumn": column,
|
|
90
|
+
"deleteCount": trailingSpaces
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addError, hasOverlap } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
const tabRe = /\t+/g;
|
|
8
|
+
|
|
9
|
+
/** @type {import("markdownlint").Rule} */
|
|
10
|
+
export default {
|
|
11
|
+
"names": [ "MD010", "no-hard-tabs" ],
|
|
12
|
+
"description": "Hard tabs",
|
|
13
|
+
"tags": [ "whitespace", "hard_tab" ],
|
|
14
|
+
"parser": "micromark",
|
|
15
|
+
"function": function MD010(params, onError) {
|
|
16
|
+
const codeBlocks = params.config.code_blocks;
|
|
17
|
+
const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks;
|
|
18
|
+
const ignoreCodeLanguages = new Set(
|
|
19
|
+
(params.config.ignore_code_languages || [])
|
|
20
|
+
.map((/** @type {void} */ language) => String(language).toLowerCase())
|
|
21
|
+
);
|
|
22
|
+
const spacesPerTab = params.config.spaces_per_tab;
|
|
23
|
+
const spaceMultiplier = (spacesPerTab === undefined) ?
|
|
24
|
+
1 :
|
|
25
|
+
Math.max(0, Number(spacesPerTab));
|
|
26
|
+
/** @type {import("markdownlint").MicromarkTokenType[]} */
|
|
27
|
+
const exclusionTypes = [];
|
|
28
|
+
if (includeCode) {
|
|
29
|
+
if (ignoreCodeLanguages.size > 0) {
|
|
30
|
+
exclusionTypes.push("codeFenced");
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
exclusionTypes.push("codeFenced", "codeIndented", "codeText");
|
|
34
|
+
}
|
|
35
|
+
const codeTokens = filterByTypesCached(exclusionTypes).filter((token) => {
|
|
36
|
+
if ((token.type === "codeFenced") && (ignoreCodeLanguages.size > 0)) {
|
|
37
|
+
const fenceInfos = getDescendantsByType(token, [ "codeFencedFence", "codeFencedFenceInfo" ]);
|
|
38
|
+
return fenceInfos.every((fenceInfo) => ignoreCodeLanguages.has(fenceInfo.text.toLowerCase()));
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
const codeRanges = codeTokens.map((token) => {
|
|
43
|
+
const { type, startLine, startColumn, endLine, endColumn } = token;
|
|
44
|
+
const codeFenced = (type === "codeFenced");
|
|
45
|
+
return {
|
|
46
|
+
"startLine": startLine + (codeFenced ? 1 : 0),
|
|
47
|
+
"startColumn": codeFenced ? 0 : startColumn,
|
|
48
|
+
"endLine": endLine - (codeFenced ? 1 : 0),
|
|
49
|
+
"endColumn": codeFenced ? Number.MAX_SAFE_INTEGER : endColumn
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
|
53
|
+
const line = params.lines[lineIndex];
|
|
54
|
+
let match = null;
|
|
55
|
+
while ((match = tabRe.exec(line)) !== null) {
|
|
56
|
+
const lineNumber = lineIndex + 1;
|
|
57
|
+
const column = match.index + 1;
|
|
58
|
+
const length = match[0].length;
|
|
59
|
+
/** @type {import("../helpers/helpers.cjs").FileRange} */
|
|
60
|
+
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
|
|
61
|
+
if (!codeRanges.some((codeRange) => hasOverlap(codeRange, range))) {
|
|
62
|
+
addError(
|
|
63
|
+
onError,
|
|
64
|
+
lineNumber,
|
|
65
|
+
"Column: " + column,
|
|
66
|
+
undefined,
|
|
67
|
+
[ column, length ],
|
|
68
|
+
{
|
|
69
|
+
"editColumn": column,
|
|
70
|
+
"deleteCount": length,
|
|
71
|
+
"insertText": "".padEnd(length * spaceMultiplier)
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addError, hasOverlap } from "../helpers/helpers.cjs";
|
|
4
|
+
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @typedef {import("micromark-extension-math")} */
|
|
8
|
+
|
|
9
|
+
const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;
|
|
10
|
+
|
|
11
|
+
/** @type {import("markdownlint").Rule} */
|
|
12
|
+
export default {
|
|
13
|
+
"names": [ "MD011", "no-reversed-links" ],
|
|
14
|
+
"description": "Reversed link syntax",
|
|
15
|
+
"tags": [ "links" ],
|
|
16
|
+
"parser": "micromark",
|
|
17
|
+
"function": function MD011(params, onError) {
|
|
18
|
+
const ignoreBlockLineNumbers = new Set();
|
|
19
|
+
for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "mathFlow" ])) {
|
|
20
|
+
addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
|
|
21
|
+
}
|
|
22
|
+
const ignoreTexts = filterByTypesCached([ "codeText", "mathText" ]);
|
|
23
|
+
for (const [ lineIndex, line ] of params.lines.entries()) {
|
|
24
|
+
const lineNumber = lineIndex + 1;
|
|
25
|
+
if (!ignoreBlockLineNumbers.has(lineNumber)) {
|
|
26
|
+
let match = null;
|
|
27
|
+
while ((match = reversedLinkRe.exec(line)) !== null) {
|
|
28
|
+
const [ reversedLink, preChar, linkText, linkDestination ] = match;
|
|
29
|
+
if (
|
|
30
|
+
!linkText.endsWith("\\") &&
|
|
31
|
+
!linkDestination.endsWith("\\")
|
|
32
|
+
) {
|
|
33
|
+
const column = match.index + preChar.length + 1;
|
|
34
|
+
const length = match[0].length - preChar.length;
|
|
35
|
+
/** @type {import("../helpers/helpers.cjs").FileRange} */
|
|
36
|
+
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
|
|
37
|
+
if (!ignoreTexts.some((ignoreText) => hasOverlap(ignoreText, range))) {
|
|
38
|
+
addError(
|
|
39
|
+
onError,
|
|
40
|
+
lineNumber,
|
|
41
|
+
reversedLink.slice(preChar.length),
|
|
42
|
+
undefined,
|
|
43
|
+
[ column, length ],
|
|
44
|
+
{
|
|
45
|
+
"editColumn": column,
|
|
46
|
+
"deleteCount": length,
|
|
47
|
+
"insertText": `[${linkText}](${linkDestination})`
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
|
|
5
|
+
import { filterByTypesCached } from "./cache.mjs";
|
|
6
|
+
|
|
7
|
+
/** @type {import("markdownlint").Rule} */
|
|
8
|
+
export default {
|
|
9
|
+
"names": [ "MD012", "no-multiple-blanks" ],
|
|
10
|
+
"description": "Multiple consecutive blank lines",
|
|
11
|
+
"tags": [ "whitespace", "blank_lines" ],
|
|
12
|
+
"parser": "micromark",
|
|
13
|
+
"function": function MD012(params, onError) {
|
|
14
|
+
const maximum = Number(params.config.maximum || 1);
|
|
15
|
+
const { lines } = params;
|
|
16
|
+
const codeBlockLineNumbers = new Set();
|
|
17
|
+
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
18
|
+
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
19
|
+
}
|
|
20
|
+
let count = 0;
|
|
21
|
+
for (const [ lineIndex, line ] of lines.entries()) {
|
|
22
|
+
const inCode = codeBlockLineNumbers.has(lineIndex + 1);
|
|
23
|
+
count = (inCode || (line.trim().length > 0)) ? 0 : count + 1;
|
|
24
|
+
if (maximum < count) {
|
|
25
|
+
addErrorDetailIf(
|
|
26
|
+
onError,
|
|
27
|
+
lineIndex + 1,
|
|
28
|
+
maximum,
|
|
29
|
+
count,
|
|
30
|
+
undefined,
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
{
|
|
34
|
+
"deleteCount": -1
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
|
4
|
+
import { filterByTypesCached, getReferenceLinkImageData } from "./cache.mjs";
|
|
5
|
+
import { addRangeToSet, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
6
|
+
|
|
7
|
+
// Regular expression for a line that is not wrappable
|
|
8
|
+
const notWrappableRe = /^(?:[#>\s]*\s)?\S*$/;
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("micromark-extension-gfm-autolink-literal")} */
|
|
11
|
+
/** @typedef {import("micromark-extension-gfm-table")} */
|
|
12
|
+
|
|
13
|
+
/** @type {import("markdownlint").Rule} */
|
|
14
|
+
export default {
|
|
15
|
+
"names": [ "MD013", "line-length" ],
|
|
16
|
+
"description": "Line length",
|
|
17
|
+
"tags": [ "line_length" ],
|
|
18
|
+
"parser": "micromark",
|
|
19
|
+
"function": function MD013(params, onError) {
|
|
20
|
+
const lineLength = Number(params.config.line_length || 80);
|
|
21
|
+
const headingLineLength = Number(params.config.heading_line_length || lineLength);
|
|
22
|
+
const codeLineLength = Number(params.config.code_block_line_length || lineLength);
|
|
23
|
+
const strict = !!params.config.strict;
|
|
24
|
+
const stern = !!params.config.stern;
|
|
25
|
+
const codeBlocks = params.config.code_blocks;
|
|
26
|
+
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
|
27
|
+
const tables = params.config.tables;
|
|
28
|
+
const includeTables = (tables === undefined) ? true : !!tables;
|
|
29
|
+
const headings = params.config.headings;
|
|
30
|
+
const includeHeadings = (headings === undefined) ? true : !!headings;
|
|
31
|
+
const headingLineNumbers = new Set();
|
|
32
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
33
|
+
addRangeToSet(headingLineNumbers, heading.startLine, heading.endLine);
|
|
34
|
+
}
|
|
35
|
+
const codeBlockLineNumbers = new Set();
|
|
36
|
+
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
37
|
+
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
38
|
+
}
|
|
39
|
+
const tableLineNumbers = new Set();
|
|
40
|
+
for (const table of filterByTypesCached([ "table" ])) {
|
|
41
|
+
addRangeToSet(tableLineNumbers, table.startLine, table.endLine);
|
|
42
|
+
}
|
|
43
|
+
const linkLineNumbers = new Set();
|
|
44
|
+
for (const link of filterByTypesCached([ "autolink", "image", "link", "literalAutolink" ])) {
|
|
45
|
+
addRangeToSet(linkLineNumbers, link.startLine, link.endLine);
|
|
46
|
+
}
|
|
47
|
+
const paragraphDataLineNumbers = new Set();
|
|
48
|
+
for (const paragraph of filterByTypesCached([ "paragraph" ])) {
|
|
49
|
+
for (const data of getDescendantsByType(paragraph, [ "data" ])) {
|
|
50
|
+
addRangeToSet(paragraphDataLineNumbers, data.startLine, data.endLine);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const linkOnlyLineNumbers = new Set();
|
|
54
|
+
for (const lineNumber of linkLineNumbers) {
|
|
55
|
+
if (!paragraphDataLineNumbers.has(lineNumber)) {
|
|
56
|
+
linkOnlyLineNumbers.add(lineNumber);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const definitionLineIndices = new Set(getReferenceLinkImageData().definitionLineIndices);
|
|
60
|
+
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
|
61
|
+
const line = params.lines[lineIndex];
|
|
62
|
+
const lineNumber = lineIndex + 1;
|
|
63
|
+
const isHeading = headingLineNumbers.has(lineNumber);
|
|
64
|
+
const inCode = codeBlockLineNumbers.has(lineNumber);
|
|
65
|
+
const inTable = tableLineNumbers.has(lineNumber);
|
|
66
|
+
const maxLength = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength);
|
|
67
|
+
// If not strict/stern, the last run of non-whitespace is allowed to go
|
|
68
|
+
// beyond the limit as long as it begins within the limit
|
|
69
|
+
const text = (strict || stern) ? line : line.replace(/\S*$/u, "#");
|
|
70
|
+
if ((maxLength > 0) &&
|
|
71
|
+
(includeCodeBlocks || !inCode) &&
|
|
72
|
+
(includeTables || !inTable) &&
|
|
73
|
+
(includeHeadings || !isHeading) &&
|
|
74
|
+
!definitionLineIndices.has(lineIndex) &&
|
|
75
|
+
(strict ||
|
|
76
|
+
(!(stern && notWrappableRe.test(line)) &&
|
|
77
|
+
!linkOnlyLineNumbers.has(lineNumber))) &&
|
|
78
|
+
(text.length > maxLength)) {
|
|
79
|
+
addErrorDetailIf(
|
|
80
|
+
onError,
|
|
81
|
+
lineNumber,
|
|
82
|
+
maxLength,
|
|
83
|
+
line.length,
|
|
84
|
+
undefined,
|
|
85
|
+
undefined,
|
|
86
|
+
[ maxLength + 1, line.length - maxLength ]
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|