markdownlint 0.24.0 → 0.26.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 (51) hide show
  1. package/CONTRIBUTING.md +15 -3
  2. package/LICENSE +1 -1
  3. package/README.md +138 -87
  4. package/demo/markdownlint-browser.js +2028 -1364
  5. package/doc/CustomRules.md +15 -4
  6. package/doc/Rules.md +217 -26
  7. package/helpers/LICENSE +1 -1
  8. package/helpers/helpers.js +541 -188
  9. package/helpers/package.json +4 -1
  10. package/lib/cache.js +15 -25
  11. package/lib/constants.js +7 -0
  12. package/lib/markdownlint.d.ts +27 -19
  13. package/lib/markdownlint.js +438 -344
  14. package/lib/md004.js +4 -4
  15. package/lib/md005.js +4 -4
  16. package/lib/md006.js +4 -4
  17. package/lib/md007.js +8 -6
  18. package/lib/md009.js +20 -13
  19. package/lib/md010.js +34 -16
  20. package/lib/md011.js +4 -4
  21. package/lib/md013.js +4 -5
  22. package/lib/md014.js +4 -4
  23. package/lib/md021.js +3 -1
  24. package/lib/md026.js +1 -1
  25. package/lib/md027.js +2 -2
  26. package/lib/md028.js +2 -2
  27. package/lib/md029.js +5 -4
  28. package/lib/md030.js +4 -4
  29. package/lib/md031.js +2 -2
  30. package/lib/md032.js +3 -2
  31. package/lib/md033.js +12 -9
  32. package/lib/md034.js +2 -2
  33. package/lib/md035.js +10 -5
  34. package/lib/md036.js +2 -2
  35. package/lib/md037.js +5 -3
  36. package/lib/md038.js +7 -4
  37. package/lib/md039.js +8 -5
  38. package/lib/md042.js +17 -10
  39. package/lib/md043.js +2 -3
  40. package/lib/md044.js +21 -10
  41. package/lib/md046.js +14 -13
  42. package/lib/md048.js +13 -14
  43. package/lib/md049-md050.js +73 -0
  44. package/lib/md051.js +84 -0
  45. package/lib/md052.js +35 -0
  46. package/lib/md053.js +52 -0
  47. package/lib/rules.js +8 -6
  48. package/package.json +37 -32
  49. package/schema/.markdownlint.jsonc +30 -3
  50. package/schema/.markdownlint.yaml +26 -1
  51. package/schema/markdownlint-config-schema.json +159 -683
package/CONTRIBUTING.md CHANGED
@@ -23,17 +23,20 @@ Try to break the new code now, or else it will get broken later.
23
23
 
24
24
  Run tests before sending a pull request via `npm test` in the [usual manner](https://docs.npmjs.com/misc/scripts).
25
25
  Tests should all pass on all platforms.
26
- The test runner is [tape](https://www.npmjs.com/package/tape) and test cases are located in `test/markdownlint-test*.js`.
26
+ The test runner is [AVA](https://github.com/avajs/ava) and test cases are located in `test/markdownlint-test*.js`.
27
27
  When running tests, `test/*.md` files are enumerated, linted, and fail if any violations are missing a corresponding `{MD###}` marker in the test file.
28
28
  For example, the line `### Heading {MD001}` is expected to trigger the rule `MD001`.
29
29
  For cases where the marker text can not be present on the same line, the syntax `{MD###:#}` can be used to include a line number.
30
30
  If `some-test.md` needs custom configuration, a `some-test.json` is used to provide a custom `options.config` for that scenario.
31
+ Tests run by `markdownlint-test-scenarios.js` use [AVA's snapshot feature](https://github.com/avajs/ava/blob/main/docs/04-snapshot-testing.md).
32
+ To update snapshots (for example, after modifying a test file), run `npm run update-snapshots` and include the updated files with the pull request.
31
33
 
32
34
  Lint before sending a pull request by running `npm run lint`.
33
35
  There should be no issues.
34
36
 
35
37
  Run a full continuous integration pass before sending a pull request via `npm run ci`.
36
- Code coverage should remain at 100%.
38
+ Code coverage should always be 100%.
39
+ As part of a continuous integration run, generated files may get updated and fail the run - commit them to the repository and rerun continuous integration.
37
40
 
38
41
  Pull requests should contain a single commit.
39
42
  If necessary, squash multiple commits before creating the pull request and when making changes.
@@ -43,9 +46,18 @@ Open pull requests against the `next` branch.
43
46
  That's where the latest changes are staged for the next release.
44
47
  Include the text "(fixes #??)" at the end of the commit message so the pull request will be associated with the relevant issue.
45
48
  End commit messages with a period (`.`).
46
- Do not include `package-lock.json` in the pull request.
47
49
  Once accepted, the tag `fixed in next` will be added to the issue.
48
50
  When the commit is merged to the main branch during the release process, the issue will be closed automatically.
49
51
  (See [Closing issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/) for details.)
50
52
 
53
+ Please refrain from using slang or meaningless placeholder words.
54
+ Sample content can be "text", "code", "heading", or the like.
55
+ Sample URLs should use [example.com](https://en.wikipedia.org/wiki/Example.com) which is safe for this purpose.
56
+ Profanity is not allowed.
57
+
58
+ In order to maintain the permissive MIT license this project uses, all contributions must be your own and released under that license.
59
+ Code you add should be an original work and should not be copied from elsewhere.
60
+ Taking code from a different project, Stack Overflow, or the like is not allowed.
61
+ The use of tools such as GitHub Copilot that generate code from other projects is not allowed.
62
+
51
63
  Thank you!
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 David Anson
3
+ Copyright (c) 2015-2022 David Anson
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -33,17 +33,19 @@ and test cases came directly from that project.
33
33
  ### Related
34
34
 
35
35
  * CLI
36
- * [markdownlint-cli command-line interface for Node.js](https://github.com/igorshubovych/markdownlint-cli)
37
- * [markdownlint-cli2 command-line interface for Node.js](https://github.com/DavidAnson/markdownlint-cli2)
36
+ * [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli)
37
+ command-line interface for Node.js ([works with pre-commit](https://github.com/igorshubovych/markdownlint-cli#use-with-pre-commit))
38
+ * [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2)
39
+ command-line interface for Node.js ([works with pre-commit](https://github.com/DavidAnson/markdownlint-cli2#pre-commit))
38
40
  * GitHub
39
41
  * [GitHub Super-Linter Action](https://github.com/github/super-linter)
40
42
  * [GitHub Actions problem matcher for markdownlint-cli](https://github.com/xt0rted/markdownlint-problem-matcher)
41
43
  * Editor
42
44
  * [vscode-markdownlint extension for VS Code](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint)
43
45
  * [Sublime Text markdownlint for Sublime Text](https://packagecontrol.io/packages/SublimeLinter-contrib-markdownlint)
44
- * [linter-node-markdownlint extension for Atom](https://atom.io/packages/linter-node-markdownlint)
45
46
  * [coc-markdownlint extension for Vim/Neovim](https://github.com/fannheyward/coc-markdownlint)
46
47
  * Tooling
48
+ * [eslint-plugin-markdownlint for the ESLint analyzer](https://github.com/paweldrozd/eslint-plugin-markdownlint)
47
49
  * [grunt-markdownlint for the Grunt task runner](https://github.com/sagiegurari/grunt-markdownlint)
48
50
  * [Cake.Markdownlint addin for Cake build automation system](https://github.com/cake-contrib/Cake.Markdownlint)
49
51
  * Ruby
@@ -102,6 +104,11 @@ playground for learning and exploring.
102
104
  * **[MD046](doc/Rules.md#md046)** *code-block-style* - Code block style
103
105
  * **[MD047](doc/Rules.md#md047)** *single-trailing-newline* - Files should end with a single newline character
104
106
  * **[MD048](doc/Rules.md#md048)** *code-fence-style* - Code fence style
107
+ * **[MD049](doc/Rules.md#md049)** *emphasis-style* - Emphasis style should be consistent
108
+ * **[MD050](doc/Rules.md#md050)** *strong-style* - Strong style should be consistent
109
+ * **[MD051](doc/Rules.md#md051)** *link-fragments* - Link fragments should be valid
110
+ * **[MD052](doc/Rules.md#md052)** *reference-links-images* - Reference links and images should use a label that is defined
111
+ * **[MD053](doc/Rules.md#md053)** *link-image-reference-definitions* - Link and image reference definitions should be needed
105
112
 
106
113
  <!-- markdownlint-restore -->
107
114
 
@@ -125,7 +132,7 @@ rules at once.
125
132
  * **blockquote** - MD027, MD028
126
133
  * **bullet** - MD004, MD005, MD006, MD007, MD032
127
134
  * **code** - MD014, MD031, MD038, MD040, MD046, MD048
128
- * **emphasis** - MD036, MD037
135
+ * **emphasis** - MD036, MD037, MD049, MD050
129
136
  * **hard_tab** - MD010
130
137
  * **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022,
131
138
  MD023, MD024, MD025, MD026, MD036, MD041, MD043
@@ -133,11 +140,11 @@ rules at once.
133
140
  MD023, MD024, MD025, MD026, MD036, MD041, MD043
134
141
  * **hr** - MD035
135
142
  * **html** - MD033
136
- * **images** - MD045
143
+ * **images** - MD045, MD052, MD053
137
144
  * **indentation** - MD005, MD006, MD007, MD027
138
145
  * **language** - MD040
139
146
  * **line_length** - MD013
140
- * **links** - MD011, MD034, MD039, MD042
147
+ * **links** - MD011, MD034, MD039, MD042, MD051, MD052, MD053
141
148
  * **ol** - MD029, MD030, MD032
142
149
  * **spaces** - MD018, MD019, MD020, MD021, MD023
143
150
  * **spelling** - MD044
@@ -163,10 +170,14 @@ appear in the final markup):
163
170
 
164
171
  * Disable all rules: `<!-- markdownlint-disable -->`
165
172
  * Enable all rules: `<!-- markdownlint-enable -->`
166
- * Disable all rules for the next line only: `<!-- markdownlint-disable-next-line -->`
173
+ * Disable all rules for the current line: `<!-- markdownlint-disable-line -->`
174
+ * Disable all rules for the next line: `<!-- markdownlint-disable-next-line -->`
167
175
  * Disable one or more rules by name: `<!-- markdownlint-disable MD001 MD005 -->`
168
176
  * Enable one or more rules by name: `<!-- markdownlint-enable MD001 MD005 -->`
169
- * Disable one or more rules by name for the next line only: `<!-- markdownlint-disable-next-line MD001 MD005 -->`
177
+ * Disable one or more rules by name for the current line:
178
+ `<!-- markdownlint-disable-line MD001 MD005 -->`
179
+ * Disable one or more rules by name for the next line:
180
+ `<!-- markdownlint-disable-next-line MD001 MD005 -->`
170
181
  * Capture the current rule configuration: `<!-- markdownlint-capture -->`
171
182
  * Restore the captured rule configuration: `<!-- markdownlint-restore -->`
172
183
 
@@ -179,6 +190,12 @@ deliberate space * in * emphasis
179
190
 
180
191
  Or:
181
192
 
193
+ ```markdown
194
+ deliberate space * in * emphasis <!-- markdownlint-disable-line no-space-in-emphasis -->
195
+ ```
196
+
197
+ Or:
198
+
182
199
  ```markdown
183
200
  <!-- markdownlint-disable no-space-in-emphasis -->
184
201
  deliberate space * in * emphasis
@@ -229,7 +246,7 @@ more rules for a file, the following more advanced syntax is supported:
229
246
  For example:
230
247
 
231
248
  ```markdown
232
- <!-- markdownlint-configure-file { "MD013": { "line_length": 70 } } -->
249
+ <!-- markdownlint-configure-file { "MD013": { "code_blocks": false } } -->
233
250
  ```
234
251
 
235
252
  or
@@ -245,8 +262,11 @@ or
245
262
  -->
246
263
  ```
247
264
 
248
- These changes apply to the entire file regardless of where the comment
249
- is located. Multiple such comments (if present) are applied top-to-bottom.
265
+ These changes apply to the entire file regardless of where the comment is
266
+ located. Multiple such comments (if present) are applied top-to-bottom. By
267
+ default, content of `markdownlint-configure-file` is assumed to be JSON, but
268
+ [`options.configParsers`](#optionsconfigparsers) can be used to support
269
+ alternate formats.
250
270
 
251
271
  ## API
252
272
 
@@ -297,60 +317,6 @@ Type: `Object`
297
317
  Configures the function. All properties are optional, but at least one
298
318
  of `files` or `strings` should be set to provide input.
299
319
 
300
- ##### options.customRules
301
-
302
- Type: `Array` of `Object`
303
-
304
- List of custom rules to include with the default rule set for linting.
305
-
306
- Each array element should define a rule. Rules are typically exported
307
- by another package, but can be defined locally. Custom rules are
308
- identified by the
309
- [keyword `markdownlint-rule` on npm](https://www.npmjs.com/search?q=keywords:markdownlint-rule).
310
-
311
- Example:
312
-
313
- ```js
314
- const extraRules = require("extraRules");
315
- const options = {
316
- "customRules": [ extraRules.one, extraRules.two ]
317
- };
318
- ```
319
-
320
- See [CustomRules.md](doc/CustomRules.md) for details about authoring
321
- custom rules.
322
-
323
- ##### options.files
324
-
325
- Type: `Array` of `String`
326
-
327
- List of files to lint.
328
-
329
- Each array element should be a single file (via relative or absolute path);
330
- [globbing](https://en.wikipedia.org/wiki/Glob_%28programming%29) is the
331
- caller's responsibility.
332
-
333
- Example: `[ "one.md", "dir/two.md" ]`
334
-
335
- ##### options.strings
336
-
337
- Type: `Object` mapping `String` to `String`
338
-
339
- Map of identifiers to strings for linting.
340
-
341
- When Markdown content is not available as files, it can be passed as
342
- strings. The keys of the `strings` object are used to identify each
343
- input value in the `result` summary.
344
-
345
- Example:
346
-
347
- ```json
348
- {
349
- "readme": "# README\n...",
350
- "changelog": "# CHANGELOG\n..."
351
- }
352
- ```
353
-
354
320
  ##### options.config
355
321
 
356
322
  Type: `Object` mapping `String` to `Boolean | Object`
@@ -442,6 +408,59 @@ const options = {
442
408
  };
443
409
  ```
444
410
 
411
+ ##### options.configParsers
412
+
413
+ Type: *Optional* `Array` of `Function` taking (`String`) and returning `Object`
414
+
415
+ Array of functions to parse the content of `markdownlint-configure-file` blocks.
416
+
417
+ As shown in the [Configuration](#configuration) section, inline comments can be
418
+ used to customize the [configuration object](#optionsconfig) for a document. By
419
+ default, the `JSON.parse` built-in is used, but custom parsers can be specified.
420
+ Content is passed to each parser function until one returns a value (vs. throwing
421
+ an exception). As such, strict parsers should come before flexible ones.
422
+
423
+ For example:
424
+
425
+ ```js
426
+ [ JSON.parse, require("toml").parse, require("js-yaml").load ]
427
+ ```
428
+
429
+ ##### options.customRules
430
+
431
+ Type: `Array` of `Object`
432
+
433
+ List of custom rules to include with the default rule set for linting.
434
+
435
+ Each array element should define a rule. Rules are typically exported
436
+ by another package, but can be defined locally. Custom rules are
437
+ identified by the
438
+ [keyword `markdownlint-rule` on npm](https://www.npmjs.com/search?q=keywords:markdownlint-rule).
439
+
440
+ Example:
441
+
442
+ ```js
443
+ const extraRules = require("extraRules");
444
+ const options = {
445
+ "customRules": [ extraRules.one, extraRules.two ]
446
+ };
447
+ ```
448
+
449
+ See [CustomRules.md](doc/CustomRules.md) for details about authoring
450
+ custom rules.
451
+
452
+ ##### options.files
453
+
454
+ Type: `Array` of `String`
455
+
456
+ List of files to lint.
457
+
458
+ Each array element should be a single file (via relative or absolute path);
459
+ [globbing](https://en.wikipedia.org/wiki/Glob_%28programming%29) is the
460
+ caller's responsibility.
461
+
462
+ Example: `[ "one.md", "dir/two.md" ]`
463
+
445
464
  ##### options.frontMatter
446
465
 
447
466
  Type: `RegExp`
@@ -472,6 +491,16 @@ title: Title
472
491
 
473
492
  Note: Matches must occur at the start of the file.
474
493
 
494
+ ##### options.fs
495
+
496
+ Type: `Object` implementing the [file system API](https://nodejs.org/api/fs.html)
497
+
498
+ In advanced scenarios, it may be desirable to bypass the default file system API.
499
+ If a custom file system implementation is provided, `markdownlint` will use that
500
+ instead of invoking `require("fs")`.
501
+
502
+ Note: The only methods called are `readFile` and `readFileSync`.
503
+
475
504
  ##### options.handleRuleFailures
476
505
 
477
506
  Type: `Boolean`
@@ -487,6 +516,20 @@ This setting can be useful in the presence of (custom) rules that encounter
487
516
  unexpected syntax and fail. By enabling this option, the linting process
488
517
  is allowed to continue and report any violations that were found.
489
518
 
519
+ ##### options.markdownItPlugins
520
+
521
+ Type: `Array` of `Array` of `Function` and plugin parameters
522
+
523
+ Specifies additional [markdown-it plugins](https://www.npmjs.com/search?q=keywords:markdown-it-plugin)
524
+ to use when parsing input. Plugins can be used to support additional syntax and
525
+ features for advanced scenarios.
526
+
527
+ Each item in the top-level `Array` should be of the form:
528
+
529
+ ```js
530
+ [ require("markdown-it-plugin"), plugin_param_0, plugin_param_1, ... ]
531
+ ```
532
+
490
533
  ##### options.noInlineConfig
491
534
 
492
535
  Type: `Boolean`
@@ -514,36 +557,31 @@ as any additional detail or context that is available. *This is deprecated.*
514
557
 
515
558
  Passing a `resultVersion` of `2` corresponds to a detailed format where each error
516
559
  includes information about the line number, rule names, description, as well as any
517
- additional detail or context that is available. *This is the default.*
560
+ additional detail or context that is available. *This is deprecated.*
518
561
 
519
562
  Passing a `resultVersion` of `3` corresponds to the detailed version `2` format
520
563
  with additional information about how to fix automatically-fixable errors. In this
521
564
  mode, all errors that occur on each line are reported (other versions report only
522
- the first error for each rule).
523
-
524
- ##### options.markdownItPlugins
525
-
526
- Type: `Array` of `Array` of `Function` and plugin parameters
527
-
528
- Specifies additional [markdown-it plugins](https://www.npmjs.com/search?q=keywords:markdown-it-plugin)
529
- to use when parsing input. Plugins can be used to support additional syntax and
530
- features for advanced scenarios.
565
+ the first error for each rule). *This is the default.*
531
566
 
532
- Each item in the top-level `Array` should be of the form:
567
+ ##### options.strings
533
568
 
534
- ```js
535
- [ require("markdown-it-plugin"), plugin_param_0, plugin_param_1, ... ]
536
- ```
569
+ Type: `Object` mapping `String` to `String`
537
570
 
538
- ##### options.fs
571
+ Map of identifiers to strings for linting.
539
572
 
540
- Type: `Object` implementing the [file system API](https://nodejs.org/api/fs.html)
573
+ When Markdown content is not available as files, it can be passed as
574
+ strings. The keys of the `strings` object are used to identify each
575
+ input value in the `result` summary.
541
576
 
542
- In advanced scenarios, it may be desirable to bypass the default file system API.
543
- If a custom file system implementation is provided, `markdownlint` will use that
544
- instead of invoking `require("fs")`.
577
+ Example:
545
578
 
546
- Note: The only methods called are `readFile` and `readFileSync`.
579
+ ```json
580
+ {
581
+ "readme": "# README\n...",
582
+ "changelog": "# CHANGELOG\n..."
583
+ }
584
+ ```
547
585
 
548
586
  #### callback
549
587
 
@@ -623,7 +661,8 @@ The `file` is resolved relative to the current working directory. If an `extends
623
661
  key is present once read, its value will be resolved as a path relative to `file`
624
662
  and loaded recursively. Settings from a file referenced by `extends` are applied
625
663
  first, then those of `file` are applied on top (overriding any of the same keys
626
- appearing in the referenced file).
664
+ appearing in the referenced file). If either the `file` or `extends` path begins
665
+ with the `~` directory, it will act as a placeholder for the home directory.
627
666
 
628
667
  #### parsers
629
668
 
@@ -859,7 +898,7 @@ const results = window.markdownlint.sync(options).toString();
859
898
  ## Examples
860
899
 
861
900
  For ideas how to integrate `markdownlint` into your workflow, refer to the
862
- following projects or one of the tools in the [Related section](#Related):
901
+ following projects or one of the tools in the [Related section](#related):
863
902
 
864
903
  * [.NET Documentation](https://docs.microsoft.com/en-us/dotnet/) ([Search repository](https://github.com/dotnet/docs/search?q=markdownlint))
865
904
  * [ally.js](https://allyjs.io/) ([Search repository](https://github.com/medialize/ally.js/search?q=markdownlint))
@@ -870,6 +909,7 @@ following projects or one of the tools in the [Related section](#Related):
870
909
  * [MDN Web Docs](https://developer.mozilla.org/) ([Search repository](https://github.com/mdn/content/search?q=markdownlint))
871
910
  * [MkDocs](https://www.mkdocs.org/) ([Search repository](https://github.com/mkdocs/mkdocs/search?q=markdownlint))
872
911
  * [Mocha](https://mochajs.org/) ([Search repository](https://github.com/mochajs/mocha/search?q=markdownlint))
912
+ * [Pi-hole documentation](https://docs.pi-hole.net) ([Search repository](https://github.com/pi-hole/docs/search?q=markdownlint))
873
913
  * [Reactable](https://glittershark.github.io/reactable/) ([Search repository](https://github.com/glittershark/reactable/search?q=markdownlint))
874
914
  * [Sinon.JS](https://sinonjs.org/) ([Search repository](https://github.com/sinonjs/sinon/search?q=markdownlint))
875
915
  * [TestCafe](https://devexpress.github.io/testcafe/) ([Search repository](https://github.com/DevExpress/testcafe/search?q=markdownlint))
@@ -968,6 +1008,17 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
968
1008
  * 0.24.0 - Remove support for end-of-life Node version 10, add support for custom file system
969
1009
  module, improve MD010/MD011/MD037/MD043/MD044, improve TypeScript declaration file
970
1010
  and JSON schema, update dependencies.
1011
+ * 0.25.0 - Add MD049/MD050 for consistent emphasis/strong style (both auto-fixable), improve
1012
+ MD007/MD010/MD032/MD033/MD035/MD037/MD039, support asynchronous custom rules,
1013
+ improve performance, improve CI process, reduce dependencies, update dependencies.
1014
+ * 0.25.1 - Update dependencies for CVE-2022-21670.
1015
+ * 0.26.0 - Add MD051/MD052/MD053 for validating link fragments & reference links/images &
1016
+ link/image reference definitions (MD053 is auto-fixable), improve
1017
+ MD010/MD031/MD035/MD039/MD042/MD044/MD049/MD050, add `markdownlint-disable-line`
1018
+ inline comment, support `~` paths in `readConfig/Sync`, add `configParsers` option,
1019
+ remove support for end-of-life Node version 12, default `resultVersion` to 3, update
1020
+ browser script to use ES2015, simplify JSON schema, address remaining CodeQL issues,
1021
+ improve performance, update dependencies.
971
1022
 
972
1023
  [npm-image]: https://img.shields.io/npm/v/markdownlint.svg
973
1024
  [npm-url]: https://www.npmjs.com/package/markdownlint