mdl 0.7.0 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/mdl/doc.rb +1 -1
- data/lib/mdl/version.rb +1 -1
- data/mdl.gemspec +3 -3
- metadata +4 -266
- data/.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md +0 -22
- data/.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md +0 -40
- data/.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST.md +0 -20
- data/.github/ISSUE_TEMPLATE/RULE_REQUEST.md +0 -20
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -23
- data/.gitignore +0 -13
- data/.pre-commit-hooks.yaml +0 -6
- data/.travis.yml +0 -12
- data/CHANGELOG.md +0 -218
- data/CONTRIBUTING.md +0 -76
- data/MAINTAINERS.md +0 -21
- data/README.md +0 -87
- data/Rakefile +0 -8
- data/docs/RULES.md +0 -1089
- data/docs/configuration.md +0 -99
- data/docs/creating_rules.md +0 -90
- data/docs/creating_styles.md +0 -47
- data/docs/rolling_a_release.md +0 -51
- data/example/markdown_spec.md +0 -897
- data/test/fixtures/default_mdlrc +0 -1
- data/test/fixtures/dir_with_md_and_markdown/bar.markdown +0 -1
- data/test/fixtures/dir_with_md_and_markdown/foo.md +0 -1
- data/test/fixtures/front_matter/jekyll_post.md +0 -16
- data/test/fixtures/front_matter/jekyll_post_2.md +0 -17
- data/test/fixtures/mdlrc_disable_rules +0 -1
- data/test/fixtures/mdlrc_disable_tags +0 -1
- data/test/fixtures/mdlrc_enable_rules +0 -1
- data/test/fixtures/mdlrc_enable_tags +0 -1
- data/test/fixtures/my_ruleset.rb +0 -6
- data/test/rule_tests/alternate_top_level_header.md +0 -3
- data/test/rule_tests/alternate_top_level_header_style.rb +0 -4
- data/test/rule_tests/atx_closed_header_spacing.md +0 -17
- data/test/rule_tests/atx_header_spacing.md +0 -5
- data/test/rule_tests/blockquote_blank_lines.md +0 -31
- data/test/rule_tests/blockquote_spaces.md +0 -23
- data/test/rule_tests/bulleted_list_2_space_indent.md +0 -6
- data/test/rule_tests/bulleted_list_2_space_indent_style.rb +0 -3
- data/test/rule_tests/bulleted_list_4_space_indent.md +0 -3
- data/test/rule_tests/bulleted_list_not_at_beginning_of_line.md +0 -14
- data/test/rule_tests/code_block_consistency.md +0 -11
- data/test/rule_tests/code_block_consistency_style.rb +0 -1
- data/test/rule_tests/code_block_dollar.md +0 -33
- data/test/rule_tests/code_block_dollar_fence.md +0 -29
- data/test/rule_tests/code_block_fenced.md +0 -17
- data/test/rule_tests/code_block_fenced_style.rb +0 -1
- data/test/rule_tests/code_block_indented.md +0 -17
- data/test/rule_tests/code_block_indented_style.rb +0 -1
- data/test/rule_tests/consecutive_blank_lines.md +0 -11
- data/test/rule_tests/consistent_bullet_styles_asterisk.md +0 -3
- data/test/rule_tests/consistent_bullet_styles_dash.md +0 -3
- data/test/rule_tests/consistent_bullet_styles_plus.md +0 -3
- data/test/rule_tests/default_test_style.rb +0 -5
- data/test/rule_tests/emphasis_instead_of_headers.md +0 -42
- data/test/rule_tests/empty_doc.md +0 -0
- data/test/rule_tests/fenced_code_blocks.md +0 -27
- data/test/rule_tests/fenced_code_with_nesting.md +0 -73
- data/test/rule_tests/fenced_code_without_blank_lines.md +0 -42
- data/test/rule_tests/fenced_code_without_blank_lines_style.rb +0 -3
- data/test/rule_tests/first_header_bad_atx.md +0 -1
- data/test/rule_tests/first_header_bad_setext.md +0 -2
- data/test/rule_tests/first_header_good_atx.md +0 -1
- data/test/rule_tests/first_header_good_setext.md +0 -2
- data/test/rule_tests/first_line_top_level_header_atx.md +0 -3
- data/test/rule_tests/first_line_top_level_header_atx_style.rb +0 -2
- data/test/rule_tests/first_line_top_level_header_setext.md +0 -4
- data/test/rule_tests/first_line_top_level_header_setext_style.rb +0 -2
- data/test/rule_tests/fix_102_extra_nodes_in_link_text.md +0 -8
- data/test/rule_tests/header_duplicate_content.md +0 -11
- data/test/rule_tests/header_duplicate_content_different_nesting.md +0 -11
- data/test/rule_tests/header_duplicate_content_different_nesting_style.rb +0 -1
- data/test/rule_tests/header_duplicate_content_no_different_nesting.md +0 -13
- data/test/rule_tests/header_multiple_toplevel.md +0 -3
- data/test/rule_tests/header_mutliple_h1_no_toplevel.md +0 -5
- data/test/rule_tests/header_trailing_punctuation.md +0 -11
- data/test/rule_tests/header_trailing_punctuation_customized.md +0 -14
- data/test/rule_tests/header_trailing_punctuation_customized_style.rb +0 -2
- data/test/rule_tests/headers_bad.md +0 -7
- data/test/rule_tests/headers_good.md +0 -5
- data/test/rule_tests/headers_good_setext_with_atx.md +0 -7
- data/test/rule_tests/headers_good_setext_with_atx_style.rb +0 -2
- data/test/rule_tests/headers_good_with_issue_numbers.md +0 -12
- data/test/rule_tests/headers_surrounding_space_atx.md +0 -12
- data/test/rule_tests/headers_surrounding_space_setext.md +0 -15
- data/test/rule_tests/headers_with_spaces_at_the_beginning.md +0 -20
- data/test/rule_tests/hr_style_dashes.md +0 -22
- data/test/rule_tests/hr_style_dashes_style.rb +0 -3
- data/test/rule_tests/hr_style_inconsistent.md +0 -22
- data/test/rule_tests/hr_style_long.md +0 -22
- data/test/rule_tests/hr_style_long_style.rb +0 -3
- data/test/rule_tests/hr_style_stars.md +0 -22
- data/test/rule_tests/hr_style_stars_style.rb +0 -3
- data/test/rule_tests/inconsistent_bullet_indent_same_level.md +0 -4
- data/test/rule_tests/inconsistent_bullet_styles_asterisk.md +0 -3
- data/test/rule_tests/inconsistent_bullet_styles_dash.md +0 -3
- data/test/rule_tests/inconsistent_bullet_styles_plus.md +0 -3
- data/test/rule_tests/incorrect_bullet_style_asterisk.md +0 -3
- data/test/rule_tests/incorrect_bullet_style_asterisk_style.rb +0 -3
- data/test/rule_tests/incorrect_bullet_style_dash.md +0 -3
- data/test/rule_tests/incorrect_bullet_style_dash_style.rb +0 -3
- data/test/rule_tests/incorrect_bullet_style_plus.md +0 -3
- data/test/rule_tests/incorrect_bullet_style_plus_style.rb +0 -3
- data/test/rule_tests/incorrect_header_atx.md +0 -6
- data/test/rule_tests/incorrect_header_atx_closed.md +0 -6
- data/test/rule_tests/incorrect_header_atx_closed_style.rb +0 -2
- data/test/rule_tests/incorrect_header_atx_style.rb +0 -2
- data/test/rule_tests/incorrect_header_setext.md +0 -6
- data/test/rule_tests/incorrect_header_setext_style.rb +0 -2
- data/test/rule_tests/inline_html.md +0 -13
- data/test/rule_tests/links.md +0 -9
- data/test/rule_tests/lists_without_blank_lines.md +0 -75
- data/test/rule_tests/long_lines.md +0 -3
- data/test/rule_tests/long_lines_100.md +0 -7
- data/test/rule_tests/long_lines_100_style.rb +0 -3
- data/test/rule_tests/long_lines_code.md +0 -45
- data/test/rule_tests/long_lines_code_style.rb +0 -3
- data/test/rule_tests/mixed_header_types_atx.md +0 -6
- data/test/rule_tests/mixed_header_types_atx_closed.md +0 -6
- data/test/rule_tests/mixed_header_types_setext.md +0 -6
- data/test/rule_tests/no_first_line_header.md +0 -1
- data/test/rule_tests/no_first_line_header_style.rb +0 -1
- data/test/rule_tests/no_first_line_top_level_header.md +0 -1
- data/test/rule_tests/no_first_line_top_level_header_style.rb +0 -1
- data/test/rule_tests/ordered_list_item_prefix.md +0 -13
- data/test/rule_tests/ordered_list_item_prefix_ordered.md +0 -13
- data/test/rule_tests/ordered_list_item_prefix_ordered_style.rb +0 -3
- data/test/rule_tests/reversed_link.md +0 -7
- data/test/rule_tests/spaces_after_list_marker.md +0 -74
- data/test/rule_tests/spaces_after_list_marker_style.rb +0 -5
- data/test/rule_tests/spaces_inside_codespan_elements.md +0 -7
- data/test/rule_tests/spaces_inside_emphasis_markers.md +0 -35
- data/test/rule_tests/spaces_inside_link_text.md +0 -28
- data/test/rule_tests/trailing_spaces_br.md +0 -4
- data/test/rule_tests/trailing_spaces_br_style.rb +0 -3
- data/test/rule_tests/whitespace_issues.md +0 -3
- data/test/setup_tests.rb +0 -5
- data/test/test_cli.rb +0 -301
- data/test/test_ruledocs.rb +0 -52
- data/test/test_rules.rb +0 -58
- data/tools/README.md +0 -3
- data/tools/docker/Dockerfile +0 -13
- data/tools/docker/README.md +0 -19
- data/tools/test_location.rb +0 -20
- data/tools/view_markdown.rb +0 -11
data/test/test_cli.rb
DELETED
|
@@ -1,301 +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\n"\
|
|
198
|
-
"#{path}/jekyll_post_2.md:16: MD001 Header levels should only increment by one level at a time\n"\
|
|
199
|
-
"\nA detailed description of the rules is available at https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md\n"
|
|
200
|
-
|
|
201
|
-
assert_equal(result[:stdout], expected)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
private
|
|
205
|
-
|
|
206
|
-
def run_cli_with_input(args, stdin)
|
|
207
|
-
run_cmd("#{mdl_script} -c #{default_rc_file} #{args}", stdin)
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def run_cli_without_rc_flag(args)
|
|
211
|
-
run_cmd("#{mdl_script} #{args}", "")
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def run_cli(args)
|
|
215
|
-
run_cmd("#{mdl_script} -c #{default_rc_file} #{args}", "")
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def run_cli_with_custom_rc_file(args, filename)
|
|
219
|
-
run_cmd("#{mdl_script} -c #{fixture_rc(filename)} #{args}", "")
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def run_cli_with_file_and_ascii_env(content)
|
|
223
|
-
Tempfile.create('foo') do |f|
|
|
224
|
-
f.write(content)
|
|
225
|
-
f.close
|
|
226
|
-
|
|
227
|
-
run_cmd("ruby -E ASCII #{mdl_script} -c #{default_rc_file} #{f.path}", "")
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def run_cmd(command, stdin)
|
|
232
|
-
result = {}
|
|
233
|
-
result[:stdout], result[:stderr], result[:status] = \
|
|
234
|
-
Open3.capture3("bundle", "exec", *command.split, :stdin_data => stdin)
|
|
235
|
-
result[:status] = result[:status].exitstatus
|
|
236
|
-
result
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
def mdl_script
|
|
240
|
-
File.expand_path("../../bin/mdl", __FILE__)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def fixture_rc(filename)
|
|
244
|
-
File.expand_path("../fixtures/#{filename}", __FILE__)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def default_rc_file
|
|
248
|
-
fixture_rc("default_mdlrc")
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def inside_tmp_dir(base_dir = Dir.tmpdir)
|
|
252
|
-
Dir.mktmpdir(nil, base_dir) do |dir|
|
|
253
|
-
Dir.chdir(dir) { yield(dir) }
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def assert_rules_enabled(result, rules, only_these_rules=false)
|
|
258
|
-
# Asserts that the given rules are enabled given the output of mdl -l
|
|
259
|
-
# If only_these_rules is set, then it asserts that the given rules and no
|
|
260
|
-
# others are enabled.
|
|
261
|
-
lines = result[:stdout].split("\n")
|
|
262
|
-
assert_equal("Enabled rules:", lines.first)
|
|
263
|
-
lines.shift
|
|
264
|
-
rules = rules.to_set
|
|
265
|
-
enabled_rules = lines.map{ |l| l.split(" ").first }.to_set
|
|
266
|
-
if only_these_rules
|
|
267
|
-
assert_equal(rules, enabled_rules)
|
|
268
|
-
else
|
|
269
|
-
assert_equal(Set.new, rules - enabled_rules)
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
def assert_rules_disabled(result, rules)
|
|
274
|
-
# Asserts that the given rules are _not_ enabled given the output of mdl -l
|
|
275
|
-
lines = result[:stdout].split("\n")
|
|
276
|
-
assert_equal("Enabled rules:", lines.first)
|
|
277
|
-
lines.shift
|
|
278
|
-
rules = rules.to_set
|
|
279
|
-
enabled_rules = lines.map{ |l| l.split(" ").first }.to_set
|
|
280
|
-
assert_equal(Set.new, rules & enabled_rules)
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def assert_ran_ok(result)
|
|
284
|
-
assert_equal(0, result[:status])
|
|
285
|
-
assert_equal("", result[:stderr])
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def assert_correctly_disabled(result)
|
|
289
|
-
assert_ran_ok(result)
|
|
290
|
-
assert_rules_disabled(result, ["MD001", "MD002"])
|
|
291
|
-
assert_rules_enabled(result, ["MD003", "MD004"])
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
def with_mdlrc(filename, dest_dir = Dir.pwd)
|
|
295
|
-
rc_path = File.join(dest_dir, ".mdlrc")
|
|
296
|
-
FileUtils.cp(fixture_rc(filename), rc_path)
|
|
297
|
-
yield
|
|
298
|
-
ensure
|
|
299
|
-
File.delete(rc_path)
|
|
300
|
-
end
|
|
301
|
-
end
|
data/test/test_ruledocs.rb
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
require_relative 'setup_tests'
|
|
2
|
-
|
|
3
|
-
# Ensures there is documentation for every rule, and that the
|
|
4
|
-
# descriptions/tags/etc in the rule match those in the documentation
|
|
5
|
-
class TestRuledocs < Minitest::Test
|
|
6
|
-
@@ruleset = MarkdownLint::RuleSet.new
|
|
7
|
-
@@ruleset.load_default
|
|
8
|
-
@@rules = @@ruleset.rules
|
|
9
|
-
|
|
10
|
-
def setup
|
|
11
|
-
@ruledocs = load_ruledocs
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def load_ruledocs
|
|
15
|
-
rules = Hash.new({}) # Default to {} if no docs for the rule
|
|
16
|
-
curr_rule = nil
|
|
17
|
-
rules_file = File.expand_path('../../docs/RULES.md', __FILE__)
|
|
18
|
-
File.read(rules_file).split("\n").each do |l|
|
|
19
|
-
if l.match(/^## (MD\d+) - (.*)$/)
|
|
20
|
-
rules[$1] = { :description => $2, :params => {} }
|
|
21
|
-
curr_rule = $1
|
|
22
|
-
elsif l.match(/^Tags: (.*)$/)
|
|
23
|
-
rules[curr_rule][:tags] = $1.split(',').map{|i| i.strip.to_sym}
|
|
24
|
-
elsif l.match(/^Aliases: (.*)$/)
|
|
25
|
-
rules[curr_rule][:aliases] = $1.split(',').map{|i| i.strip}
|
|
26
|
-
elsif l.match(/^Parameters: (.*)(\(.*\)?)$/)
|
|
27
|
-
rules[curr_rule][:params] = $1.split(',').map{|i| i.strip.to_sym}
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
rules
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
@@rules.each do |id, r|
|
|
34
|
-
define_method("test_ruledoc_description_#{id}") do
|
|
35
|
-
assert_equal r.description, @ruledocs[id][:description]
|
|
36
|
-
end
|
|
37
|
-
define_method("test_ruledoc_tags_#{id}") do
|
|
38
|
-
assert_equal r.tags, @ruledocs[id][:tags]
|
|
39
|
-
end
|
|
40
|
-
define_method("test_ruledoc_aliases_#{id}") do
|
|
41
|
-
assert_equal r.aliases, @ruledocs[id][:aliases]
|
|
42
|
-
end
|
|
43
|
-
define_method("test_ruledoc_params_#{id}") do
|
|
44
|
-
assert_equal r.params.keys.sort, (@ruledocs[id][:params] || []).sort
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_ruledoc_for_every_rule
|
|
49
|
-
# (and vice versa)
|
|
50
|
-
assert_equal @@rules.keys, @ruledocs.keys
|
|
51
|
-
end
|
|
52
|
-
end
|
data/test/test_rules.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require_relative 'setup_tests'
|
|
2
|
-
|
|
3
|
-
class TestRules < Minitest::Test
|
|
4
|
-
|
|
5
|
-
def get_expected_errors(lines)
|
|
6
|
-
# Looks for lines tagged with {MD123} to signify that a rule is expected to
|
|
7
|
-
# fire for this line. It also looks for lines tagged with {MD123:1} to
|
|
8
|
-
# signify that a rule is expected to fire on another line (the line number
|
|
9
|
-
# after the colon).
|
|
10
|
-
expected_errors = {}
|
|
11
|
-
re = /\{(MD\d+)(?::(\d+))?\}/
|
|
12
|
-
lines.each_with_index do |line, num|
|
|
13
|
-
m = re.match(line)
|
|
14
|
-
while m
|
|
15
|
-
expected_errors[m[1]] ||= []
|
|
16
|
-
if m[2]
|
|
17
|
-
expected_line = m[2].to_i
|
|
18
|
-
else
|
|
19
|
-
expected_line = num + 1 # 1 indexed lines
|
|
20
|
-
end
|
|
21
|
-
expected_errors[m[1]] << expected_line
|
|
22
|
-
m = re.match(line, m.end(0))
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
expected_errors
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def do_lint(filename)
|
|
29
|
-
# Check for a test_case_style.rb style file for individual tests
|
|
30
|
-
style_file = filename.sub(/.md$/, '_style.rb')
|
|
31
|
-
if ! File.exist?(style_file)
|
|
32
|
-
style_file = "#{File.dirname(filename)}/default_test_style.rb"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
ruleset = MarkdownLint::RuleSet.new
|
|
36
|
-
ruleset.load_default
|
|
37
|
-
rules = ruleset.rules
|
|
38
|
-
style = MarkdownLint::Style.load(style_file, rules)
|
|
39
|
-
rules.select! {|r| style.rules.include?(r)}
|
|
40
|
-
|
|
41
|
-
doc = MarkdownLint::Doc.new(File.read(filename))
|
|
42
|
-
expected_errors = get_expected_errors(doc.lines)
|
|
43
|
-
actual_errors = {}
|
|
44
|
-
rules.sort.each do |id, rule|
|
|
45
|
-
error_lines = rule.check.call(doc)
|
|
46
|
-
if error_lines and not error_lines.empty?
|
|
47
|
-
actual_errors[id] = error_lines
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
assert_equal expected_errors, actual_errors
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
Dir[File.expand_path("../rule_tests/*.md", __FILE__)].each do |filename|
|
|
54
|
-
define_method("test_#{File.basename(filename, '.md')}") do
|
|
55
|
-
do_lint(filename)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
data/tools/README.md
DELETED
data/tools/docker/Dockerfile
DELETED
data/tools/docker/README.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Docker container for markdownlint
|
|
2
|
-
|
|
3
|
-
## Using the docker image
|
|
4
|
-
|
|
5
|
-
To check a single file:
|
|
6
|
-
|
|
7
|
-
docker run --rm -v ${PWD}:/data mivok/markdownlint myfile.md
|
|
8
|
-
|
|
9
|
-
Or, to check all files in a directory:
|
|
10
|
-
|
|
11
|
-
docker run --rm -v ${PWD}:/data mivok/markdownlint .
|
|
12
|
-
|
|
13
|
-
## Building from a docker file
|
|
14
|
-
|
|
15
|
-
The following will tag and upload a new release. Replace X.Y.Z as appropriate.
|
|
16
|
-
|
|
17
|
-
docker build -t mivok/markdownlint:latest -t mivok/markdownlint:X.Y.Z .
|
|
18
|
-
docker push mivok/markdownlint:latest
|
|
19
|
-
docker push mivok/markdownling:X.Y.Z
|