Skip to content

Commit b5da040

Browse files
committed
(MAINT) Refactor markdown specs and fix markdownlint errors
1 parent 236cdae commit b5da040

File tree

12 files changed

+77
-49
lines changed

12 files changed

+77
-49
lines changed

lib/puppet-strings/markdown.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module PuppetStrings::Markdown
1414
# generates markdown documentation
1515
# @return [String] markdown doc
1616
def self.generate
17-
final = "# Reference\n"
17+
final = "# Reference\n\n"
1818
final << "<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n"
1919
final << PuppetStrings::Markdown::TableOfContents.render
2020
final << PuppetStrings::Markdown::PuppetClasses.render

lib/puppet-strings/markdown/base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def private?
169169
@tags.any? { |tag| tag[:tag_name] == 'api' && tag[:text] == 'private' }
170170
end
171171

172+
def word_wrap(text, line_width: 120, break_sequence: "\n")
173+
text.split("\n").collect! do |line|
174+
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line
175+
end * break_sequence
176+
end
177+
172178
# @return [String] full markdown rendering of a component
173179
def render(template)
174180
file = File.join(File.dirname(__FILE__),"templates/#{template}")

lib/puppet-strings/markdown/templates/classes_and_defines.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
* **See also**
2525
<% see.each do |sa| -%>
2626
<% if sa[:name] -%>
27-
<%= sa[:name] %>
27+
<%= " * #{sa[:name]}" %>
2828
<% end -%>
2929
<% if sa[:text] -%>
30-
<%= sa[:text] %>
30+
<%= " * #{sa[:text]}" %>
3131
<% end -%>
3232
<% end -%>
3333

lib/puppet-strings/markdown/templates/data_type.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
* **See also**
2525
<% see.each do |sa| -%>
2626
<% if sa[:name] -%>
27-
<%= sa[:name] %>
27+
<%= " * #{sa[:name]}" %>
2828
<% end -%>
2929
<% if sa[:text] -%>
30-
<%= sa[:text] %>
30+
<%= " * #{sa[:text]}" %>
3131
<% end -%>
3232
<% end -%>
3333

lib/puppet-strings/markdown/templates/function.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Returns: `<%= sig.return_type %>`<% if sig.return_val %> <%= sig.return_val %><%
5555
<% end -%>
5656
<% if raises -%>
5757
Raises:
58+
5859
<% raises.each do |r| -%>
5960
* <%= error_type(r[:text]) %> <%= error_text(r[:text]) %>
6061
<% end -%>

lib/puppet-strings/markdown/templates/resource_type.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
* **See also**
2525
<% see.each do |sa| -%>
2626
<% if sa[:name] -%>
27-
<%= sa[:name] %>
27+
<%= " * #{sa[:name]}" %>
2828
<% end -%>
2929
<% if sa[:text] -%>
30-
<%= sa[:text] %>
30+
<%= " * #{sa[:text]}" %>
3131
<% end -%>
3232
<% end -%>
3333

@@ -116,7 +116,7 @@ Aliases: <%= param[:aliases].to_s.delete('{').delete('}') %>
116116
Data type: `<%= param[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(param[:data_type]) %>
117117

118118
<% end -%>
119-
<%= param[:description] %>
119+
<%= word_wrap(param[:description]) %>
120120

121121
<% if options_for_param(param[:name]) -%>
122122
Options:

lib/puppet-strings/markdown/templates/table_of_contents.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<% if group.length > 0 -%>
2-
**<%= group_name %>**
2+
### <%= group_name %>
33

44
<% if priv -%>
5-
_Public <%= group_name %>_
5+
#### Public <%= group_name %>
66

77
<% group.each do |item| -%>
88
<% unless item[:private] -%>
99
* [`<%= item[:name] %>`](#<%= item[:link] %>)<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
1010
<% end -%>
1111
<% end -%>
1212

13-
_Private <%= group_name %>_
13+
#### Private <%= group_name %>
1414

1515
<% group.each do |item| -%>
1616
<% if item[:private] -%>
File renamed without changes.

spec/markdownlint_style.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all
2+
3+
# Update line length to 120 chars.
4+
rule 'MD013', line_length: 120
5+
6+
# Allow duplicate headings.
7+
exclude_rule 'MD024'
8+
9+
# Allow trailing punctuation in headings.
10+
exclude_rule 'MD026'

spec/spec_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def lint_markdown(content)
5656
return [] unless mdl_available
5757
require 'mdl'
5858

59-
ruleset = MarkdownLint::RuleSet.new
60-
ruleset.load_default
59+
# Load default mdl ruleset
60+
ruleset = MarkdownLint::RuleSet.new.tap { |r| r.load_default }
6161

62-
# All rules
63-
style = MarkdownLint::Style.load('all', ruleset.rules)
62+
# Apply custom style to ruleset rules
63+
MarkdownLint::Style.load(File.join(__dir__, 'markdownlint_style.rb'), ruleset.rules)
6464

6565
# Create a document
6666
doc = MarkdownLint::Doc.new(content, false)
@@ -73,7 +73,7 @@ def lint_markdown(content)
7373
# record the error
7474
error_lines.each do |line|
7575
line += doc.offset # Correct line numbers for any yaml front matter
76-
violations << "#{filename}:#{line}: #{id} #{rule.description}"
76+
violations << "#{line}: #{id} #{rule.description}: #{doc.lines[line - 1]}"
7777
end
7878
end
7979
violations

0 commit comments

Comments
 (0)