markdownlint 0.12.0 → 0.14.2

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 (61) hide show
  1. package/.eslintrc.json +52 -275
  2. package/.travis.yml +2 -2
  3. package/LICENSE +1 -1
  4. package/README.md +54 -27
  5. package/doc/CustomRules.md +7 -2
  6. package/doc/Rules.md +120 -33
  7. package/example/standalone.js +2 -2
  8. package/helpers/LICENSE +21 -0
  9. package/helpers/README.md +50 -0
  10. package/{lib/shared.js → helpers/helpers.js} +91 -82
  11. package/helpers/package.json +18 -0
  12. package/lib/cache.js +24 -0
  13. package/lib/markdownlint.js +78 -45
  14. package/lib/md001.js +3 -3
  15. package/lib/md002.js +2 -2
  16. package/lib/md003.js +5 -4
  17. package/lib/md004.js +11 -9
  18. package/lib/md005.js +12 -10
  19. package/lib/md006.js +7 -5
  20. package/lib/md007.js +7 -5
  21. package/lib/md009.js +10 -8
  22. package/lib/md010.js +5 -5
  23. package/lib/md011.js +4 -4
  24. package/lib/md012.js +4 -3
  25. package/lib/md013.js +41 -32
  26. package/lib/md014.js +7 -6
  27. package/lib/md018.js +6 -4
  28. package/lib/md019.js +6 -5
  29. package/lib/md020.js +5 -4
  30. package/lib/md021.js +6 -5
  31. package/lib/md022.js +22 -22
  32. package/lib/md023.js +5 -4
  33. package/lib/md024.js +6 -6
  34. package/lib/md025.js +11 -5
  35. package/lib/md026.js +4 -4
  36. package/lib/md027.js +6 -6
  37. package/lib/md028.js +2 -2
  38. package/lib/md029.js +17 -9
  39. package/lib/md030.js +8 -6
  40. package/lib/md031.js +7 -6
  41. package/lib/md032.js +10 -12
  42. package/lib/md033.js +27 -26
  43. package/lib/md034.js +15 -10
  44. package/lib/md035.js +3 -3
  45. package/lib/md036.js +2 -2
  46. package/lib/md037.js +12 -9
  47. package/lib/md038.js +6 -5
  48. package/lib/md039.js +7 -6
  49. package/lib/md040.js +3 -3
  50. package/lib/md041.js +17 -19
  51. package/lib/md042.js +5 -4
  52. package/lib/md043.js +5 -4
  53. package/lib/md044.js +14 -13
  54. package/lib/md045.js +3 -3
  55. package/lib/md046.js +32 -0
  56. package/lib/md047.js +18 -0
  57. package/lib/rules.js +3 -1
  58. package/package.json +12 -11
  59. package/schema/build-config-schema.js +36 -2
  60. package/schema/markdownlint-config-schema.json +178 -14
  61. package/style/cirosantilli.json +1 -1
package/doc/Rules.md CHANGED
@@ -51,20 +51,24 @@ Aliases: first-heading-h1, first-header-h1
51
51
 
52
52
  Parameters: level (number; default 1)
53
53
 
54
- This rule is triggered when the first heading in the document isn't a h1 heading:
54
+ > Note: *MD002 has been deprecated and is disabled by default.*
55
+ > [MD041/first-line-heading](#md041) offers an improved implementation.
56
+
57
+ This rule is intended to ensure document headings start at the top level and
58
+ is triggered when the first heading in the document isn't an h1 heading:
55
59
 
56
60
  ```markdown
57
- ## This isn't a H1 heading
61
+ ## This isn't an H1 heading
58
62
 
59
63
  ### Another heading
60
64
  ```
61
65
 
62
- The first heading in the document should be a h1 heading:
66
+ The first heading in the document should be an h1 heading:
63
67
 
64
68
  ```markdown
65
- # Start with a H1 heading
69
+ # Start with an H1 heading
66
70
 
67
- ## Then use a H2 for subsections
71
+ ## Then use an H2 for subsections
68
72
  ```
69
73
 
70
74
  Note: The `level` parameter can be used to change the top level (ex: to h2) in
@@ -215,7 +219,6 @@ the same ending column:
215
219
  ...
216
220
  ```
217
221
 
218
-
219
222
  <a name="md006"></a>
220
223
 
221
224
  ## MD006 - Consider starting bulleted lists at the beginning of the line
@@ -294,7 +297,7 @@ when a single space is used after the list marker.
294
297
 
295
298
  Rationale (4 space indent): Same indent as code blocks, simpler for editors to
296
299
  implement. See
297
- <http://www.cirosantilli.com/markdown-styleguide/#indented-lists> for more
300
+ <https://www.cirosantilli.com/markdown-style-guide/#indentation-of-content-inside-lists> for more
298
301
  information.
299
302
 
300
303
  In addition, this is a compatibility issue with multi-markdown parsers, which
@@ -383,13 +386,13 @@ where the syntax appears to have been reversed (the `[]` and `()` are
383
386
  reversed):
384
387
 
385
388
  ```markdown
386
- (Incorrect link syntax)[http://www.example.com/]
389
+ (Incorrect link syntax)[https://www.example.com/]
387
390
  ```
388
391
 
389
392
  To fix this, swap the `[]` and `()` around:
390
393
 
391
394
  ```markdown
392
- [Correct link syntax](http://www.example.com/)
395
+ [Correct link syntax](https://www.example.com/)
393
396
  ```
394
397
 
395
398
  Note: [Markdown Extra](https://en.wikipedia.org/wiki/Markdown_Extra)-style footnotes do not trigger this rule:
@@ -440,13 +443,14 @@ Tags: line_length
440
443
 
441
444
  Aliases: line-length
442
445
 
443
- Parameters: line_length, code_blocks, tables, headings, headers (number; default 80, boolean; default true)
446
+ Parameters: line_length, heading_line_length, code_blocks, tables, headings, headers (number; default 80, boolean; default true)
444
447
 
445
448
  > If `headings` is not provided, `headers` (deprecated) will be used.
446
449
 
447
450
  This rule is triggered when there are lines that are longer than the
448
- configured line length (default: 80 characters). To fix this, split the line
449
- up into multiple lines.
451
+ configured `line_length` (default: 80 characters). To fix this, split the line
452
+ up into multiple lines. To set a different maximum length for headings, use
453
+ `heading_line_length`.
450
454
 
451
455
  This rule has an exception where there is no whitespace beyond the configured
452
456
  line length. This allows you to still include items such as long URLs without
@@ -499,7 +503,7 @@ baz
499
503
 
500
504
  Rationale: it is easier to copy and paste and less noisy if the dollar signs
501
505
  are omitted when they are not needed. See
502
- <http://www.cirosantilli.com/markdown-styleguide/#dollar-signs-in-shell-code>
506
+ <https://www.cirosantilli.com/markdown-style-guide/#dollar-signs-in-shell-code>
503
507
  for more information.
504
508
 
505
509
  <a name="md018"></a>
@@ -619,8 +623,10 @@ Tags: headings, headers, blank_lines
619
623
 
620
624
  Aliases: blanks-around-headings, blanks-around-headers
621
625
 
626
+ Parameters: lines_above, lines_below (number; default 1)
627
+
622
628
  This rule is triggered when headings (any style) are either not preceded or not
623
- followed by a blank line:
629
+ followed by at least one blank line:
624
630
 
625
631
  ```markdown
626
632
  # Heading 1
@@ -647,6 +653,12 @@ Rationale: Aside from aesthetic reasons, some parsers, including kramdown, will
647
653
  not parse headings that don't have a blank line before, and will parse them as
648
654
  regular text.
649
655
 
656
+ The `lines_above` and `lines_below` parameters can be used to specify a different
657
+ number of blank lines (including 0) above or below each heading.
658
+
659
+ Note: If `lines_above` or `lines_below` are configured to require more than one
660
+ blank line, [MD012/no-multiple-blanks](#md012) should also be customized.
661
+
650
662
  <a name="md023"></a>
651
663
 
652
664
  ## MD023 - Headings must start at the beginning of the line
@@ -727,12 +739,12 @@ in change logs):
727
739
 
728
740
  Tags: headings, headers
729
741
 
730
- Aliases: single-h1
742
+ Aliases: single-title, single-h1
731
743
 
732
- Parameters: level (number; default 1)
744
+ Parameters: level, front_matter_title (number; default 1, string; default "^\s*title:")
733
745
 
734
746
  This rule is triggered when a top level heading is in use (the first line of
735
- the file is a h1 heading), and more than one h1 heading is in use in the
747
+ the file is an h1 heading), and more than one h1 heading is in use in the
736
748
  document:
737
749
 
738
750
  ```markdown
@@ -753,7 +765,7 @@ headings:
753
765
  ## Another heading
754
766
  ```
755
767
 
756
- Rationale: A top level heading is a h1 on the first line of the file, and
768
+ Rationale: A top level heading is an h1 on the first line of the file, and
757
769
  serves as the title for the document. If this convention is in use, then there
758
770
  can not be more than one title for the document, and the entire document
759
771
  should be contained within this heading.
@@ -761,6 +773,13 @@ should be contained within this heading.
761
773
  Note: The `level` parameter can be used to change the top level (ex: to h2) in
762
774
  cases where an h1 is added externally.
763
775
 
776
+ If [YAML](https://en.wikipedia.org/wiki/YAML) front matter is present and contains
777
+ a `title` property (commonly used with blog posts), this rule treats that as a top
778
+ level heading and will report a violation for any subsequent top level headings.
779
+ To use a different property name in front matter, specify the text of a regular
780
+ expression via the `front_matter_title` parameter. To disable the use of front
781
+ matter by this rule, specify `""` for `front_matter_title`.
782
+
764
783
  <a name="md026"></a>
765
784
 
766
785
  ## MD026 - Trailing punctuation in heading
@@ -863,11 +882,12 @@ Tags: ol
863
882
 
864
883
  Aliases: ol-prefix
865
884
 
866
- Parameters: style ("one", "ordered", "one_or_ordered"; default "one_or_ordered")
885
+ Parameters: style ("one", "ordered", "one_or_ordered", "zero"; default "one_or_ordered")
867
886
 
868
- This rule is triggered on ordered lists that do not either start with '1.' or
887
+ This rule is triggered for ordered lists that do not either start with '1.' or
869
888
  do not have a prefix that increases in numerical order (depending on the
870
- configured style).
889
+ configured style). The less-common pattern of using '0.' for all prefixes is
890
+ also supported.
871
891
 
872
892
  Example valid list if the style is configured as 'one':
873
893
 
@@ -887,6 +907,14 @@ Example valid list if the style is configured as 'ordered':
887
907
 
888
908
  Both examples are valid when the style is configured as 'one_or_ordered'.
889
909
 
910
+ Example valid list if the style is configured as 'zero':
911
+
912
+ ```markdown
913
+ 0. Do this.
914
+ 0. Do that.
915
+ 0. Done.
916
+ ```
917
+
890
918
  Example invalid list for all styles:
891
919
 
892
920
  ```markdown
@@ -941,7 +969,7 @@ of every item in the list consists of a single paragraph, or multiple
941
969
  paragraphs (including sub-lists and code blocks).
942
970
 
943
971
  For example, the style guide at
944
- <http://www.cirosantilli.com/markdown-styleguide/#spaces-after-marker>
972
+ <https://www.cirosantilli.com/markdown-style-guide/#spaces-after-list-marker>
945
973
  specifies that 1 space after the list marker should be used if every item in
946
974
  the list fits within a single paragraph, but to use 2 or 3 spaces (for ordered
947
975
  and unordered lists respectively) if there are multiple paragraphs of content
@@ -1109,13 +1137,13 @@ This rule is triggered whenever a URL is given that isn't surrounded by angle
1109
1137
  brackets:
1110
1138
 
1111
1139
  ```markdown
1112
- For more information, see http://www.example.com/.
1140
+ For more information, see https://www.example.com/.
1113
1141
  ```
1114
1142
 
1115
1143
  To fix this, add angle brackets around the URL:
1116
1144
 
1117
1145
  ```markdown
1118
- For more information, see <http://www.example.com/>.
1146
+ For more information, see <https://www.example.com/>.
1119
1147
  ```
1120
1148
 
1121
1149
  Rationale: Without angle brackets, the URL isn't converted into a link in many
@@ -1126,7 +1154,7 @@ enclose it in a code block, otherwise in some markdown parsers it _will_ be
1126
1154
  converted:
1127
1155
 
1128
1156
  ```markdown
1129
- `http://www.example.com`
1157
+ `https://www.example.com`
1130
1158
  ```
1131
1159
 
1132
1160
  <a name="md035"></a>
@@ -1294,13 +1322,13 @@ Aliases: no-space-in-links
1294
1322
  This rule is triggered on links that have spaces surrounding the link text:
1295
1323
 
1296
1324
  ```markdown
1297
- [ a link ](http://www.example.com/)
1325
+ [ a link ](https://www.example.com/)
1298
1326
  ```
1299
1327
 
1300
1328
  To fix this, remove the spaces surrounding the link text:
1301
1329
 
1302
1330
  ```markdown
1303
- [a link](http://www.example.com/)
1331
+ [a link](https://www.example.com/)
1304
1332
  ```
1305
1333
 
1306
1334
  <a name="md040"></a>
@@ -1336,18 +1364,18 @@ echo Hello world
1336
1364
 
1337
1365
  Tags: headings, headers
1338
1366
 
1339
- Aliases: first-line-h1
1367
+ Aliases: first-line-heading, first-line-h1
1340
1368
 
1341
1369
  Parameters: level, front_matter_title (number; default 1, string; default "^\s*title:")
1342
1370
 
1343
- This rule is triggered when the first line in the file isn't a top level (h1)
1344
- heading:
1371
+ This rule is intended to ensure documents have a title and is triggered when
1372
+ the first line in the file isn't a top level (h1) heading:
1345
1373
 
1346
1374
  ```markdown
1347
1375
  This is a file without a heading
1348
1376
  ```
1349
1377
 
1350
- To fix this, add a heading to the top of your file:
1378
+ To fix this, add a top level heading to the beginning of the file:
1351
1379
 
1352
1380
  ```markdown
1353
1381
  # File with heading
@@ -1355,10 +1383,10 @@ To fix this, add a heading to the top of your file:
1355
1383
  This is a file with a top level heading
1356
1384
  ```
1357
1385
 
1358
- The `level` parameter can be used to change the top level (ex: to h2) in cases
1386
+ Note: The `level` parameter can be used to change the top level (ex: to h2) in cases
1359
1387
  where an h1 is added externally.
1360
1388
 
1361
- If front matter is present and contains a [YAML](https://en.wikipedia.org/wiki/YAML)
1389
+ If [YAML](https://en.wikipedia.org/wiki/YAML) front matter is present and contains a
1362
1390
  `title` property (commonly used with blog posts), this rule will not report a
1363
1391
  violation. To use a different property name in front matter, specify the text
1364
1392
  of a regular expression via the `front_matter_title` parameter. To disable the
@@ -1516,3 +1544,62 @@ Or with reference syntax as:
1516
1544
  Guidance for writing alternate text is available from the [W3C](https://www.w3.org/WAI/alt/),
1517
1545
  [Wikipedia](https://en.wikipedia.org/wiki/Alt_attribute), and
1518
1546
  [other locations](https://www.phase2technology.com/blog/no-more-excuses-definitive-guide-alt-text-field).
1547
+
1548
+ <a name="md046"></a>
1549
+
1550
+ ## MD046 - Code block style
1551
+
1552
+ Tags: code
1553
+
1554
+ Aliases: code-block-style
1555
+
1556
+ Parameters: style ("consistent", "fenced", "indented"; default "consistent")
1557
+
1558
+ This rule is triggered when unwanted or different code block styles are used in
1559
+ the same document.
1560
+
1561
+ In the default configuration this rule reports a violation for the following document:
1562
+
1563
+ Some text.
1564
+
1565
+ # Indented code
1566
+
1567
+ More text.
1568
+
1569
+ ```ruby
1570
+ # Fenced code
1571
+ ```
1572
+
1573
+ More text.
1574
+
1575
+ To fix violations of this rule, use a consistent style (either indenting or code fences).
1576
+
1577
+ The specified style can be specific (`fenced`, `indented`) or simply require that usage
1578
+ be consistent within the document (`consistent`).
1579
+
1580
+ <a name="md047"></a>
1581
+
1582
+ ## MD047 - Files should end with a single newline character
1583
+
1584
+ Tags: blank_lines
1585
+
1586
+ Aliases: single-trailing-newline
1587
+
1588
+ This rule is triggered when there is not a single newline character at the end of a file.
1589
+
1590
+ Example that triggers the rule:
1591
+
1592
+ ```markdown
1593
+ # Heading
1594
+
1595
+ This file ends without a newline.[EOF]
1596
+ ```
1597
+
1598
+ To fix the violation, add a newline character to the end of the file:
1599
+
1600
+ ```markdown
1601
+ # Heading
1602
+
1603
+ This file ends with a newline.
1604
+ [EOF]
1605
+ ```
@@ -5,8 +5,8 @@ const markdownlint = require("../lib/markdownlint");
5
5
  const options = {
6
6
  "files": [ "good.md", "bad.md" ],
7
7
  "strings": {
8
- "good.string": "# good.string\n\nThis string passes all rules.",
9
- "bad.string": "#bad.string\n\n#This string fails\tsome rules."
8
+ "good.string": "# good.string\n\nThis string passes all rules.\n",
9
+ "bad.string": "#bad.string\n\n#This string fails\tsome rules.\n"
10
10
  }
11
11
  };
12
12
 
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2019 David Anson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # markdownlint-rule-helpers
2
+
3
+ > A collection of `markdownlint` helper functions for custom rules
4
+
5
+ ## Overview
6
+
7
+ The [Markdown](https://en.wikipedia.org/wiki/Markdown) linter
8
+ [`markdownlint`](https://github.com/DavidAnson/markdownlint) offers a variety of built-in validation
9
+ [rules](https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md) and supports the
10
+ creation of [custom rules](https://github.com/DavidAnson/markdownlint/blob/master/doc/CustomRules.md).
11
+ The internal rules share various helper functions; this package exposes those for reuse by custom rules.
12
+
13
+ ## API
14
+
15
+ _Undocumented_ - This package exports the internal functions as-is. The APIs were not originally meant
16
+ to be public, are not officially supported, and may change from release to release. There are brief
17
+ descriptive comments above each function, but no [JSDoc](https://en.m.wikipedia.org/wiki/JSDoc)
18
+ annotations. That said, some of what's here will be useful to custom rule authors and may avoid
19
+ duplicating code.
20
+
21
+ ## Example
22
+
23
+ ```js
24
+ const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
25
+
26
+ module.exports = {
27
+ "names": [ "every-n-lines" ],
28
+ "description": "Rule that reports an error every N lines",
29
+ "tags": [ "test" ],
30
+ "function": (params, onError) => {
31
+ const n = params.config.n || 2;
32
+ forEachLine(getLineMetadata(params), (line, lineIndex) => {
33
+ const lineNumber = lineIndex + 1;
34
+ if ((lineNumber % n) === 0) {
35
+ onError({
36
+ "lineNumber": lineNumber,
37
+ "detail": "Line number " + lineNumber
38
+ });
39
+ }
40
+ });
41
+ }
42
+ };
43
+ ```
44
+
45
+ See also: [`markdownlint` built-in rule implementations](https://github.com/DavidAnson/markdownlint/tree/master/lib).
46
+
47
+ ## Tests
48
+
49
+ _None_ - The entire body of code is tested to 100% coverage by the core `markdownlint` project,
50
+ so there are no additional tests here.