markdownlint 0.26.2 → 0.28.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 (95) hide show
  1. package/CHANGELOG.md +378 -0
  2. package/CONTRIBUTING.md +82 -59
  3. package/LICENSE +1 -1
  4. package/README.md +304 -305
  5. package/demo/markdownlint-browser.js +4973 -3379
  6. package/doc/CustomRules.md +99 -51
  7. package/doc/Prettier.md +14 -10
  8. package/doc/ReleaseProcess.md +20 -0
  9. package/doc/Rules.md +474 -311
  10. package/doc/md001.md +37 -0
  11. package/doc/md002.md +37 -0
  12. package/doc/md003.md +59 -0
  13. package/doc/md004.md +49 -0
  14. package/doc/md005.md +53 -0
  15. package/doc/md006.md +46 -0
  16. package/doc/md007.md +55 -0
  17. package/doc/md009.md +51 -0
  18. package/doc/md010.md +56 -0
  19. package/doc/md011.md +30 -0
  20. package/doc/md012.md +38 -0
  21. package/doc/md013.md +60 -0
  22. package/doc/md014.md +54 -0
  23. package/doc/md018.md +27 -0
  24. package/doc/md019.md +28 -0
  25. package/doc/md020.md +29 -0
  26. package/doc/md021.md +31 -0
  27. package/doc/md022.md +46 -0
  28. package/doc/md023.md +26 -0
  29. package/doc/md024.md +47 -0
  30. package/doc/md025.md +49 -0
  31. package/doc/md026.md +41 -0
  32. package/doc/md027.md +24 -0
  33. package/doc/md028.md +40 -0
  34. package/doc/md029.md +98 -0
  35. package/doc/md030.md +82 -0
  36. package/doc/md031.md +50 -0
  37. package/doc/md032.md +38 -0
  38. package/doc/md033.md +27 -0
  39. package/doc/md034.md +50 -0
  40. package/doc/md035.md +42 -0
  41. package/doc/md036.md +45 -0
  42. package/doc/md037.md +37 -0
  43. package/doc/md038.md +40 -0
  44. package/doc/md039.md +21 -0
  45. package/doc/md040.md +52 -0
  46. package/doc/md041.md +49 -0
  47. package/doc/md042.md +32 -0
  48. package/doc/md043.md +72 -0
  49. package/doc/md044.md +35 -0
  50. package/doc/md045.md +34 -0
  51. package/doc/md046.md +40 -0
  52. package/doc/md047.md +34 -0
  53. package/doc/md048.md +41 -0
  54. package/doc/md049.md +32 -0
  55. package/doc/md050.md +32 -0
  56. package/doc/md051.md +50 -0
  57. package/doc/md052.md +33 -0
  58. package/doc/md053.md +38 -0
  59. package/helpers/LICENSE +1 -1
  60. package/helpers/README.md +35 -15
  61. package/helpers/helpers.js +182 -162
  62. package/helpers/micromark.cjs +209 -0
  63. package/helpers/package.json +5 -2
  64. package/lib/constants.js +8 -1
  65. package/lib/markdownlint.d.ts +5 -5
  66. package/lib/markdownlint.js +46 -24
  67. package/lib/md002.js +1 -1
  68. package/lib/md011.js +2 -2
  69. package/lib/md013.js +7 -6
  70. package/lib/md019.js +1 -1
  71. package/lib/md022.js +15 -3
  72. package/lib/md023.js +1 -1
  73. package/lib/md026.js +1 -1
  74. package/lib/md027.js +1 -1
  75. package/lib/md028.js +1 -1
  76. package/lib/md033.js +47 -29
  77. package/lib/md034.js +54 -47
  78. package/lib/md035.js +9 -11
  79. package/lib/md036.js +1 -1
  80. package/lib/md037.js +2 -2
  81. package/lib/md038.js +81 -56
  82. package/lib/md039.js +1 -1
  83. package/lib/md040.js +21 -2
  84. package/lib/md041.js +1 -1
  85. package/lib/md043.js +4 -2
  86. package/lib/md044.js +58 -43
  87. package/lib/md046.js +1 -1
  88. package/lib/md048.js +3 -1
  89. package/lib/md051.js +37 -5
  90. package/lib/rules.js +1 -1
  91. package/package.json +43 -28
  92. package/schema/.markdownlint.jsonc +11 -4
  93. package/schema/.markdownlint.yaml +11 -6
  94. package/schema/markdownlint-config-schema.json +27 -3
  95. package/style/prettier.json +26 -0
@@ -1,27 +1,40 @@
1
1
  # Custom Rules
2
2
 
3
- In addition to its built-in rules, `markdownlint` lets you enhance the linting experience by passing a list of custom rules using the
4
- [`options.customRules` property](../README.md#optionscustomrules).
5
- Custom rules can do everything the built-in rules can and are defined inline or imported from another package
6
- ([keyword `markdownlint-rule` on npm](https://www.npmjs.com/search?q=keywords:markdownlint-rule)).
7
- Custom rules can be disabled, enabled, and customized using the same syntax as built-in rules.
3
+ In addition to its built-in rules, `markdownlint` lets you enhance the linting
4
+ experience by passing a list of custom rules using the [`options.customRules`
5
+ property][options-custom-rules]. Custom rules can do everything the built-in
6
+ rules can and are defined inline or imported from another package ([keyword
7
+ `markdownlint-rule` on npm][markdownlint-rule]). Custom rules can be disabled,
8
+ enabled, and customized using the same syntax as built-in rules.
9
+
10
+ ## Implementing Simple Rules
11
+
12
+ For simple requirements like disallowing certain characters or patterns,
13
+ the community-developed
14
+ [markdownlint-rule-search-replace][markdownlint-rule-search-replace]
15
+ plug-in can be used.
16
+ This plug-in allows anyone to create a set of simple text-replacement rules in
17
+ JSON without needing to write any code.
18
+
19
+ [markdownlint-rule-search-replace]: https://www.npmjs.com/package/markdownlint-rule-search-replace
8
20
 
9
21
  ## Authoring
10
22
 
11
- Rules are defined by a name (or multiple names), a description, an optional link to more information, one or more tags, and a function that implements
12
- the rule's behavior.
13
- That function is called once for each file/string input and is passed the parsed input and a function to log any violations.
23
+ Rules are defined by a name (or multiple names), a description, an optional link
24
+ to more information, one or more tags, and a function that implements the rule's
25
+ behavior. That function is called once for each file/string input and is passed
26
+ the parsed input and a function to log any violations.
14
27
 
15
28
  A simple rule implementation looks like:
16
29
 
17
- ```js
30
+ ```javascript
18
31
  module.exports = {
19
32
  "names": [ "any-blockquote" ],
20
33
  "description": "Rule that reports an error for any blockquote",
21
34
  "information": new URL("https://example.com/rules/any-blockquote"),
22
35
  "tags": [ "test" ],
23
36
  "function": function rule(params, onError) {
24
- params.tokens.filter(function filterToken(token) {
37
+ params.parsers.markdownit.tokens.filter(function filterToken(token) {
25
38
  return token.type === "blockquote_open";
26
39
  }).forEach(function forToken(blockquote) {
27
40
  var lines = blockquote.map[1] - blockquote.map[0];
@@ -35,62 +48,85 @@ module.exports = {
35
48
  };
36
49
  ```
37
50
 
38
- A rule is implemented as an `Object` with one optional and four required properties:
51
+ A rule is implemented as an `Object` with one optional and four required
52
+ properties:
39
53
 
40
- - `names` is a required `Array` of `String` values that identify the rule in output messages and config.
41
- - `description` is a required `String` value that describes the rule in output messages.
42
- - `information` is an optional (absolute) `URL` of a link to more information about the rule.
43
- - `tags` is a required `Array` of `String` values that groups related rules for easier customization.
44
- - `asynchronous` is an optional `Boolean` value that indicates whether the rule returns a `Promise` and runs asynchronously.
45
- - `function` is a required `Function` that implements the rule and is passed two parameters:
46
- - `params` is an `Object` with properties that describe the content being analyzed:
54
+ - `names` is a required `Array` of `String` values that identify the rule in
55
+ output messages and config.
56
+ - `description` is a required `String` value that describes the rule in output
57
+ messages.
58
+ - `information` is an optional (absolute) `URL` of a link to more information
59
+ about the rule.
60
+ - `tags` is a required `Array` of `String` values that groups related rules for
61
+ easier customization.
62
+ - `asynchronous` is an optional `Boolean` value that indicates whether the rule
63
+ returns a `Promise` and runs asynchronously.
64
+ - `function` is a required `Function` that implements the rule and is passed two
65
+ parameters:
66
+ - `params` is an `Object` with properties that describe the content being
67
+ analyzed:
47
68
  - `name` is a `String` that identifies the input file/string.
48
- - `tokens` is an `Array` of [`markdown-it` `Token` objects](https://markdown-it.github.io/markdown-it/#Token)
49
- with added `line` and `lineNumber` properties.
50
- - `lines` is an `Array` of `String` values corresponding to the lines of the input file/string.
51
- - `frontMatterLines` is an `Array` of `String` values corresponding to any front matter (not present in `lines`).
52
- - `config` is an `Object` corresponding to the rule's entry in `options.config` (if present).
53
- - `onError` is a function that takes a single `Object` parameter with one required and four optional properties:
54
- - `lineNumber` is a required `Number` specifying the 1-based line number of the error.
55
- - `detail` is an optional `String` with information about what caused the error.
56
- - `context` is an optional `String` with relevant text surrounding the error location.
57
- - `range` is an optional `Array` with two `Number` values identifying the 1-based column and length of the error.
58
- - `fixInfo` is an optional `Object` with information about how to fix the error (all properties are optional, but
59
- at least one of `deleteCount` and `insertText` should be present; when applying a fix, the delete should be
69
+ - `tokens` is an `Array` of [`markdown-it` `Token`s][markdown-it-token] with
70
+ added `line` and `lineNumber` properties.
71
+ - `lines` is an `Array` of `String` values corresponding to the lines of the
72
+ input file/string.
73
+ - `frontMatterLines` is an `Array` of `String` values corresponding to any
74
+ front matter (not present in `lines`).
75
+ - `config` is an `Object` corresponding to the rule's entry in
76
+ `options.config` (if present).
77
+ - `onError` is a function that takes a single `Object` parameter with one
78
+ required and four optional properties:
79
+ - `lineNumber` is a required `Number` specifying the 1-based line number of
80
+ the error.
81
+ - `detail` is an optional `String` with information about what caused the
82
+ error.
83
+ - `context` is an optional `String` with relevant text surrounding the error
84
+ location.
85
+ - `range` is an optional `Array` with two `Number` values identifying the
86
+ 1-based column and length of the error.
87
+ - `fixInfo` is an optional `Object` with information about how to fix the
88
+ error (all properties are optional, but at least one of `deleteCount` and
89
+ `insertText` should be present; when applying a fix, the delete should be
60
90
  performed before the insert):
61
- - `lineNumber` is an optional `Number` specifying the 1-based line number of the edit.
62
- - `editColumn` is an optional `Number` specifying the 1-based column number of the edit.
63
- - `deleteCount` is an optional `Number` specifying the number of characters to delete (the value `-1` is used to delete the line).
64
- - `insertText` is an optional `String` specifying the text to insert. `\n` is the platform-independent way to add
65
- a line break; line breaks should be added at the beginning of a line instead of at the end).
91
+ - `lineNumber` is an optional `Number` specifying the 1-based line number
92
+ of the edit.
93
+ - `editColumn` is an optional `Number` specifying the 1-based column
94
+ number of the edit.
95
+ - `deleteCount` is an optional `Number` specifying the number of
96
+ characters to delete (the value `-1` is used to delete the line).
97
+ - `insertText` is an optional `String` specifying the text to insert. `\n`
98
+ is the platform-independent way to add a line break; line breaks should
99
+ be added at the beginning of a line instead of at the end.
66
100
 
67
- The collection of helper functions shared by the built-in rules is available for use by custom rules in the
68
- [markdownlint-rule-helpers package](https://www.npmjs.com/package/markdownlint-rule-helpers).
101
+ The collection of helper functions shared by the built-in rules is available for
102
+ use by custom rules in the [markdownlint-rule-helpers package][rule-helpers].
69
103
 
70
104
  ### Asynchronous Rules
71
105
 
72
- If a rule needs to perform asynchronous operations (such as fetching a network resource), it can specify the value `true` for its `asynchronous` property.
73
- Asynchronous rules should return a `Promise` from their `function` implementation that is resolved when the rule completes.
74
- (The value passed to `resolve(...)` is ignored.)
75
- Linting violations from asynchronous rules are reported via the `onError` function just like for synchronous rules.
106
+ If a rule needs to perform asynchronous operations (such as fetching a network
107
+ resource), it can specify the value `true` for its `asynchronous` property.
108
+ Asynchronous rules should return a `Promise` from their `function`
109
+ implementation that is resolved when the rule completes. (The value passed to
110
+ `resolve(...)` is ignored.) Linting violations from asynchronous rules are
111
+ reported via the `onError` function just like for synchronous rules.
76
112
 
77
- **Note**: Asynchronous rules cannot be referenced in a synchronous calling context (i.e., `markdownlint.sync(...)`).
78
- Attempting to do so throws an exception.
113
+ **Note**: Asynchronous rules cannot be referenced in a synchronous calling
114
+ context (i.e., `markdownlint.sync(...)`). Attempting to do so throws an
115
+ exception.
79
116
 
80
117
  ## Examples
81
118
 
82
- - [Simple rules used by the project's test cases](../test/rules)
83
- - [Code for all `markdownlint` built-in rules](../lib)
84
- - [Package configuration for publishing to npm](../test/rules/npm)
119
+ - [Simple rules used by the project's test cases][test-rules]
120
+ - [Code for all `markdownlint` built-in rules][lib]
121
+ - [Package configuration for publishing to npm][test-rules-npm]
85
122
  - Packages should export a single rule object or an `Array` of rule objects
86
- - [Custom rules from the Microsoft/vscode-docs-authoring repository](https://github.com/microsoft/vscode-docs-authoring/tree/main/packages/docs-linting/markdownlint-custom-rules)
87
- - [Custom rules from the axibase/docs-util repository](https://github.com/axibase/docs-util/tree/master/linting-rules)
88
- - [Custom rules from the webhintio/hint repository](https://github.com/webhintio/hint/blob/main/scripts/lint-markdown.js)
123
+ - [Custom rules from the axibase/docs-util repository][docs-util]
124
+ - [Custom rules from the webhintio/hint repository][hint]
89
125
 
90
126
  ## References
91
127
 
92
- - [CommonMark documentation and specification](https://commonmark.org/)
93
- - [`markdown-it` Markdown parser project page](https://github.com/markdown-it/markdown-it)
128
+ - [CommonMark documentation and specification][commonmark]
129
+ - [`markdown-it` Markdown parser project page][markdown-it]
94
130
 
95
131
  ## Params
96
132
 
@@ -324,3 +360,15 @@ Yields the `params` object:
324
360
  }
325
361
  }
326
362
  ```
363
+
364
+ [commonmark]: https://commonmark.org/
365
+ [docs-util]: https://github.com/axibase/docs-util/tree/master/linting-rules
366
+ [hint]: https://github.com/webhintio/hint/blob/main/scripts/lint-markdown.js
367
+ [lib]: ../lib
368
+ [markdown-it]: https://github.com/markdown-it/markdown-it
369
+ [markdown-it-token]: https://markdown-it.github.io/markdown-it/#Token
370
+ [markdownlint-rule]: https://www.npmjs.com/search?q=keywords:markdownlint-rule
371
+ [rule-helpers]: https://www.npmjs.com/package/markdownlint-rule-helpers
372
+ [options-custom-rules]: ../README.md#optionscustomrules
373
+ [test-rules]: ../test/rules
374
+ [test-rules-npm]: ../test/rules/npm
package/doc/Prettier.md CHANGED
@@ -1,23 +1,27 @@
1
- # Using markdownlint with Prettier
1
+ # Using `markdownlint` with Prettier
2
2
 
3
- [`Prettier`](https://prettier.io) is a popular code formatter. For the most part,
4
- it works seamlessly with `markdownlint`. Special situations are documented
5
- below.
3
+ [`Prettier`](https://prettier.io) is a popular code formatter.
4
+ For the most part, Prettier works seamlessly with `markdownlint`.
5
+
6
+ You can `extend` the [`prettier.json`](../style/prettier.json) style to disable
7
+ all `markdownlint` rules that overlap with Prettier.
8
+
9
+ Other scenarios are documented below.
6
10
 
7
11
  ## List item indentation
8
12
 
9
13
  The default settings of `markdownlint` and `Prettier` are compatible and don't
10
14
  result in any linting violations. If `Prettier` is used with `--tab-width` set
11
- to `4`, the following `markdownlint` configuration can be used:
15
+ to `4` (vs. `2`), the following `markdownlint` configuration can be used:
12
16
 
13
17
  ```json
14
18
  {
15
- "MD007": {
16
- "indent": 4
19
+ "list-marker-space": {
20
+ "ul_multi": 3,
21
+ "ul_single": 3
17
22
  },
18
- "MD030": {
19
- "ul_single": 3,
20
- "ul_multi": 3
23
+ "ul-indent": {
24
+ "indent": 4
21
25
  }
22
26
  }
23
27
  ```
@@ -0,0 +1,20 @@
1
+ # Release Process
2
+
3
+ The `markdownlint` library has some related dependencies that are updated along
4
+ with it. To prevent possible regressions from having a widespread impact, these
5
+ releases are separated by a few days to provide an opportunity to find issues.
6
+
7
+ 1. [`markdownlint`][markdownlint]
8
+ 2. [`markdownlint-cli2`][markdownlint-cli2]
9
+ 3. [`markdownlint-cli2-action`][markdownlint-cli2-action]
10
+ 4. [`vscode-markdownlint`][vscode-markdownlint]
11
+ 5. [`markdownlint-cli`][markdownlint-cli]
12
+
13
+ This sequence is not strict and may be adjusted based on the content of the
14
+ release and the scope of feature work in each dependency.
15
+
16
+ [markdownlint]: https://github.com/DavidAnson/markdownlint
17
+ [markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
18
+ [markdownlint-cli2-action]: https://github.com/marketplace/actions/markdownlint-cli2-action
19
+ [vscode-markdownlint]: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
20
+ [markdownlint-cli]: https://github.com/igorshubovych/markdownlint-cli