markdownlint 0.20.0 → 0.20.4

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.
Files changed (64) hide show
  1. package/CONTRIBUTING.md +47 -47
  2. package/LICENSE +21 -21
  3. package/README.md +881 -868
  4. package/demo/markdownlint-browser.js +5438 -5306
  5. package/doc/CustomRules.md +313 -313
  6. package/doc/Rules.md +1847 -1795
  7. package/helpers/LICENSE +21 -21
  8. package/helpers/README.md +50 -50
  9. package/helpers/helpers.js +687 -627
  10. package/helpers/package.json +18 -18
  11. package/lib/cache.js +24 -24
  12. package/lib/markdownlint.d.ts +352 -352
  13. package/lib/markdownlint.js +1101 -1101
  14. package/lib/md001.js +22 -22
  15. package/lib/md002.js +22 -22
  16. package/lib/md003.js +42 -42
  17. package/lib/md004.js +43 -43
  18. package/lib/md005.js +69 -69
  19. package/lib/md006.js +34 -34
  20. package/lib/md007.js +47 -47
  21. package/lib/md009.js +77 -77
  22. package/lib/md010.js +38 -38
  23. package/lib/md011.js +38 -38
  24. package/lib/md012.js +32 -32
  25. package/lib/md013.js +99 -99
  26. package/lib/md014.js +53 -53
  27. package/lib/md018.js +34 -34
  28. package/lib/md019.js +39 -39
  29. package/lib/md020.js +62 -62
  30. package/lib/md021.js +60 -60
  31. package/lib/md022.js +56 -56
  32. package/lib/md023.js +38 -38
  33. package/lib/md024.js +38 -38
  34. package/lib/md025.js +32 -32
  35. package/lib/md026.js +40 -40
  36. package/lib/md027.js +56 -56
  37. package/lib/md028.js +38 -38
  38. package/lib/md029.js +66 -66
  39. package/lib/md030.js +50 -50
  40. package/lib/md031.js +39 -39
  41. package/lib/md032.js +50 -50
  42. package/lib/md033.js +45 -45
  43. package/lib/md034.js +61 -61
  44. package/lib/md035.js +21 -21
  45. package/lib/md036.js +56 -56
  46. package/lib/md037.js +150 -89
  47. package/lib/md038.js +68 -68
  48. package/lib/md039.js +64 -64
  49. package/lib/md040.js +18 -18
  50. package/lib/md041.js +31 -31
  51. package/lib/md042.js +41 -41
  52. package/lib/md043.js +45 -45
  53. package/lib/md044.js +77 -71
  54. package/lib/md045.js +18 -18
  55. package/lib/md046.js +32 -32
  56. package/lib/md047.js +28 -28
  57. package/lib/md048.js +29 -29
  58. package/lib/rules.js +61 -61
  59. package/package.json +73 -67
  60. package/schema/build-config-schema.js +405 -405
  61. package/schema/markdownlint-config-schema.json +1550 -1550
  62. package/style/all.json +5 -5
  63. package/style/cirosantilli.json +22 -22
  64. package/style/relaxed.json +13 -13
package/lib/md014.js CHANGED
@@ -1,53 +1,53 @@
1
- // @ts-check
2
-
3
- "use strict";
4
-
5
- const { addErrorContext, filterTokens } = require("../helpers");
6
-
7
- const dollarCommandRe = /^(\s*)(\$\s+)/;
8
-
9
- module.exports = {
10
- "names": [ "MD014", "commands-show-output" ],
11
- "description": "Dollar signs used before commands without showing output",
12
- "tags": [ "code" ],
13
- "function": function MD014(params, onError) {
14
- [ "code_block", "fence" ].forEach((type) => {
15
- filterTokens(params, type, (token) => {
16
- const margin = (token.type === "fence") ? 1 : 0;
17
- const dollarInstances = [];
18
- let allDollars = true;
19
- for (let i = token.map[0] + margin; i < token.map[1] - margin; i++) {
20
- const line = params.lines[i];
21
- const lineTrim = line.trim();
22
- if (lineTrim) {
23
- const match = dollarCommandRe.exec(line);
24
- if (match) {
25
- const column = match[1].length + 1;
26
- const length = match[2].length;
27
- dollarInstances.push([ i, lineTrim, column, length ]);
28
- } else {
29
- allDollars = false;
30
- }
31
- }
32
- }
33
- if (allDollars) {
34
- dollarInstances.forEach((instance) => {
35
- const [ i, lineTrim, column, length ] = instance;
36
- addErrorContext(
37
- onError,
38
- i + 1,
39
- lineTrim,
40
- null,
41
- null,
42
- [ column, length ],
43
- {
44
- "editColumn": column,
45
- "deleteCount": length
46
- }
47
- );
48
- });
49
- }
50
- });
51
- });
52
- }
53
- };
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext, filterTokens } = require("../helpers");
6
+
7
+ const dollarCommandRe = /^(\s*)(\$\s+)/;
8
+
9
+ module.exports = {
10
+ "names": [ "MD014", "commands-show-output" ],
11
+ "description": "Dollar signs used before commands without showing output",
12
+ "tags": [ "code" ],
13
+ "function": function MD014(params, onError) {
14
+ [ "code_block", "fence" ].forEach((type) => {
15
+ filterTokens(params, type, (token) => {
16
+ const margin = (token.type === "fence") ? 1 : 0;
17
+ const dollarInstances = [];
18
+ let allDollars = true;
19
+ for (let i = token.map[0] + margin; i < token.map[1] - margin; i++) {
20
+ const line = params.lines[i];
21
+ const lineTrim = line.trim();
22
+ if (lineTrim) {
23
+ const match = dollarCommandRe.exec(line);
24
+ if (match) {
25
+ const column = match[1].length + 1;
26
+ const length = match[2].length;
27
+ dollarInstances.push([ i, lineTrim, column, length ]);
28
+ } else {
29
+ allDollars = false;
30
+ }
31
+ }
32
+ }
33
+ if (allDollars) {
34
+ dollarInstances.forEach((instance) => {
35
+ const [ i, lineTrim, column, length ] = instance;
36
+ addErrorContext(
37
+ onError,
38
+ i + 1,
39
+ lineTrim,
40
+ null,
41
+ null,
42
+ [ column, length ],
43
+ {
44
+ "editColumn": column,
45
+ "deleteCount": length
46
+ }
47
+ );
48
+ });
49
+ }
50
+ });
51
+ });
52
+ }
53
+ };
package/lib/md018.js CHANGED
@@ -1,34 +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", "headers", "atx", "spaces" ],
12
- "function": function MD018(params, onError) {
13
- forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
14
- if (!inCode &&
15
- /^#+[^#\s]/.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
- };
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", "headers", "atx", "spaces" ],
12
+ "function": function MD018(params, onError) {
13
+ forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
14
+ if (!inCode &&
15
+ /^#+[^#\s]/.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
+ };
package/lib/md019.js CHANGED
@@ -1,39 +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", "headers", "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 = /^(#+)(\s{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
- };
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", "headers", "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 = /^(#+)(\s{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
+ };
package/lib/md020.js CHANGED
@@ -1,62 +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", "headers", "atx_closed", "spaces" ],
12
- "function": function MD020(params, onError) {
13
- forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
14
- if (!inCode) {
15
- const match =
16
- /^(#+)(\s*)([^#]*?[^#\\])(\s*)((?:\\#)?)(#+)(\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
- };
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", "headers", "atx_closed", "spaces" ],
12
+ "function": function MD020(params, onError) {
13
+ forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
14
+ if (!inCode) {
15
+ const match =
16
+ /^(#+)(\s*)([^#]*?[^#\\])(\s*)((?:\\#)?)(#+)(\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
+ };
package/lib/md021.js CHANGED
@@ -1,60 +1,60 @@
1
- // @ts-check
2
-
3
- "use strict";
4
-
5
- const { addErrorContext, filterTokens, headingStyleFor } =
6
- require("../helpers");
7
-
8
- module.exports = {
9
- "names": [ "MD021", "no-multiple-space-closed-atx" ],
10
- "description": "Multiple spaces inside hashes on closed atx style heading",
11
- "tags": [ "headings", "headers", "atx_closed", "spaces" ],
12
- "function": function MD021(params, onError) {
13
- filterTokens(params, "heading_open", (token) => {
14
- if (headingStyleFor(token) === "atx_closed") {
15
- const { line, lineNumber } = token;
16
- const match = /^(#+)(\s+)([^#]+?)(\s+)(#+)(\s*)$/.exec(line);
17
- if (match) {
18
- const [
19
- ,
20
- leftHash,
21
- { "length": leftSpaceLength },
22
- content,
23
- { "length": rightSpaceLength },
24
- rightHash,
25
- { "length": trailSpaceLength }
26
- ] = match;
27
- const left = leftSpaceLength > 1;
28
- const right = rightSpaceLength > 1;
29
- if (left || right) {
30
- const length = line.length;
31
- const leftHashLength = leftHash.length;
32
- const rightHashLength = rightHash.length;
33
- const range = left ?
34
- [
35
- 1,
36
- leftHashLength + leftSpaceLength + 1
37
- ] :
38
- [
39
- length - trailSpaceLength - rightHashLength - rightSpaceLength,
40
- rightSpaceLength + rightHashLength + 1
41
- ];
42
- addErrorContext(
43
- onError,
44
- lineNumber,
45
- line.trim(),
46
- left,
47
- right,
48
- range,
49
- {
50
- "editColumn": 1,
51
- "deleteCount": length,
52
- "insertText": `${leftHash} ${content} ${rightHash}`
53
- }
54
- );
55
- }
56
- }
57
- }
58
- });
59
- }
60
- };
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext, filterTokens, headingStyleFor } =
6
+ require("../helpers");
7
+
8
+ module.exports = {
9
+ "names": [ "MD021", "no-multiple-space-closed-atx" ],
10
+ "description": "Multiple spaces inside hashes on closed atx style heading",
11
+ "tags": [ "headings", "headers", "atx_closed", "spaces" ],
12
+ "function": function MD021(params, onError) {
13
+ filterTokens(params, "heading_open", (token) => {
14
+ if (headingStyleFor(token) === "atx_closed") {
15
+ const { line, lineNumber } = token;
16
+ const match = /^(#+)(\s+)([^#]+?)(\s+)(#+)(\s*)$/.exec(line);
17
+ if (match) {
18
+ const [
19
+ ,
20
+ leftHash,
21
+ { "length": leftSpaceLength },
22
+ content,
23
+ { "length": rightSpaceLength },
24
+ rightHash,
25
+ { "length": trailSpaceLength }
26
+ ] = match;
27
+ const left = leftSpaceLength > 1;
28
+ const right = rightSpaceLength > 1;
29
+ if (left || right) {
30
+ const length = line.length;
31
+ const leftHashLength = leftHash.length;
32
+ const rightHashLength = rightHash.length;
33
+ const range = left ?
34
+ [
35
+ 1,
36
+ leftHashLength + leftSpaceLength + 1
37
+ ] :
38
+ [
39
+ length - trailSpaceLength - rightHashLength - rightSpaceLength,
40
+ rightSpaceLength + rightHashLength + 1
41
+ ];
42
+ addErrorContext(
43
+ onError,
44
+ lineNumber,
45
+ line.trim(),
46
+ left,
47
+ right,
48
+ range,
49
+ {
50
+ "editColumn": 1,
51
+ "deleteCount": length,
52
+ "insertText": `${leftHash} ${content} ${rightHash}`
53
+ }
54
+ );
55
+ }
56
+ }
57
+ }
58
+ });
59
+ }
60
+ };
package/lib/md022.js CHANGED
@@ -1,56 +1,56 @@
1
- // @ts-check
2
-
3
- "use strict";
4
-
5
- const { addErrorDetailIf, filterTokens, isBlankLine } = require("../helpers");
6
-
7
- module.exports = {
8
- "names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
9
- "description": "Headings should be surrounded by blank lines",
10
- "tags": [ "headings", "headers", "blank_lines" ],
11
- "function": function MD022(params, onError) {
12
- let linesAbove = params.config.lines_above;
13
- linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove);
14
- let linesBelow = params.config.lines_below;
15
- linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow);
16
- const { lines } = params;
17
- filterTokens(params, "heading_open", (token) => {
18
- const [ topIndex, nextIndex ] = token.map;
19
- let actualAbove = 0;
20
- for (let i = 0; i < linesAbove; i++) {
21
- if (isBlankLine(lines[topIndex - i - 1])) {
22
- actualAbove++;
23
- }
24
- }
25
- addErrorDetailIf(
26
- onError,
27
- topIndex + 1,
28
- linesAbove,
29
- actualAbove,
30
- "Above",
31
- lines[topIndex].trim(),
32
- null,
33
- {
34
- "insertText": "".padEnd(linesAbove - actualAbove, "\n")
35
- });
36
- let actualBelow = 0;
37
- for (let i = 0; i < linesBelow; i++) {
38
- if (isBlankLine(lines[nextIndex + i])) {
39
- actualBelow++;
40
- }
41
- }
42
- addErrorDetailIf(
43
- onError,
44
- topIndex + 1,
45
- linesBelow,
46
- actualBelow,
47
- "Below",
48
- lines[topIndex].trim(),
49
- null,
50
- {
51
- "lineNumber": nextIndex + 1,
52
- "insertText": "".padEnd(linesBelow - actualBelow, "\n")
53
- });
54
- });
55
- }
56
- };
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf, filterTokens, isBlankLine } = require("../helpers");
6
+
7
+ module.exports = {
8
+ "names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
9
+ "description": "Headings should be surrounded by blank lines",
10
+ "tags": [ "headings", "headers", "blank_lines" ],
11
+ "function": function MD022(params, onError) {
12
+ let linesAbove = params.config.lines_above;
13
+ linesAbove = Number((linesAbove === undefined) ? 1 : linesAbove);
14
+ let linesBelow = params.config.lines_below;
15
+ linesBelow = Number((linesBelow === undefined) ? 1 : linesBelow);
16
+ const { lines } = params;
17
+ filterTokens(params, "heading_open", (token) => {
18
+ const [ topIndex, nextIndex ] = token.map;
19
+ let actualAbove = 0;
20
+ for (let i = 0; i < linesAbove; i++) {
21
+ if (isBlankLine(lines[topIndex - i - 1])) {
22
+ actualAbove++;
23
+ }
24
+ }
25
+ addErrorDetailIf(
26
+ onError,
27
+ topIndex + 1,
28
+ linesAbove,
29
+ actualAbove,
30
+ "Above",
31
+ lines[topIndex].trim(),
32
+ null,
33
+ {
34
+ "insertText": "".padEnd(linesAbove - actualAbove, "\n")
35
+ });
36
+ let actualBelow = 0;
37
+ for (let i = 0; i < linesBelow; i++) {
38
+ if (isBlankLine(lines[nextIndex + i])) {
39
+ actualBelow++;
40
+ }
41
+ }
42
+ addErrorDetailIf(
43
+ onError,
44
+ topIndex + 1,
45
+ linesBelow,
46
+ actualBelow,
47
+ "Below",
48
+ lines[topIndex].trim(),
49
+ null,
50
+ {
51
+ "lineNumber": nextIndex + 1,
52
+ "insertText": "".padEnd(linesBelow - actualBelow, "\n")
53
+ });
54
+ });
55
+ }
56
+ };