mdl 0.5.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mdl +2 -2
  3. data/lib/mdl.rb +49 -40
  4. data/lib/mdl/cli.rb +92 -90
  5. data/lib/mdl/config.rb +2 -1
  6. data/lib/mdl/doc.rb +52 -59
  7. data/lib/mdl/kramdown_parser.rb +1 -1
  8. data/lib/mdl/rules.rb +224 -169
  9. data/lib/mdl/ruleset.rb +11 -10
  10. data/lib/mdl/style.rb +30 -8
  11. data/lib/mdl/styles/cirosantilli.rb +2 -2
  12. data/lib/mdl/styles/default.rb +1 -1
  13. data/lib/mdl/version.rb +1 -1
  14. data/mdl.gemspec +23 -20
  15. metadata +85 -289
  16. data/.gitignore +0 -13
  17. data/.travis.yml +0 -23
  18. data/CHANGELOG.md +0 -187
  19. data/README.md +0 -86
  20. data/Rakefile +0 -8
  21. data/docs/RULES.md +0 -1047
  22. data/docs/configuration.md +0 -99
  23. data/docs/creating_rules.md +0 -90
  24. data/docs/creating_styles.md +0 -47
  25. data/docs/rolling_a_release.md +0 -49
  26. data/example/markdown_spec.md +0 -897
  27. data/test/fixtures/default_mdlrc +0 -1
  28. data/test/fixtures/dir_with_md_and_markdown/bar.markdown +0 -1
  29. data/test/fixtures/dir_with_md_and_markdown/foo.md +0 -1
  30. data/test/fixtures/front_matter/jekyll_post.md +0 -16
  31. data/test/fixtures/mdlrc_disable_rules +0 -1
  32. data/test/fixtures/mdlrc_disable_tags +0 -1
  33. data/test/fixtures/mdlrc_enable_rules +0 -1
  34. data/test/fixtures/mdlrc_enable_tags +0 -1
  35. data/test/fixtures/my_ruleset.rb +0 -6
  36. data/test/rule_tests/alternate_top_level_header.md +0 -3
  37. data/test/rule_tests/alternate_top_level_header_style.rb +0 -4
  38. data/test/rule_tests/atx_closed_header_spacing.md +0 -17
  39. data/test/rule_tests/atx_header_spacing.md +0 -5
  40. data/test/rule_tests/blockquote_blank_lines.md +0 -31
  41. data/test/rule_tests/blockquote_spaces.md +0 -23
  42. data/test/rule_tests/bulleted_list_2_space_indent.md +0 -6
  43. data/test/rule_tests/bulleted_list_2_space_indent_style.rb +0 -3
  44. data/test/rule_tests/bulleted_list_4_space_indent.md +0 -3
  45. data/test/rule_tests/bulleted_list_not_at_beginning_of_line.md +0 -14
  46. data/test/rule_tests/code_block_consistency.md +0 -11
  47. data/test/rule_tests/code_block_consistency_style.rb +0 -1
  48. data/test/rule_tests/code_block_dollar.md +0 -33
  49. data/test/rule_tests/code_block_dollar_fence.md +0 -29
  50. data/test/rule_tests/code_block_fenced.md +0 -17
  51. data/test/rule_tests/code_block_fenced_style.rb +0 -1
  52. data/test/rule_tests/code_block_indented.md +0 -17
  53. data/test/rule_tests/code_block_indented_style.rb +0 -1
  54. data/test/rule_tests/consecutive_blank_lines.md +0 -11
  55. data/test/rule_tests/consistent_bullet_styles_asterisk.md +0 -3
  56. data/test/rule_tests/consistent_bullet_styles_dash.md +0 -3
  57. data/test/rule_tests/consistent_bullet_styles_plus.md +0 -3
  58. data/test/rule_tests/default_test_style.rb +0 -5
  59. data/test/rule_tests/emphasis_instead_of_headers.md +0 -40
  60. data/test/rule_tests/empty_doc.md +0 -0
  61. data/test/rule_tests/fenced_code_blocks.md +0 -27
  62. data/test/rule_tests/fenced_code_with_nesting.md +0 -73
  63. data/test/rule_tests/fenced_code_without_blank_lines.md +0 -42
  64. data/test/rule_tests/fenced_code_without_blank_lines_style.rb +0 -3
  65. data/test/rule_tests/first_header_bad_atx.md +0 -1
  66. data/test/rule_tests/first_header_bad_setext.md +0 -2
  67. data/test/rule_tests/first_header_good_atx.md +0 -1
  68. data/test/rule_tests/first_header_good_setext.md +0 -2
  69. data/test/rule_tests/first_line_top_level_header_atx.md +0 -3
  70. data/test/rule_tests/first_line_top_level_header_atx_style.rb +0 -2
  71. data/test/rule_tests/first_line_top_level_header_setext.md +0 -4
  72. data/test/rule_tests/first_line_top_level_header_setext_style.rb +0 -2
  73. data/test/rule_tests/fix_102_extra_nodes_in_link_text.md +0 -8
  74. data/test/rule_tests/header_duplicate_content.md +0 -11
  75. data/test/rule_tests/header_duplicate_content_different_nesting.md +0 -11
  76. data/test/rule_tests/header_duplicate_content_different_nesting_style.rb +0 -1
  77. data/test/rule_tests/header_duplicate_content_no_different_nesting.md +0 -13
  78. data/test/rule_tests/header_multiple_toplevel.md +0 -3
  79. data/test/rule_tests/header_mutliple_h1_no_toplevel.md +0 -5
  80. data/test/rule_tests/header_trailing_punctuation.md +0 -11
  81. data/test/rule_tests/header_trailing_punctuation_customized.md +0 -14
  82. data/test/rule_tests/header_trailing_punctuation_customized_style.rb +0 -2
  83. data/test/rule_tests/headers_bad.md +0 -7
  84. data/test/rule_tests/headers_good.md +0 -5
  85. data/test/rule_tests/headers_good_setext_with_atx.md +0 -7
  86. data/test/rule_tests/headers_good_setext_with_atx_style.rb +0 -2
  87. data/test/rule_tests/headers_good_with_issue_numbers.md +0 -12
  88. data/test/rule_tests/headers_surrounding_space_atx.md +0 -12
  89. data/test/rule_tests/headers_surrounding_space_setext.md +0 -15
  90. data/test/rule_tests/headers_with_spaces_at_the_beginning.md +0 -20
  91. data/test/rule_tests/hr_style_dashes.md +0 -22
  92. data/test/rule_tests/hr_style_dashes_style.rb +0 -3
  93. data/test/rule_tests/hr_style_inconsistent.md +0 -22
  94. data/test/rule_tests/hr_style_long.md +0 -22
  95. data/test/rule_tests/hr_style_long_style.rb +0 -3
  96. data/test/rule_tests/hr_style_stars.md +0 -22
  97. data/test/rule_tests/hr_style_stars_style.rb +0 -3
  98. data/test/rule_tests/inconsistent_bullet_indent_same_level.md +0 -4
  99. data/test/rule_tests/inconsistent_bullet_styles_asterisk.md +0 -3
  100. data/test/rule_tests/inconsistent_bullet_styles_dash.md +0 -3
  101. data/test/rule_tests/inconsistent_bullet_styles_plus.md +0 -3
  102. data/test/rule_tests/incorrect_bullet_style_asterisk.md +0 -3
  103. data/test/rule_tests/incorrect_bullet_style_asterisk_style.rb +0 -3
  104. data/test/rule_tests/incorrect_bullet_style_dash.md +0 -3
  105. data/test/rule_tests/incorrect_bullet_style_dash_style.rb +0 -3
  106. data/test/rule_tests/incorrect_bullet_style_plus.md +0 -3
  107. data/test/rule_tests/incorrect_bullet_style_plus_style.rb +0 -3
  108. data/test/rule_tests/incorrect_header_atx.md +0 -6
  109. data/test/rule_tests/incorrect_header_atx_closed.md +0 -6
  110. data/test/rule_tests/incorrect_header_atx_closed_style.rb +0 -2
  111. data/test/rule_tests/incorrect_header_atx_style.rb +0 -2
  112. data/test/rule_tests/incorrect_header_setext.md +0 -6
  113. data/test/rule_tests/incorrect_header_setext_style.rb +0 -2
  114. data/test/rule_tests/inline_html.md +0 -13
  115. data/test/rule_tests/links.md +0 -9
  116. data/test/rule_tests/lists_without_blank_lines.md +0 -75
  117. data/test/rule_tests/long_lines.md +0 -3
  118. data/test/rule_tests/long_lines_100.md +0 -7
  119. data/test/rule_tests/long_lines_100_style.rb +0 -3
  120. data/test/rule_tests/long_lines_code.md +0 -45
  121. data/test/rule_tests/long_lines_code_style.rb +0 -3
  122. data/test/rule_tests/mixed_header_types_atx.md +0 -6
  123. data/test/rule_tests/mixed_header_types_atx_closed.md +0 -6
  124. data/test/rule_tests/mixed_header_types_setext.md +0 -6
  125. data/test/rule_tests/no_first_line_header.md +0 -1
  126. data/test/rule_tests/no_first_line_header_style.rb +0 -1
  127. data/test/rule_tests/no_first_line_top_level_header.md +0 -1
  128. data/test/rule_tests/no_first_line_top_level_header_style.rb +0 -1
  129. data/test/rule_tests/ordered_list_item_prefix.md +0 -13
  130. data/test/rule_tests/ordered_list_item_prefix_ordered.md +0 -13
  131. data/test/rule_tests/ordered_list_item_prefix_ordered_style.rb +0 -3
  132. data/test/rule_tests/reversed_link.md +0 -7
  133. data/test/rule_tests/spaces_after_list_marker.md +0 -74
  134. data/test/rule_tests/spaces_after_list_marker_style.rb +0 -5
  135. data/test/rule_tests/spaces_inside_codespan_elements.md +0 -7
  136. data/test/rule_tests/spaces_inside_emphasis_markers.md +0 -35
  137. data/test/rule_tests/spaces_inside_link_text.md +0 -10
  138. data/test/rule_tests/trailing_spaces_br.md +0 -4
  139. data/test/rule_tests/trailing_spaces_br_style.rb +0 -3
  140. data/test/rule_tests/whitespace_issues.md +0 -3
  141. data/test/setup_tests.rb +0 -5
  142. data/test/test_cli.rb +0 -300
  143. data/test/test_ruledocs.rb +0 -52
  144. data/test/test_rules.rb +0 -58
  145. data/tools/README.md +0 -3
  146. data/tools/docker/Dockerfile +0 -13
  147. data/tools/docker/README.md +0 -19
  148. data/tools/test_location.rb +0 -20
  149. data/tools/view_markdown.rb +0 -11
@@ -1,2 +0,0 @@
1
- all
2
- rule 'MD003', :style => :atx_closed
@@ -1,2 +0,0 @@
1
- all
2
- rule 'MD003', :style => :atx
@@ -1,6 +0,0 @@
1
- # Header 1 {MD003} #
2
-
3
- ## Header 2 {MD003}
4
-
5
- Header 3
6
- --------
@@ -1,2 +0,0 @@
1
- all
2
- rule 'MD003', :style => :setext
@@ -1,13 +0,0 @@
1
- # Regular header
2
-
3
- <h1>Inline HTML Header {MD033}</h1>
4
-
5
- <p>More inline HTML {MD033}
6
- but this time on multiple lines
7
- </p>
8
-
9
- <h1>This shouldn't trigger as it's inside a code block</h1>
10
-
11
- ```text
12
- <p>Neither should this as it's also in a code block</p>
13
- ```
@@ -1,9 +0,0 @@
1
- # Link test
2
-
3
- For more information, please see the
4
- following page: http://www.example.com/ {MD034}
5
- which will tell you all you want to know.
6
-
7
- http://www.google.com/ {MD034}
8
-
9
- This link should be fine: <http://www.google.com/>
@@ -1,75 +0,0 @@
1
- * list (on first line)
2
-
3
- text
4
-
5
- * list
6
-
7
- text
8
- * list {MD032}
9
- text
10
- + list {MD032}
11
- text
12
- - list {MD032}
13
- text
14
- 1. list {MD032}
15
- text
16
-
17
- * list
18
- * list {MD032}
19
- text
20
-
21
- text
22
- 10. list {MD032}
23
- 20. list
24
-
25
- text
26
-
27
- * list
28
- * list
29
- * list
30
-
31
- text
32
-
33
- * list
34
- with hanging indent
35
- * list
36
- with hanging indent
37
- * list
38
- with hanging indent
39
-
40
- Note: list without hanging indent violates MD032
41
-
42
- * list
43
-
44
- item with blank lines
45
-
46
- * list
47
-
48
- item with blank lines
49
-
50
- text
51
-
52
- ```js
53
- /*
54
- * code block
55
- * not a list
56
- */
57
- ```
58
-
59
- text
60
-
61
- * list {MD032}
62
- ``` {MD031}
63
- code
64
- ```
65
-
66
- text
67
-
68
- ```
69
- code
70
- ``` {MD031}
71
- * list {MD032}
72
-
73
- text
74
-
75
- * list (on last line without newline)
@@ -1,3 +0,0 @@
1
- This is a very very very very very very very very very very very very very very long line {MD013}
2
-
3
- This line however, while very long, doesn't have whitespace after the 80th columnwhichallowsforURLsandotherlongthings.
@@ -1,7 +0,0 @@
1
- This is a very very very very very very very very long line over 80 chars but less than 100
2
-
3
- This is a very very very very very very very very very very long line over 80 chars, and also over 100. {MD013}
4
-
5
- This is a very very very very very very very very very long line that is exactly 100 characters long
6
-
7
- This line however, while very long, doesn't have whitespace after the 100th columnwhichallowsforURLsandotherlongthings.
@@ -1,3 +0,0 @@
1
- all
2
- rule 'MD013', :line_length => 100
3
- exclude_rule "MD041"
@@ -1,45 +0,0 @@
1
- This is a short line.
2
-
3
- This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
4
-
5
- This is a short line.
6
-
7
- ```text
8
- Here is a short line in a code block.
9
- Here is a very very very very very very very very very very very very very very very very very very very long line in a code block.
10
- ```
11
-
12
- ```text
13
- test
14
- test
15
-
16
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
17
- ```
18
-
19
- This is a short line.
20
-
21
- | First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header |
22
- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
23
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
24
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
25
- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
26
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
27
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
28
- | ============= | ============= | ============= | ============= | ============= | ============= |
29
- | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
30
- {: rules="groups"}
31
-
32
- This is a very very very very very very very very very very very very very very very very very very very very long line. {MD013}
33
-
34
- Another line.
35
-
36
- | First Header | Second Header | Third Header | Fourth Header | Fifth Header | Sixth Header |
37
- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
38
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
39
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
40
- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
41
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
42
- | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell | Content Cell |
43
- | ============= | ============= | ============= | ============= | ============= | ============= |
44
- | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell | Footer Cell |
45
- {: rules="groups"}
@@ -1,3 +0,0 @@
1
- all
2
- rule 'MD013', :code_blocks => false, :tables => false
3
- exclude_rule "MD041"
@@ -1,6 +0,0 @@
1
- # Header
2
-
3
- ## Header 2 {MD003} ##
4
-
5
- Header 3 {MD003}
6
- ----------------
@@ -1,6 +0,0 @@
1
- # Header 1 #
2
-
3
- ## Header 2 {MD003}
4
-
5
- Header 3 {MD003}
6
- ----------------
@@ -1,6 +0,0 @@
1
- Header 1
2
- ========
3
-
4
- ## Header 2 {MD003}
5
-
6
- ## Header 3 {MD003} ##
@@ -1 +0,0 @@
1
- This is a file without a top level header {MD041}
@@ -1 +0,0 @@
1
- ## Second level header {MD041} {MD002}
@@ -1,13 +0,0 @@
1
- Good list:
2
-
3
- 1. Do this.
4
- 1. Do that.
5
- 1. ???
6
- 1. Profit!
7
-
8
- Bad list:
9
-
10
- 1. Do this.
11
- 2. Do nothing. {MD029}
12
- 3. ??? {MD029}
13
- 4. Failed! {MD029}
@@ -1,13 +0,0 @@
1
- Good list:
2
-
3
- 1. Do this.
4
- 2. Do that.
5
- 3. ???
6
- 4. Profit!
7
-
8
- Bad list:
9
-
10
- 1. Do this.
11
- 1. Do nothing. {MD029}
12
- 1. ??? {MD029}
13
- 1. Failed! {MD029}
@@ -1,3 +0,0 @@
1
- all
2
- rule 'MD029', :style => :ordered
3
- exclude_rule 'MD041'
@@ -1,7 +0,0 @@
1
- Go to (this website)[http://www.example.com] {MD011} {MD034}
2
-
3
- However, this shouldn't trigger inside code blocks:
4
-
5
- myObj.getFiles("test")[0]
6
-
7
- Nor inline code: `myobj.getFiles("test")[0]`
@@ -1,74 +0,0 @@
1
- Normal list
2
-
3
- * Foo
4
- * Bar
5
- * Baz
6
-
7
- List with incorrect spacing
8
-
9
- * Foo {MD030}
10
- * Bar {MD030}
11
- * Baz {MD030}
12
-
13
- List with children:
14
-
15
- * Foo {MD030}
16
- * Bar {MD030}
17
- * Baz
18
-
19
- List with children and correct spacing:
20
-
21
- * Foo
22
- * Bar
23
- * Baz (This sublist has no children)
24
-
25
- List with Multiple paragraphs and correct spacing
26
-
27
- * Foo
28
-
29
- Here is the second paragraph
30
-
31
- * All items in the list need the same indent
32
-
33
- List with multiple paragraphs and incorrect spacing
34
-
35
- * Foo {MD030}
36
-
37
- Here is the second paragraph
38
-
39
- * Bar {MD030}
40
-
41
- List with code blocks:
42
-
43
- * Foo
44
-
45
- Here is some code
46
-
47
- * Bar
48
-
49
- Ordered lists:
50
-
51
- 1. Foo
52
- 1. Bar
53
- 1. Baz
54
-
55
- And with incorrect spacing:
56
-
57
- 1. Foo {MD030}
58
- 1. Bar {MD030}
59
- 1. Baz {MD030}
60
-
61
- Ordered lists with children:
62
-
63
- 1. Foo {MD030}
64
- * Hi
65
- 1. Bar {MD030}
66
- 1. Baz {MD030}
67
-
68
- Ordered lists with children (correct spacing), and with something other than
69
- the first item determining that the entire list has children:
70
-
71
- 1. Foo
72
- 1. Bar
73
- * Hi
74
- 1. Baz
@@ -1,5 +0,0 @@
1
- all
2
- rule "MD007", :indent => 4
3
- rule "MD030", :ul_multi => 3, :ol_multi => 2
4
- exclude_rule "MD041"
5
- exclude_rule "MD046"
@@ -1,7 +0,0 @@
1
- `normal codespan element`
2
-
3
- ` codespan element with space inside left` {MD038}
4
-
5
- `codespan element with space inside right ` {MD038}
6
-
7
- ` codespan element with spaces inside ` {MD038}
@@ -1,35 +0,0 @@
1
- Line with *Normal emphasis*
2
-
3
- Line with **Normal strong**
4
-
5
- Line with _Normal emphasis_
6
-
7
- Line with __Normal strong__
8
-
9
- Broken * emphasis * with spaces in {MD037}
10
-
11
- Broken ** strong ** with spaces in {MD037}
12
-
13
- Broken _ emphasis _ with spaces in {MD037}
14
-
15
- Broken __ strong __ with spaces in {MD037}
16
-
17
- Mixed *ok emphasis* and * broken emphasis * {MD037}
18
-
19
- Mixed **ok strong** and ** broken strong ** {MD037}
20
-
21
- Mixed _ok emphasis_ and _ broken emphasis _ {MD037}
22
-
23
- Mixed __ok strong__ and __ broken strong __ {MD037}
24
-
25
- Mixed *ok emphasis* **ok strong** * broken emphasis * {MD037}
26
-
27
- Multiple * broken emphasis * _ broken emphasis _ {MD037}
28
-
29
- One-sided *broken emphasis * {MD037}
30
-
31
- One-sided * broken emphasis* {MD037}
32
-
33
- Don't _flag on _words with underscores before them.
34
-
35
- The same goes for words* with asterisks* after them.
@@ -1,10 +0,0 @@
1
- [foo](http://bar/)
2
-
3
- [foo ](http://bar/) {MD039}
4
-
5
- [ foo](http://bar/) {MD039}
6
-
7
- [ foo ](http://bar/) {MD039}
8
-
9
- The following shouldn't break anything:
10
- [![Screenshot.png](/images/Screenshot.png)](/images/Screenshot.png)
@@ -1,4 +0,0 @@
1
- This line has a single trailing space {MD009}
2
- This line has two trailing spaces and should be allowed
3
- This line has three trailing spaces {MD009}
4
- This line has four trailing spaces {MD009}
@@ -1,3 +0,0 @@
1
- all
2
- rule 'MD009', :br_spaces => 2
3
- exclude_rule "MD041"
@@ -1,3 +0,0 @@
1
- Some text {MD009}
2
- Some more text {MD010}
3
- Some more text
@@ -1,5 +0,0 @@
1
- require 'bundler/setup'
2
- Bundler.setup
3
-
4
- require_relative '../lib/mdl'
5
- require 'minitest/autorun'
@@ -1,300 +0,0 @@
1
- require_relative 'setup_tests'
2
- require 'open3'
3
- require 'set'
4
- require 'fileutils'
5
-
6
- class TestCli < Minitest::Test
7
- def test_help_text
8
- result = run_cli("--help")
9
- assert_match(/Usage: \S+ \[options\]/, result[:stdout])
10
- assert_equal(0, result[:status])
11
- end
12
-
13
- def test_default_ruleset_loading
14
- result = run_cli("-l")
15
- assert_ran_ok(result)
16
- assert_rules_enabled(result, ["MD001"])
17
- end
18
-
19
- def test_show_alias_rule_list
20
- result = run_cli("-al")
21
- assert_ran_ok(result)
22
- assert_rules_enabled(result, ["header-increment"])
23
- end
24
-
25
- def test_show_alias_processing_file
26
- result = run_cli_with_input("-a -r MD002", "## header2")
27
- assert_equal(1, result[:status])
28
- assert_equal("", result[:stderr])
29
- assert_match(/^\(stdin\):1: first-header-h1/, result[:stdout])
30
- end
31
-
32
- def test_running_on_unicode_input
33
- result = run_cli_with_file_and_ascii_env("## header2 🚀")
34
- assert_equal(1, result[:status])
35
- assert_equal("", result[:stderr])
36
- assert_match(/MD002 First header should be a top level header/,
37
- result[:stdout])
38
- end
39
-
40
- def test_skipping_default_ruleset_loading
41
- result = run_cli("-ld")
42
- assert_rules_enabled(result, [], true)
43
- end
44
-
45
- def test_custom_ruleset_loading
46
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
47
- result = run_cli("-ldu #{my_ruleset}")
48
- assert_rules_enabled(result, ["MY001"], true)
49
- assert_ran_ok(result)
50
- end
51
-
52
- def test_show_alias_rule_without_alias
53
- # Tests that when -a is given, but the rule doesn't have an alias, it
54
- # prints the rule ID instead.
55
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
56
- result = run_cli("-ladu #{my_ruleset}")
57
- assert_rules_enabled(result, ["MY001"], true)
58
- assert_ran_ok(result)
59
- end
60
-
61
- def test_custom_ruleset_processing_success
62
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
63
- result = run_cli_with_input("-du #{my_ruleset}", "Hello World")
64
- assert_equal("", result[:stdout])
65
- assert_ran_ok(result)
66
- end
67
-
68
- def test_custom_ruleset_processing_failure
69
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
70
- result = run_cli_with_input("-du #{my_ruleset}", "Goodbye world")
71
- assert_equal(1, result[:status])
72
- assert_match(/^\(stdin\):1: MY001/, result[:stdout])
73
- assert_equal("", result[:stderr])
74
- end
75
-
76
- def test_custom_ruleset_processing_failure_with_show_alias
77
- # The custom rule doesn't have an alias, so the output should be identical
78
- # to that without show_alias enabled.
79
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
80
- result = run_cli_with_input("-dau #{my_ruleset}", "Goodbye world")
81
- assert_equal(1, result[:status])
82
- assert_match(/^\(stdin\):1: MY001/, result[:stdout])
83
- assert_equal("", result[:stderr])
84
- end
85
-
86
- def test_custom_ruleset_loading_with_default
87
- my_ruleset = File.expand_path("../fixtures/my_ruleset.rb", __FILE__)
88
- result = run_cli("-lu #{my_ruleset}")
89
- assert_rules_enabled(result, ["MD001", "MY001"])
90
- assert_ran_ok(result)
91
- end
92
-
93
- def test_rule_inclusion_cli
94
- result = run_cli("-r MD001 -l")
95
- assert_rules_enabled(result, ["MD001"], true)
96
- assert_ran_ok(result)
97
- end
98
-
99
- def test_rule_exclusion_cli
100
- result = run_cli("-r ~MD001 -l")
101
- assert_rules_disabled(result, ["MD001"])
102
- assert_ran_ok(result)
103
- end
104
-
105
- def test_rule_inclusion_with_exclusion_cli
106
- result = run_cli("-r ~MD001,MD039 -l")
107
- assert_rules_enabled(result, ["MD039"], true)
108
- assert_ran_ok(result)
109
- end
110
-
111
- def test_tag_inclusion_cli
112
- result = run_cli("-t headers -l")
113
- assert_rules_enabled(result, ["MD001", "MD002", "MD003"])
114
- assert_rules_disabled(result, ["MD004", "MD005", "MD006"])
115
- assert_ran_ok(result)
116
- end
117
-
118
- def test_tag_exclusion_cli
119
- result = run_cli("-t ~headers -l")
120
- assert_ran_ok(result)
121
- assert_rules_disabled(result, ["MD001", "MD002", "MD003"])
122
- assert_rules_enabled(result, ["MD004", "MD005", "MD006"])
123
- end
124
-
125
- def test_rule_inclusion_config
126
- result = run_cli_with_custom_rc_file("-l", "mdlrc_enable_rules")
127
- assert_ran_ok(result)
128
- assert_rules_enabled(result, ["MD001", "MD002"], true)
129
- end
130
-
131
- def test_rule_exclusion_config
132
- result = run_cli_with_custom_rc_file("-l", "mdlrc_disable_rules")
133
- assert_correctly_disabled(result)
134
- end
135
-
136
- def test_mdlrc_loading_from_current_dir_by_default
137
- inside_tmp_dir do |dir|
138
- with_mdlrc("mdlrc_disable_rules", dir) do
139
- result = run_cli_without_rc_flag("-l")
140
- assert_correctly_disabled(result)
141
- end
142
- end
143
- end
144
-
145
- def test_mdlrc_loading_ascends_until_it_finds_an_rc_file
146
- Dir.mktmpdir do |parent_dir|
147
- inside_tmp_dir(parent_dir) do
148
- with_mdlrc("mdlrc_disable_rules", parent_dir) do
149
- result = run_cli_without_rc_flag("-l")
150
- assert_correctly_disabled(result)
151
- end
152
- end
153
- end
154
- end
155
-
156
- def test_tag_inclusion_config
157
- result = run_cli_with_custom_rc_file("-l", "mdlrc_enable_tags")
158
- assert_ran_ok(result)
159
- assert_rules_enabled(result, ["MD001", "MD002", "MD009", "MD010"])
160
- assert_rules_disabled(result, ["MD004", "MD005"])
161
- end
162
-
163
- def test_tag_exclusion_config
164
- result = run_cli_with_custom_rc_file("-l", "mdlrc_disable_tags")
165
- assert_ran_ok(result)
166
- assert_rules_enabled(result, ["MD004", "MD030", "MD032"])
167
- assert_rules_disabled(result, ["MD001", "MD005"])
168
- end
169
-
170
- def test_rule_inclusion_alias_cli
171
- result = run_cli("-l -r header-increment")
172
- assert_ran_ok(result)
173
- assert_rules_enabled(result, ["MD001"], true)
174
- end
175
-
176
- def test_rule_exclusion_alias_cli
177
- result = run_cli("-l -r ~header-increment")
178
- assert_ran_ok(result)
179
- assert_rules_disabled(result, ["MD001"])
180
- assert_rules_enabled(result, ["MD002"])
181
- end
182
-
183
- def test_directory_scanning
184
- path = File.expand_path("./fixtures/dir_with_md_and_markdown", File.dirname(__FILE__))
185
- result = run_cli("#{path}")
186
- lines_output = result[:stdout].lines
187
- interested_lines = lines_output[0..(lines_output.count - 3)]
188
- files_with_issues = interested_lines.map { |l| l.split(":")[0] }.sort
189
- assert_equal(files_with_issues, ["#{path}/bar.markdown", "#{path}/foo.md"])
190
- end
191
-
192
- def test_ignore_front_matter
193
- path = File.expand_path("./fixtures/front_matter", File.dirname(__FILE__))
194
- result = run_cli("-i -r MD001,MD041,MD034 #{path}")
195
-
196
- expected = \
197
- "#{path}/jekyll_post.md:16: MD001 Header levels should only increment by one level at a time"\
198
- "\n\nA detailed description of the rules is available at https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md\n"
199
-
200
- assert_equal(result[:stdout], expected)
201
- end
202
-
203
- private
204
-
205
- def run_cli_with_input(args, stdin)
206
- run_cmd("#{mdl_script} -c #{default_rc_file} #{args}", stdin)
207
- end
208
-
209
- def run_cli_without_rc_flag(args)
210
- run_cmd("#{mdl_script} #{args}", "")
211
- end
212
-
213
- def run_cli(args)
214
- run_cmd("#{mdl_script} -c #{default_rc_file} #{args}", "")
215
- end
216
-
217
- def run_cli_with_custom_rc_file(args, filename)
218
- run_cmd("#{mdl_script} -c #{fixture_rc(filename)} #{args}", "")
219
- end
220
-
221
- def run_cli_with_file_and_ascii_env(content)
222
- Tempfile.create('foo') do |f|
223
- f.write(content)
224
- f.close
225
-
226
- run_cmd("ruby -E ASCII #{mdl_script} -c #{default_rc_file} #{f.path}", "")
227
- end
228
- end
229
-
230
- def run_cmd(command, stdin)
231
- result = {}
232
- result[:stdout], result[:stderr], result[:status] = \
233
- Open3.capture3("bundle", "exec", *command.split, :stdin_data => stdin)
234
- result[:status] = result[:status].exitstatus
235
- result
236
- end
237
-
238
- def mdl_script
239
- File.expand_path("../../bin/mdl", __FILE__)
240
- end
241
-
242
- def fixture_rc(filename)
243
- File.expand_path("../fixtures/#{filename}", __FILE__)
244
- end
245
-
246
- def default_rc_file
247
- fixture_rc("default_mdlrc")
248
- end
249
-
250
- def inside_tmp_dir(base_dir = Dir.tmpdir)
251
- Dir.mktmpdir(nil, base_dir) do |dir|
252
- Dir.chdir(dir) { yield(dir) }
253
- end
254
- end
255
-
256
- def assert_rules_enabled(result, rules, only_these_rules=false)
257
- # Asserts that the given rules are enabled given the output of mdl -l
258
- # If only_these_rules is set, then it asserts that the given rules and no
259
- # others are enabled.
260
- lines = result[:stdout].split("\n")
261
- assert_equal("Enabled rules:", lines.first)
262
- lines.shift
263
- rules = rules.to_set
264
- enabled_rules = lines.map{ |l| l.split(" ").first }.to_set
265
- if only_these_rules
266
- assert_equal(rules, enabled_rules)
267
- else
268
- assert_equal(Set.new, rules - enabled_rules)
269
- end
270
- end
271
-
272
- def assert_rules_disabled(result, rules)
273
- # Asserts that the given rules are _not_ enabled given the output of mdl -l
274
- lines = result[:stdout].split("\n")
275
- assert_equal("Enabled rules:", lines.first)
276
- lines.shift
277
- rules = rules.to_set
278
- enabled_rules = lines.map{ |l| l.split(" ").first }.to_set
279
- assert_equal(Set.new, rules & enabled_rules)
280
- end
281
-
282
- def assert_ran_ok(result)
283
- assert_equal(0, result[:status])
284
- assert_equal("", result[:stderr])
285
- end
286
-
287
- def assert_correctly_disabled(result)
288
- assert_ran_ok(result)
289
- assert_rules_disabled(result, ["MD001", "MD002"])
290
- assert_rules_enabled(result, ["MD003", "MD004"])
291
- end
292
-
293
- def with_mdlrc(filename, dest_dir = Dir.pwd)
294
- rc_path = File.join(dest_dir, ".mdlrc")
295
- FileUtils.cp(fixture_rc(filename), rc_path)
296
- yield
297
- ensure
298
- File.delete(rc_path)
299
- end
300
- end