markdownlint 0.34.0 → 0.36.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 (90) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +97 -45
  3. package/demo/markdownlint-browser.js +2186 -2164
  4. package/doc/CustomRules.md +66 -255
  5. package/doc/Rules.md +102 -29
  6. package/doc/md003.md +2 -2
  7. package/doc/md004.md +4 -3
  8. package/doc/md034.md +5 -0
  9. package/doc/md035.md +3 -8
  10. package/doc/md044.md +10 -0
  11. package/doc/md046.md +2 -2
  12. package/doc/md048.md +3 -2
  13. package/doc/md049.md +4 -3
  14. package/doc/md050.md +4 -4
  15. package/doc/md051.md +11 -3
  16. package/doc/md055.md +3 -2
  17. package/doc/md058.md +48 -0
  18. package/helpers/README.md +2 -45
  19. package/helpers/helpers.js +115 -607
  20. package/helpers/micromark-helpers.cjs +296 -0
  21. package/helpers/micromark-parse.cjs +313 -0
  22. package/helpers/package.json +5 -2
  23. package/helpers/shared.js +6 -0
  24. package/helpers/test.cjs +28 -0
  25. package/lib/cache.js +62 -13
  26. package/lib/configuration-strict.d.ts +1199 -0
  27. package/lib/configuration.d.ts +3 -1173
  28. package/lib/constants.js +3 -2
  29. package/lib/markdownit.cjs +172 -0
  30. package/lib/markdownlint.d.ts +103 -56
  31. package/lib/markdownlint.js +180 -120
  32. package/lib/md001.js +15 -9
  33. package/lib/md003.js +14 -9
  34. package/lib/md004.js +55 -48
  35. package/lib/md005.js +4 -13
  36. package/lib/md007.js +7 -11
  37. package/lib/md009.js +50 -44
  38. package/lib/md010.js +52 -33
  39. package/lib/md011.js +32 -23
  40. package/lib/md012.js +17 -9
  41. package/lib/md013.js +44 -38
  42. package/lib/md014.js +31 -38
  43. package/lib/md018.js +17 -9
  44. package/lib/md019-md021.js +80 -0
  45. package/lib/md020.js +14 -8
  46. package/lib/md022.js +13 -29
  47. package/lib/md023.js +22 -23
  48. package/lib/md024.js +12 -9
  49. package/lib/md025.js +15 -10
  50. package/lib/md026.js +2 -7
  51. package/lib/md027.js +7 -12
  52. package/lib/md028.js +3 -8
  53. package/lib/md029.js +40 -34
  54. package/lib/md030.js +4 -10
  55. package/lib/md031.js +45 -23
  56. package/lib/md032.js +33 -31
  57. package/lib/md033.js +3 -8
  58. package/lib/md034.js +21 -34
  59. package/lib/md035.js +2 -7
  60. package/lib/md036.js +19 -24
  61. package/lib/md037.js +3 -8
  62. package/lib/md038.js +11 -22
  63. package/lib/md039.js +64 -54
  64. package/lib/md040.js +13 -20
  65. package/lib/md041.js +5 -5
  66. package/lib/md042.js +44 -38
  67. package/lib/md043.js +20 -14
  68. package/lib/md044.js +34 -36
  69. package/lib/md045.js +5 -10
  70. package/lib/md046.js +2 -8
  71. package/lib/md048.js +30 -23
  72. package/lib/md049-md050.js +22 -12
  73. package/lib/md051.js +20 -28
  74. package/lib/md052.js +2 -2
  75. package/lib/md053.js +7 -6
  76. package/lib/md054.js +16 -23
  77. package/lib/md055.js +41 -49
  78. package/lib/md056.js +32 -33
  79. package/lib/md058.js +58 -0
  80. package/lib/rules.js +11 -4
  81. package/package.json +23 -20
  82. package/schema/.markdownlint.jsonc +58 -52
  83. package/schema/.markdownlint.yaml +56 -51
  84. package/schema/ValidatingConfiguration.md +6 -8
  85. package/schema/markdownlint-config-schema-strict.json +1841 -0
  86. package/schema/markdownlint-config-schema.json +141 -109
  87. package/style/prettier.json +1 -0
  88. package/helpers/micromark.cjs +0 -445
  89. package/lib/md019.js +0 -42
  90. package/lib/md021.js +0 -65
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.36.0
4
+
5
+ - Improve MD051
6
+ - Move `applyFix` and `applyFixes` from helpers to core
7
+ - Make `micromark` parser available to custom rules
8
+ - Introduce `./micromark` helpers exports
9
+ - Update custom/rule documentation
10
+ - Improve performance
11
+ - Update dependencies
12
+
13
+ ## 0.35.0
14
+
15
+ - Add MD058/blanks-around-tables
16
+ - Use `micromark` in MD001/MD003/MD009/MD010/MD013/MD014/MD019/MD021/MD023/
17
+ MD024/MD025/MD039/MD042/MD043
18
+ - Improve MD018/MD020/MD031/MD034/MD044
19
+ - `markdown-it` parser no longer invoked by default
20
+ - Add strict version of JSON schema
21
+ - Improve performance
22
+ - Update dependencies
23
+
3
24
  ## 0.34.0
4
25
 
5
26
  - Use `micromark` in MD027/MD028/MD036/MD040/MD041/MD046/MD048
package/README.md CHANGED
@@ -13,22 +13,31 @@ npm install markdownlint --save-dev
13
13
 
14
14
  ## Overview
15
15
 
16
- The [Markdown](https://en.wikipedia.org/wiki/Markdown) markup language
17
- is designed to be easy to read, write, and understand. It succeeds -
18
- and its flexibility is both a benefit and a drawback. Many styles are
19
- possible, so formatting can be inconsistent. Some constructs don't
20
- work well in all parsers and should be avoided. The
21
- [CommonMark](https://commonmark.org/) specification standardizes
22
- parsers - but not authors.
23
-
24
- `markdownlint` is a
25
- [static analysis](https://en.wikipedia.org/wiki/Static_program_analysis)
26
- tool for [Node.js](https://nodejs.org/) with a library of rules
27
- to enforce standards and consistency for Markdown files. It was
28
- inspired by - and heavily influenced by - Mark Harrison's
29
- [markdownlint](https://github.com/markdownlint/markdownlint) for
30
- [Ruby](https://www.ruby-lang.org/). The initial rules, rule documentation,
31
- and test cases came directly from that project.
16
+ The [Markdown][markdown] markup language is designed to be easy to read, write,
17
+ and understand. It succeeds - and its flexibility is both a benefit and a
18
+ drawback. Many styles are possible, so formatting can be inconsistent; some
19
+ constructs don't work well in all parsers and should be avoided.
20
+
21
+ `markdownlint` is a [static analysis][static-analysis] tool for
22
+ [Node.js][nodejs] with a library of rules to enforce standards and consistency
23
+ for Markdown files. It was inspired by - and heavily influenced by - Mark
24
+ Harrison's [markdownlint][markdownlint-ruby] for Ruby. The initial rules, rule
25
+ documentation, and test cases came from that project.
26
+
27
+ `markdownlint` uses the [`micromark`][micromark] parser and honors the
28
+ [CommonMark][commonmark] specification for Markdown. It additionally supports
29
+ popular [GitHub Flavored Markdown (GFM)][gfm] syntax like autolinks and tables
30
+ as well as directives, footnotes, and math syntax - all implemented by
31
+ [`micromark` extensions][micromark-extensions].
32
+
33
+ [commonmark]: https://commonmark.org/
34
+ [gfm]: https://github.github.com/gfm/
35
+ [markdown]: https://en.wikipedia.org/wiki/Markdown
36
+ [markdownlint-ruby]: https://github.com/markdownlint/markdownlint
37
+ [micromark]: https://github.com/micromark/micromark
38
+ [micromark-extensions]: https://github.com/micromark/micromark?tab=readme-ov-file#list-of-extensions
39
+ [nodejs]: https://nodejs.org/
40
+ [static-analysis]: https://en.wikipedia.org/wiki/Static_program_analysis
32
41
 
33
42
  ### Related
34
43
 
@@ -136,6 +145,7 @@ playground for learning and exploring.
136
145
  - **[MD054](doc/md054.md)** *link-image-style* - Link and image style
137
146
  - **[MD055](doc/md055.md)** *table-pipe-style* - Table pipe style
138
147
  - **[MD056](doc/md056.md)** *table-column-count* - Table column count
148
+ - **[MD058](doc/md058.md)** *blanks-around-tables* - Tables should be surrounded by blank lines
139
149
 
140
150
  <!-- markdownlint-restore -->
141
151
 
@@ -177,7 +187,7 @@ rules at once.
177
187
  - **`ol`** - `MD029`, `MD030`, `MD032`
178
188
  - **`spaces`** - `MD018`, `MD019`, `MD020`, `MD021`, `MD023`
179
189
  - **`spelling`** - `MD044`
180
- - **`table`** - `MD055`, `MD056`
190
+ - **`table`** - `MD055`, `MD056`, `MD058`
181
191
  - **`ul`** - `MD004`, `MD005`, `MD007`, `MD030`, `MD032`
182
192
  - **`url`** - `MD034`
183
193
  - **`whitespace`** - `MD009`, `MD010`, `MD012`, `MD027`, `MD028`, `MD030`,
@@ -353,16 +363,16 @@ Type: `Object` mapping `String` to `Boolean | Object`
353
363
 
354
364
  Configures the rules to use.
355
365
 
356
- Object keys are rule names or aliases and values are the rule's configuration.
366
+ Object keys are rule names/aliases; object values are the rule's configuration.
357
367
  The value `false` disables a rule, `true` enables its default configuration,
358
- and passing an object customizes its settings. Setting the special `default`
359
- rule to `true` or `false` includes/excludes all rules by default. Enabling
360
- or disabling a tag name (ex: `whitespace`) affects all rules having that
361
- tag.
368
+ and passing an object value customizes that rule. Setting the special `default`
369
+ rule to `true` or `false` includes/excludes all rules by default. In the absence
370
+ of a configuration object, all rules are enabled. Enabling or disabling a tag
371
+ name (ex: `whitespace`) affects all rules having that tag.
362
372
 
363
- The `default` rule is applied first, then keys are processed in order
364
- from top to bottom with later values overriding earlier ones. Keys
365
- (including rule names, aliases, tags, and `default`) are not case-sensitive.
373
+ The `default` rule is applied first, then keys are processed in order from top
374
+ to bottom with later values overriding earlier ones. Keys (including rule names,
375
+ aliases, tags, and `default`) are not case-sensitive.
366
376
 
367
377
  Example:
368
378
 
@@ -515,7 +525,7 @@ specify a custom `RegExp` or use the value `null` to disable the feature.
515
525
  The default value:
516
526
 
517
527
  ```javascript
518
- /((^---\s*$[\s\S]+?^---\s*)|(^\+\+\+\s*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m
528
+ /((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m
519
529
  ```
520
530
 
521
531
  Ignores [YAML](https://en.wikipedia.org/wiki/YAML),
@@ -562,9 +572,9 @@ is allowed to continue and report any violations that were found.
562
572
 
563
573
  Type: `Array` of `Array` of `Function` and plugin parameters
564
574
 
565
- Specifies additional [markdown-it plugins][markdown-it-plugin] to use when
575
+ Specifies additional [`markdown-it` plugins][markdown-it-plugin] to use when
566
576
  parsing input. Plugins can be used to support additional syntax and features for
567
- advanced scenarios.
577
+ advanced scenarios. *Deprecated.*
568
578
 
569
579
  [markdown-it-plugin]: https://www.npmjs.com/search?q=keywords:markdown-it-plugin
570
580
 
@@ -574,6 +584,13 @@ Each item in the top-level `Array` should be of the form:
574
584
  [ require("markdown-it-plugin"), plugin_param_0, plugin_param_1, ... ]
575
585
  ```
576
586
 
587
+ > Note that `markdown-it` plugins are only called when the `markdown-it` parser
588
+ > is invoked. None of the built-in rules use the `markdown-it` parser, so
589
+ > `markdown-it` plugins will only be invoked when one or more
590
+ > [custom rules][custom-rules] that use the `markdown-it` parser are present.
591
+
592
+ [custom-rules]: #custom-rules
593
+
577
594
  ##### options.noInlineConfig
578
595
 
579
596
  Type: `Boolean`
@@ -593,23 +610,20 @@ Specifies which version of the `result` object to return (see the "Usage"
593
610
  section below for examples).
594
611
 
595
612
  Passing a `resultVersion` of `0` corresponds to the original, simple format
596
- where each error is identified by rule name and line number. *This is
597
- deprecated.*
613
+ where each error is identified by rule name and line number. *Deprecated*
598
614
 
599
615
  Passing a `resultVersion` of `1` corresponds to a detailed format where each
600
616
  error includes information about the line number, rule name, alias, description,
601
- as well as any additional detail or context that is available. *This is
602
- deprecated.*
617
+ as well as any additional detail or context that is available. *Deprecated*
603
618
 
604
619
  Passing a `resultVersion` of `2` corresponds to a detailed format where each
605
620
  error includes information about the line number, rule names, description, as
606
- well as any additional detail or context that is available. *This is
607
- deprecated.*
621
+ well as any additional detail or context that is available. *Deprecated*
608
622
 
609
623
  Passing a `resultVersion` of `3` corresponds to the detailed version `2` format
610
624
  with additional information about how to fix automatically-fixable errors. In
611
625
  this mode, all errors that occur on each line are reported (other versions
612
- report only the first error for each rule). *This is the default.*
626
+ report only the first error for each rule). This is the default behavior.
613
627
 
614
628
  ##### options.strings
615
629
 
@@ -754,6 +768,44 @@ Type: `Object`
754
768
 
755
769
  Configuration object.
756
770
 
771
+ ### Fixing
772
+
773
+ Rules that can be fixed automatically include a `fixInfo` property which is
774
+ outlined in the [documentation for custom rules](doc/CustomRules.md#authoring).
775
+ To apply fixes consistently, the `applyFix`/`applyFixes` methods may be used:
776
+
777
+ ```javascript
778
+ /**
779
+ * Applies the specified fix to a Markdown content line.
780
+ *
781
+ * @param {string} line Line of Markdown content.
782
+ * @param {RuleOnErrorFixInfo} fixInfo RuleOnErrorFixInfo instance.
783
+ * @param {string} [lineEnding] Line ending to use.
784
+ * @returns {string | null} Fixed content or null if deleted.
785
+ */
786
+ function applyFix(line, fixInfo, lineEnding = "\n") { ... }
787
+
788
+ /**
789
+ * Applies as many of the specified fixes as possible to Markdown content.
790
+ *
791
+ * @param {string} input Lines of Markdown content.
792
+ * @param {RuleOnErrorInfo[]} errors RuleOnErrorInfo instances.
793
+ * @returns {string} Fixed content.
794
+ */
795
+ function applyFixes(input, errors) { ... }
796
+ ```
797
+
798
+ Invoking `applyFixes` with the results of a call to lint can be done like so:
799
+
800
+ ```javascript
801
+ const { "sync": markdownlintSync, applyFixes } = require("markdownlint");
802
+
803
+ function fixMarkdownlintViolations(content) {
804
+ const fixResults = markdownlintSync({ strings: { content } });
805
+ return applyFixes(content, fixResults.content);
806
+ }
807
+ ```
808
+
757
809
  ## Usage
758
810
 
759
811
  Invoke `markdownlint` and use the `result` object's `toString` method:
@@ -920,14 +972,6 @@ bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be
920
972
  Use --force to continue.
921
973
  ```
922
974
 
923
- ### Fixing
924
-
925
- Rules that can be fixed automatically include a `fixInfo` property which is
926
- outlined in the [documentation for custom rules](doc/CustomRules.md#authoring).
927
- To apply those fixes more easily, the `applyFixes` method in
928
- [markdownlint-rule-helpers](helpers/README.md#applying-recommended-fixes) may
929
- be used.
930
-
931
975
  ## Browser
932
976
 
933
977
  `markdownlint` also works in the browser.
@@ -938,10 +982,11 @@ Generate normal and minified scripts with:
938
982
  npm run build-demo
939
983
  ```
940
984
 
941
- Then reference `markdown-it` and `markdownlint`:
985
+ Then reference `markdownlint` and `micromark` scripts:
942
986
 
943
987
  ```html
944
- <script src="demo/markdown-it.min.js"></script>
988
+ <script src="demo/micromark-browser.js"></script>
989
+ <script src="demo/micromark-html-browser.js"></script>
945
990
  <script src="demo/markdownlint-browser.min.js"></script>
946
991
  ```
947
992
 
@@ -979,6 +1024,11 @@ following projects or one of the tools in the [Related section](#related):
979
1024
  - [webpack][webpack] ([Search repository][webpack-search])
980
1025
  - [WordPress][wordpress] ([Search repository][wordpress-search])
981
1026
 
1027
+ For more advanced integration scenarios:
1028
+
1029
+ - [GitHub Docs content linter][content-linter]
1030
+ - [GitHub's `markdownlint-github` repository][markdownlint-github]
1031
+
982
1032
  [ally-js]: https://allyjs.io/
983
1033
  [ally-js-search]: https://github.com/medialize/ally.js/search?q=markdownlint
984
1034
  [airflow]: https://airflow.apache.org
@@ -987,6 +1037,7 @@ following projects or one of the tools in the [Related section](#related):
987
1037
  [boostnote-search]: https://github.com/BoostIO/Boostnote/search?q=markdownlint
988
1038
  [codimd]: https://github.com/hackmdio/codimd
989
1039
  [codimd-search]: https://github.com/hackmdio/codimd/search?q=markdownlint
1040
+ [content-linter]: https://docs.github.com/en/contributing/collaborating-on-github-docs/using-the-content-linter
990
1041
  [dot-net-doc]: https://docs.microsoft.com/en-us/dotnet/
991
1042
  [dot-net-doc-search]: https://github.com/dotnet/docs/search?q=markdownlint
992
1043
  [electron]: https://www.electronjs.org
@@ -995,6 +1046,7 @@ following projects or one of the tools in the [Related section](#related):
995
1046
  [eslint-search]: https://github.com/eslint/eslint/search?q=markdownlint
996
1047
  [garden]: https://zendeskgarden.github.io/react-components/
997
1048
  [garden-search]: https://github.com/zendeskgarden/react-components/search?q=markdownlint
1049
+ [markdownlint-github]: https://github.com/github/markdownlint-github
998
1050
  [mdn]: https://developer.mozilla.org/
999
1051
  [mdn-search]: https://github.com/mdn/content/search?q=markdownlint
1000
1052
  [mkdocs]: https://www.mkdocs.org/