markdownlint 0.26.1 → 0.27.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.
Files changed (85) hide show
  1. package/CONTRIBUTING.md +81 -59
  2. package/README.md +424 -301
  3. package/demo/markdownlint-browser.js +445 -210
  4. package/doc/CustomRules.md +101 -50
  5. package/doc/Prettier.md +14 -10
  6. package/doc/ReleaseProcess.md +20 -0
  7. package/doc/Rules.md +464 -296
  8. package/doc/md001.md +37 -0
  9. package/doc/md002.md +37 -0
  10. package/doc/md003.md +59 -0
  11. package/doc/md004.md +49 -0
  12. package/doc/md005.md +53 -0
  13. package/doc/md006.md +46 -0
  14. package/doc/md007.md +55 -0
  15. package/doc/md009.md +51 -0
  16. package/doc/md010.md +56 -0
  17. package/doc/md011.md +30 -0
  18. package/doc/md012.md +38 -0
  19. package/doc/md013.md +60 -0
  20. package/doc/md014.md +54 -0
  21. package/doc/md018.md +27 -0
  22. package/doc/md019.md +28 -0
  23. package/doc/md020.md +29 -0
  24. package/doc/md021.md +31 -0
  25. package/doc/md022.md +46 -0
  26. package/doc/md023.md +26 -0
  27. package/doc/md024.md +47 -0
  28. package/doc/md025.md +49 -0
  29. package/doc/md026.md +41 -0
  30. package/doc/md027.md +24 -0
  31. package/doc/md028.md +40 -0
  32. package/doc/md029.md +98 -0
  33. package/doc/md030.md +82 -0
  34. package/doc/md031.md +50 -0
  35. package/doc/md032.md +38 -0
  36. package/doc/md033.md +27 -0
  37. package/doc/md034.md +44 -0
  38. package/doc/md035.md +42 -0
  39. package/doc/md036.md +45 -0
  40. package/doc/md037.md +37 -0
  41. package/doc/md038.md +40 -0
  42. package/doc/md039.md +21 -0
  43. package/doc/md040.md +52 -0
  44. package/doc/md041.md +49 -0
  45. package/doc/md042.md +32 -0
  46. package/doc/md043.md +72 -0
  47. package/doc/md044.md +35 -0
  48. package/doc/md045.md +34 -0
  49. package/doc/md046.md +40 -0
  50. package/doc/md047.md +34 -0
  51. package/doc/md048.md +41 -0
  52. package/doc/md049.md +32 -0
  53. package/doc/md050.md +32 -0
  54. package/doc/md051.md +50 -0
  55. package/doc/md052.md +33 -0
  56. package/doc/md053.md +38 -0
  57. package/helpers/README.md +35 -15
  58. package/helpers/helpers.js +234 -70
  59. package/helpers/package.json +2 -2
  60. package/lib/constants.js +8 -1
  61. package/lib/markdownlint.js +7 -12
  62. package/lib/md011.js +2 -2
  63. package/lib/md013.js +7 -6
  64. package/lib/md019.js +1 -1
  65. package/lib/md022.js +15 -3
  66. package/lib/md023.js +1 -1
  67. package/lib/md026.js +1 -1
  68. package/lib/md032.js +4 -5
  69. package/lib/md033.js +16 -5
  70. package/lib/md034.js +70 -45
  71. package/lib/md035.js +1 -1
  72. package/lib/md037.js +25 -22
  73. package/lib/md038.js +1 -1
  74. package/lib/md039.js +1 -1
  75. package/lib/md040.js +21 -2
  76. package/lib/md043.js +4 -2
  77. package/lib/md044.js +4 -3
  78. package/lib/md051.js +43 -11
  79. package/lib/md053.js +18 -11
  80. package/lib/rules.js +1 -1
  81. package/package.json +31 -21
  82. package/schema/.markdownlint.jsonc +16 -4
  83. package/schema/.markdownlint.yaml +13 -3
  84. package/schema/markdownlint-config-schema.json +45 -5
  85. package/style/prettier.json +26 -0
package/lib/md051.js CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { addError, escapeForRegExp, filterTokens, forEachInlineChild,
6
- forEachHeading, htmlElementRe } = require("../helpers");
5
+ const { addError, addErrorDetailIf, escapeForRegExp, filterTokens,
6
+ forEachInlineChild, forEachHeading, htmlElementRe } = require("../helpers");
7
7
 
8
8
  // Regular expression for identifying HTML anchor names
9
- const identifierRe = /(?:id|name)\s*=\s*['"]?([^'"\s>]+)/iu;
9
+ const idRe = /\sid\s*=\s*['"]?([^'"\s>]+)/iu;
10
+ const nameRe = /\sname\s*=\s*['"]?([^'"\s>]+)/iu;
10
11
 
11
12
  /**
12
13
  * Converts a Markdown heading into an HTML fragment according to the rules
@@ -55,11 +56,10 @@ module.exports = {
55
56
  let match = null;
56
57
  while ((match = htmlElementRe.exec(token.content)) !== null) {
57
58
  const [ tag, , element ] = match;
58
- if (element.toLowerCase() === "a") {
59
- const idMatch = identifierRe.exec(tag);
60
- if (idMatch) {
61
- fragments.set(`#${idMatch[1]}`, 0);
62
- }
59
+ const anchorMatch = idRe.exec(tag) ||
60
+ (element.toLowerCase() === "a" && nameRe.exec(tag));
61
+ if (anchorMatch) {
62
+ fragments.set(`#${anchorMatch[1]}`, 0);
63
63
  }
64
64
  }
65
65
  };
@@ -73,14 +73,46 @@ module.exports = {
73
73
  if (id && (id.length > 1) && (id[0] === "#") && !fragments.has(id)) {
74
74
  let context = id;
75
75
  let range = null;
76
+ let fixInfo = null;
76
77
  const match = line.match(
77
78
  new RegExp(`\\[.*?\\]\\(${escapeForRegExp(context)}\\)`)
78
79
  );
79
80
  if (match) {
80
- context = match[0];
81
- range = [ match.index + 1, match[0].length ];
81
+ [ context ] = match;
82
+ const index = match.index;
83
+ const length = context.length;
84
+ range = [ index + 1, length ];
85
+ fixInfo = {
86
+ "editColumn": index + (length - id.length),
87
+ "deleteCount": id.length,
88
+ "insertText": null
89
+ };
90
+ }
91
+ const idLower = id.toLowerCase();
92
+ const mixedCaseKey = [ ...fragments.keys() ]
93
+ .find((key) => idLower === key.toLowerCase());
94
+ if (mixedCaseKey) {
95
+ (fixInfo || {}).insertText = mixedCaseKey;
96
+ addErrorDetailIf(
97
+ onError,
98
+ lineNumber,
99
+ mixedCaseKey,
100
+ id,
101
+ undefined,
102
+ context,
103
+ range,
104
+ fixInfo
105
+ );
106
+ } else {
107
+ addError(
108
+ onError,
109
+ lineNumber,
110
+ undefined,
111
+ context,
112
+ // @ts-ignore
113
+ range
114
+ );
82
115
  }
83
- addError(onError, lineNumber, undefined, context, range);
84
116
  }
85
117
  });
86
118
  }
package/lib/md053.js CHANGED
@@ -11,7 +11,8 @@ module.exports = {
11
11
  "description": "Link and image reference definitions should be needed",
12
12
  "tags": [ "images", "links" ],
13
13
  "function": function MD053(params, onError) {
14
- const { lines } = params;
14
+ const ignored = new Set(params.config.ignored_definitions || [ "//" ]);
15
+ const lines = params.lines;
15
16
  const { references, shortcuts, definitions, duplicateDefinitions } =
16
17
  referenceLinkImageData();
17
18
  const singleLineDefinition = (line) => (
@@ -23,7 +24,11 @@ module.exports = {
23
24
  // Look for unused link references (unreferenced by any link/image)
24
25
  for (const definition of definitions.entries()) {
25
26
  const [ label, lineIndex ] = definition;
26
- if (!references.has(label) && !shortcuts.has(label)) {
27
+ if (
28
+ !ignored.has(label) &&
29
+ !references.has(label) &&
30
+ !shortcuts.has(label)
31
+ ) {
27
32
  const line = lines[lineIndex];
28
33
  addError(
29
34
  onError,
@@ -38,15 +43,17 @@ module.exports = {
38
43
  // Look for duplicate link references (defined more than once)
39
44
  for (const duplicateDefinition of duplicateDefinitions) {
40
45
  const [ label, lineIndex ] = duplicateDefinition;
41
- const line = lines[lineIndex];
42
- addError(
43
- onError,
44
- lineIndex + 1,
45
- `Duplicate link or image reference definition: "${label}"`,
46
- ellipsify(line),
47
- [ 1, line.length ],
48
- singleLineDefinition(line) ? deleteFixInfo : 0
49
- );
46
+ if (!ignored.has(label)) {
47
+ const line = lines[lineIndex];
48
+ addError(
49
+ onError,
50
+ lineIndex + 1,
51
+ `Duplicate link or image reference definition: "${label}"`,
52
+ ellipsify(line),
53
+ [ 1, line.length ],
54
+ singleLineDefinition(line) ? deleteFixInfo : 0
55
+ );
56
+ }
50
57
  }
51
58
  }
52
59
  };
package/lib/rules.js CHANGED
@@ -58,6 +58,6 @@ for (const rule of rules) {
58
58
  const name = rule.names[0].toLowerCase();
59
59
  // eslint-disable-next-line dot-notation
60
60
  rule["information"] =
61
- new URL(`${homepage}/blob/v${version}/doc/Rules.md#${name}`);
61
+ new URL(`${homepage}/blob/v${version}/doc/${name}.md`);
62
62
  }
63
63
  module.exports = rules;
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "markdownlint",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "description": "A Node.js style checker and lint tool for Markdown/CommonMark files.",
5
5
  "type": "commonjs",
6
6
  "main": "./lib/markdownlint.js",
7
7
  "exports": {
8
8
  ".": "./lib/markdownlint.js",
9
- "./helpers": "./helpers/helpers.js"
9
+ "./helpers": "./helpers/helpers.js",
10
+ "./style/all": "./style/all.json",
11
+ "./style/cirosantilli": "./style/cirosantilli.json",
12
+ "./style/prettier": "./style/prettier.json",
13
+ "./style/relaxed": "./style/relaxed.json"
10
14
  },
11
15
  "types": "./lib/markdownlint.d.ts",
12
16
  "author": "David Anson (https://dlaa.me/)",
@@ -23,24 +27,28 @@
23
27
  "build-config-schema": "node schema/build-config-schema.js",
24
28
  "build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --resolveJsonModule --target es2015 lib/markdownlint.js && node scripts delete 'lib/{c,md,r}*.d.ts' 'helpers/*.d.ts'",
25
29
  "build-demo": "node scripts copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && cd demo && webpack --no-stats",
30
+ "build-docs": "node doc-build/build-rules.mjs",
26
31
  "build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
27
- "ci": "npm-run-all --continue-on-error --parallel build-config lint serial-declaration-demo test-cover && git diff --exit-code",
32
+ "ci": "npm-run-all --continue-on-error --parallel lint serial-config-docs serial-declaration-demo test-cover && git diff --exit-code",
33
+ "clone-test-repos-apache-airflow": "cd test-repos && git clone https://github.com/apache/airflow apache-airflow --depth 1 --no-tags --quiet",
28
34
  "clone-test-repos-dotnet-docs": "cd test-repos && git clone https://github.com/dotnet/docs dotnet-docs --depth 1 --no-tags --quiet",
35
+ "clone-test-repos-electron-electron": "cd test-repos && git clone https://github.com/electron/electron electron-electron --depth 1 --no-tags --quiet",
29
36
  "clone-test-repos-eslint-eslint": "cd test-repos && git clone https://github.com/eslint/eslint eslint-eslint --depth 1 --no-tags --quiet",
37
+ "clone-test-repos-mdn-content": "cd test-repos && git clone https://github.com/mdn/content mdn-content --depth 1 --no-tags --quiet",
30
38
  "clone-test-repos-mkdocs-mkdocs": "cd test-repos && git clone https://github.com/mkdocs/mkdocs mkdocs-mkdocs --depth 1 --no-tags --quiet",
31
39
  "clone-test-repos-mochajs-mocha": "cd test-repos && git clone https://github.com/mochajs/mocha mochajs-mocha --depth 1 --no-tags --quiet",
32
40
  "clone-test-repos-pi-hole-docs": "cd test-repos && git clone https://github.com/pi-hole/docs pi-hole-docs --depth 1 --no-tags --quiet",
33
41
  "clone-test-repos-v8-v8-dev": "cd test-repos && git clone https://github.com/v8/v8.dev v8-v8-dev --depth 1 --no-tags --quiet",
34
42
  "clone-test-repos-webhintio-hint": "cd test-repos && git clone https://github.com/webhintio/hint webhintio-hint --depth 1 --no-tags --quiet",
35
43
  "clone-test-repos-webpack-webpack-js-org": "cd test-repos && git clone https://github.com/webpack/webpack.js.org webpack-webpack-js-org --depth 1 --no-tags --quiet",
36
- "clone-test-repos": "mkdir test-repos && cd test-repos && npm run clone-test-repos-eslint-eslint && npm run clone-test-repos-mkdocs-mkdocs && npm run clone-test-repos-mochajs-mocha && npm run clone-test-repos-pi-hole-docs && npm run clone-test-repos-webhintio-hint && npm run clone-test-repos-webpack-webpack-js-org",
37
- "clone-test-repos-large": "npm run clone-test-repos && cd test-repos && npm run clone-test-repos-dotnet-docs && npm run clone-test-repos-v8-v8-dev",
44
+ "clone-test-repos": "mkdir test-repos && cd test-repos && npm run clone-test-repos-apache-airflow && npm run clone-test-repos-dotnet-docs && npm run clone-test-repos-electron-electron && npm run clone-test-repos-eslint-eslint && npm run clone-test-repos-mdn-content && npm run clone-test-repos-mkdocs-mkdocs && npm run clone-test-repos-mochajs-mocha && npm run clone-test-repos-pi-hole-docs && npm run clone-test-repos-v8-v8-dev && npm run clone-test-repos-webhintio-hint && npm run clone-test-repos-webpack-webpack-js-org",
38
45
  "declaration": "npm run build-declaration && npm run test-declaration",
39
46
  "example": "cd example && node standalone.js && grunt markdownlint --force && gulp markdownlint",
40
47
  "docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm install",
41
48
  "docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm run upgrade",
42
- "lint": "eslint --max-warnings 0 .",
49
+ "lint": "eslint --ext .js,.mjs --max-warnings 0 .",
43
50
  "lint-test-repos": "ava --timeout=5m test/markdownlint-test-repos.js",
51
+ "serial-config-docs": "npm run build-config && npm run build-docs",
44
52
  "serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration",
45
53
  "test": "ava test/markdownlint-test.js test/markdownlint-test-config.js test/markdownlint-test-custom-rules.js test/markdownlint-test-helpers.js test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js",
46
54
  "test-cover": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 npm test",
@@ -50,35 +58,37 @@
50
58
  "upgrade": "npx --yes npm-check-updates --upgrade"
51
59
  },
52
60
  "engines": {
53
- "node": ">=14"
61
+ "node": ">=14.18.0"
54
62
  },
55
63
  "dependencies": {
56
64
  "markdown-it": "13.0.1"
57
65
  },
58
66
  "devDependencies": {
59
- "ava": "4.3.0",
60
- "c8": "7.11.3",
61
- "eslint": "8.18.0",
67
+ "ava": "5.1.0",
68
+ "c8": "7.12.0",
69
+ "eslint": "8.30.0",
62
70
  "eslint-plugin-es": "4.1.0",
63
- "eslint-plugin-jsdoc": "39.3.3",
64
- "eslint-plugin-node": "11.1.0",
65
- "eslint-plugin-unicorn": "42.0.0",
66
- "globby": "13.1.2",
71
+ "eslint-plugin-jsdoc": "39.6.4",
72
+ "eslint-plugin-n": "15.6.0",
73
+ "eslint-plugin-regexp": "1.11.0",
74
+ "eslint-plugin-unicorn": "45.0.2",
75
+ "globby": "13.1.3",
67
76
  "js-yaml": "4.1.0",
77
+ "markdown-it-footnote": "3.0.3",
68
78
  "markdown-it-for-inline": "0.1.1",
69
79
  "markdown-it-sub": "1.0.0",
70
80
  "markdown-it-sup": "1.0.0",
71
81
  "markdown-it-texmath": "1.0.0",
72
- "markdownlint-rule-github-internal-links": "0.1.0",
73
- "markdownlint-rule-helpers": "0.16.0",
82
+ "markdownlint-rule-helpers": "0.17.2",
74
83
  "npm-run-all": "4.1.5",
75
- "strip-json-comments": "4.0.0",
84
+ "strip-json-comments": "5.0.0",
85
+ "terser-webpack-plugin": "5.3.6",
76
86
  "toml": "3.0.0",
77
- "ts-loader": "9.3.0",
87
+ "ts-loader": "9.4.2",
78
88
  "tv4": "1.3.0",
79
- "typescript": "4.7.4",
80
- "webpack": "5.73.0",
81
- "webpack-cli": "4.10.0"
89
+ "typescript": "4.9.4",
90
+ "webpack": "5.75.0",
91
+ "webpack-cli": "5.0.1"
82
92
  },
83
93
  "keywords": [
84
94
  "markdown",
@@ -139,7 +139,7 @@
139
139
 
140
140
  // MD026/no-trailing-punctuation - Trailing punctuation in heading
141
141
  "MD026": {
142
- // Punctuation characters
142
+ // Punctuation characters not allowed at end of headings
143
143
  "punctuation": ".,;:!。,;:!"
144
144
  },
145
145
 
@@ -207,7 +207,12 @@
207
207
  "MD039": true,
208
208
 
209
209
  // MD040/fenced-code-language - Fenced code blocks should have a language specified
210
- "MD040": true,
210
+ "MD040": {
211
+ // List of languages
212
+ "allowed_languages": [],
213
+ // Require language only
214
+ "language_only": false
215
+ },
211
216
 
212
217
  // MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading
213
218
  "MD041": {
@@ -225,7 +230,9 @@
225
230
  // List of headings
226
231
  "headings": [],
227
232
  // List of headings
228
- "headers": []
233
+ "headers": [],
234
+ // Match case of headings
235
+ "match_case": false
229
236
  },
230
237
 
231
238
  // MD044/proper-names - Proper names should have the correct capitalization
@@ -275,5 +282,10 @@
275
282
  "MD052": true,
276
283
 
277
284
  // MD053/link-image-reference-definitions - Link and image reference definitions should be needed
278
- "MD053": true
285
+ "MD053": {
286
+ // Ignored definitions
287
+ "ignored_definitions": [
288
+ "//"
289
+ ]
290
+ }
279
291
  }
@@ -127,7 +127,7 @@ MD025:
127
127
 
128
128
  # MD026/no-trailing-punctuation - Trailing punctuation in heading
129
129
  MD026:
130
- # Punctuation characters
130
+ # Punctuation characters not allowed at end of headings
131
131
  punctuation: ".,;:!。,;:!"
132
132
 
133
133
  # MD027/no-multiple-space-blockquote - Multiple spaces after blockquote symbol
@@ -188,7 +188,11 @@ MD038: true
188
188
  MD039: true
189
189
 
190
190
  # MD040/fenced-code-language - Fenced code blocks should have a language specified
191
- MD040: true
191
+ MD040:
192
+ # List of languages
193
+ allowed_languages: []
194
+ # Require language only
195
+ language_only: false
192
196
 
193
197
  # MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading
194
198
  MD041:
@@ -206,6 +210,8 @@ MD043:
206
210
  headings: []
207
211
  # List of headings
208
212
  headers: []
213
+ # Match case of headings
214
+ match_case: false
209
215
 
210
216
  # MD044/proper-names - Proper names should have the correct capitalization
211
217
  MD044:
@@ -249,4 +255,8 @@ MD051: true
249
255
  MD052: true
250
256
 
251
257
  # MD053/link-image-reference-definitions - Link and image reference definitions should be needed
252
- MD053: true
258
+ MD053:
259
+ # Ignored definitions
260
+ ignored_definitions: [
261
+ "//"
262
+ ]
@@ -456,7 +456,7 @@
456
456
  "default": true,
457
457
  "properties": {
458
458
  "punctuation": {
459
- "description": "Punctuation characters",
459
+ "description": "Punctuation characters not allowed at end of headings",
460
460
  "type": "string",
461
461
  "default": ".,;:!。,;:!"
462
462
  }
@@ -669,8 +669,27 @@
669
669
  },
670
670
  "MD040": {
671
671
  "description": "MD040/fenced-code-language - Fenced code blocks should have a language specified",
672
- "type": "boolean",
673
- "default": true
672
+ "type": [
673
+ "boolean",
674
+ "object"
675
+ ],
676
+ "default": true,
677
+ "properties": {
678
+ "allowed_languages": {
679
+ "description": "List of languages",
680
+ "type": "array",
681
+ "items": {
682
+ "type": "string"
683
+ },
684
+ "default": []
685
+ },
686
+ "language_only": {
687
+ "description": "Require language only",
688
+ "type": "boolean",
689
+ "default": false
690
+ }
691
+ },
692
+ "additionalProperties": false
674
693
  },
675
694
  "fenced-code-language": {
676
695
  "$ref": "#/properties/MD040"
@@ -737,6 +756,11 @@
737
756
  "pattern": "^(\\*|\\+|#{1,6} .*)$"
738
757
  },
739
758
  "default": []
759
+ },
760
+ "match_case": {
761
+ "description": "Match case of headings",
762
+ "type": "boolean",
763
+ "default": false
740
764
  }
741
765
  },
742
766
  "additionalProperties": false
@@ -909,8 +933,24 @@
909
933
  },
910
934
  "MD053": {
911
935
  "description": "MD053/link-image-reference-definitions - Link and image reference definitions should be needed",
912
- "type": "boolean",
913
- "default": true
936
+ "type": [
937
+ "boolean",
938
+ "object"
939
+ ],
940
+ "default": true,
941
+ "properties": {
942
+ "ignored_definitions": {
943
+ "description": "Ignored definitions",
944
+ "type": "array",
945
+ "items": {
946
+ "type": "string"
947
+ },
948
+ "default": [
949
+ "//"
950
+ ]
951
+ }
952
+ },
953
+ "additionalProperties": false
914
954
  },
915
955
  "link-image-reference-definitions": {
916
956
  "$ref": "#/properties/MD053"
@@ -0,0 +1,26 @@
1
+ {
2
+ "comment": "Disables rules that may conflict with Prettier",
3
+
4
+ "blanks-around-fences": false,
5
+ "blanks-around-headings": false,
6
+ "blanks-around-lists": false,
7
+ "code-fence-style": false,
8
+ "emphasis-style": false,
9
+ "heading-start-left": false,
10
+ "hr-style": false,
11
+ "line-length": false,
12
+ "list-indent": false,
13
+ "list-marker-space": false,
14
+ "no-blanks-blockquote": false,
15
+ "no-hard-tabs": false,
16
+ "no-missing-space-atx": false,
17
+ "no-missing-space-closed-atx": false,
18
+ "no-multiple-blanks": false,
19
+ "no-multiple-space-atx": false,
20
+ "no-multiple-space-blockquote": false,
21
+ "no-multiple-space-closed-atx": false,
22
+ "no-trailing-spaces": false,
23
+ "ol-prefix": false,
24
+ "strong-style": false,
25
+ "ul-indent": false
26
+ }