Skip to content

Commit 1bacf79

Browse files
authored
Fix herb linter offenses in ERB templates (#1645)
## Summary - Remove `then` keyword from all ERB control flow tags (52 offenses) - Move duplicated HTML elements outside conditional branches (14 offenses) - Add `.herb.yml` config to disable rules not applicable to RDoc: - `erb-no-instance-variables-in-partials` — RDoc templates aren't Rails partials - `erb-no-unsafe-script-interpolation` — templates render trusted RDoc data - `erb-no-output-in-attribute-position` — same reason Fixes CI failure caused by `@herb-tools/linter` 0.9.0 introducing new rules.
1 parent d7d58e6 commit 1bacf79

17 files changed

Lines changed: 103 additions & 74 deletions

.herb.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 0.9.0
2+
3+
linter:
4+
enabled: true
5+
6+
rules:
7+
# RDoc templates are not Rails partials — instance variables are the
8+
# standard way to pass data from the generator to templates.
9+
erb-no-instance-variables-in-partials:
10+
enabled: false
11+
12+
# Template output is generated from trusted RDoc data, not user input.
13+
erb-no-unsafe-script-interpolation:
14+
enabled: false
15+
16+
# Same: attribute values come from trusted RDoc data.
17+
erb-no-output-in-attribute-position:
18+
enabled: false
19+
20+
formatter:
21+
enabled: false

lib/rdoc/generator/template/aliki/_head.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<%- elsif @title %>
2929
<meta name="keywords" content="ruby,documentation,<%= h @title %>">
3030
<%- if @options.main_page and
31-
main_page = @files.find { |f| f.full_name == @options.main_page } then %>
31+
main_page = @files.find { |f| f.full_name == @options.main_page } %>
3232
<meta
3333
name="description"
3434
content="<%= h "#{@title}: #{excerpt(main_page.comment)}" %>"

lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- unless klass.extends.empty? then %>
1+
<%- unless klass.extends.empty? %>
22
<div id="extends-section" class="nav-section">
33
<details class="nav-section-collapsible" open>
44
<summary class="nav-section-header">
@@ -13,11 +13,13 @@
1313

1414
<ul class="nav-list">
1515
<%- klass.extends.each do |ext| %>
16-
<%- unless String === ext.module then %>
17-
<li><a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a></li>
18-
<%- else %>
19-
<li><span class="extend"><%= ext.name %></span></li>
20-
<%- end %>
16+
<li>
17+
<%- unless String === ext.module %>
18+
<a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a>
19+
<%- else %>
20+
<span class="extend"><%= ext.name %></span>
21+
<%- end %>
22+
</li>
2123
<%- end %>
2224
</ul>
2325
</details>

lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- unless klass.includes.empty? then %>
1+
<%- unless klass.includes.empty? %>
22
<div id="includes-section" class="nav-section">
33
<details class="nav-section-collapsible" open>
44
<summary class="nav-section-header">
@@ -13,11 +13,13 @@
1313

1414
<ul class="nav-list">
1515
<%- klass.includes.each do |inc| %>
16-
<%- unless String === inc.module then %>
17-
<li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a></li>
18-
<%- else %>
19-
<li><span class="include"><%= inc.name %></span></li>
20-
<%- end %>
16+
<li>
17+
<%- unless String === inc.module %>
18+
<a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a>
19+
<%- else %>
20+
<span class="include"><%= inc.name %></span>
21+
<%- end %>
22+
</li>
2123
<%- end %>
2224
</ul>
2325
</details>

lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%- installed.each do |name, href, exists, type, _| %>
66
<%- next if type == :extra %>
77
<li class="folder">
8-
<%- if exists then %>
8+
<%- if exists %>
99
<a href="<%= href %>"><%= h name %></a>
1010
<%- else %>
1111
<%= h name %>

lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%- dir = current.full_name[%r{\A[^/]+(?=/)}] || current.page_name %>
55
<%- end %>
66

7-
<%- unless simple_files.empty? then %>
7+
<%- unless simple_files.empty? %>
88
<div id="fileindex-section" class="nav-section">
99
<details class="nav-section-collapsible" <%= 'open' unless @inside_class_file %>>
1010
<summary class="nav-section-header">

lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- unless klass.sections.length == 1 then %>
1+
<%- unless klass.sections.length == 1 %>
22
<div id="sections-section" class="nav-section">
33
<details class="nav-section-collapsible" open>
44
<summary class="nav-section-header">

lib/rdoc/generator/template/aliki/class.rhtml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<% if namespace[:self] %>
2323
<span><%= namespace[:name] %></span>
2424
<% else %>
25-
<a href="<%= namespace[:path] %>"><%= namespace[:name] %></a><span>::</span>
25+
<a href="<%= namespace[:path] %>"><%= namespace[:name] %></a><span class="separator">::</span>
2626
<% end %>
2727
</li>
2828
<% end %>
@@ -41,31 +41,31 @@
4141
<%- klass.each_section do |section, constants, attributes| %>
4242
<span id="<%= section.legacy_aref %>" class="legacy-anchor"></span>
4343
<section class="documentation-section anchor-link">
44-
<%- if section.title then %>
44+
<%- if section.title %>
4545
<header class="documentation-section-title">
4646
<h2 id="<%= section.aref %>">
4747
<a href="#<%= section.aref %>"><%= section.title %></a>
4848
</h2>
4949
</header>
5050
<%- end %>
5151

52-
<%- if section.comment then %>
52+
<%- if section.comment %>
5353
<div>
5454
<%= section.description %>
5555
</div>
5656
<%- end %>
5757

58-
<%- unless constants.empty? then %>
58+
<%- unless constants.empty? %>
5959
<section class="constants-list">
6060
<header>
6161
<h3 id="<%= section.aref %>-constants"><a href="#<%= section.aref %>-constants">Constants</a></h3>
6262
</header>
6363
<dl>
6464
<%- constants.each do |const| %>
6565
<dt id="<%= const.name %>"><%= const.name %></dt>
66-
<%- if const.comment then %>
66+
<%- if const.comment %>
6767
<dd>
68-
<%- if const.mixin_from then %>
68+
<%- if const.mixin_from %>
6969
<div class="mixin-from">
7070
Included from <a href="<%= klass.aref_to(const.mixin_from.path) %>"><%= const.mixin_from.full_name %></a>
7171
</div>
@@ -80,7 +80,7 @@
8080
</section>
8181
<%- end %>
8282

83-
<%- unless attributes.empty? then %>
83+
<%- unless attributes.empty? %>
8484
<section class="attribute-method-details method-section">
8585
<header>
8686
<h3 id="<%= section.aref %>-attributes"><a href="#<%= section.aref %>-attributes">Attributes</a></h3>
@@ -96,12 +96,12 @@
9696
</div>
9797

9898
<div class="method-description">
99-
<%- if attrib.mixin_from then %>
99+
<%- if attrib.mixin_from %>
100100
<div class="mixin-from">
101101
<%= attrib.singleton ? "Extended" : "Included" %> from <a href="<%= klass.aref_to(attrib.mixin_from.path) %>"><%= attrib.mixin_from.full_name %></a>
102102
</div>
103103
<%- end %>
104-
<%- if attrib.comment then %>
104+
<%- if attrib.comment %>
105105
<%= attrib.description.strip %>
106106
<%- else %>
107107
<p class="missing-docs">(Not documented)</p>
@@ -124,7 +124,7 @@
124124
<%- methods.each do |method| %>
125125
<div id="<%= method.aref %>" class="method-detail anchor-link <%= method.is_alias_for ? "method-alias" : '' %>">
126126
<div class="method-header">
127-
<%- if (call_seq = method.call_seq) then %>
127+
<%- if (call_seq = method.call_seq) %>
128128
<%- call_seq.strip.split("\n").each_with_index do |call_seq, i| %>
129129
<div class="method-heading">
130130
<a href="#<%= method.aref %>" title="Link to this method">
@@ -136,7 +136,7 @@
136136
</a>
137137
</div>
138138
<%- end %>
139-
<%- elsif method.has_call_seq? then %>
139+
<%- elsif method.has_call_seq? %>
140140
<div class="method-heading">
141141
<a href="#<%= method.aref %>" title="Link to this method">
142142
<span class="method-name"><%= h method.name %></span>
@@ -163,19 +163,19 @@
163163
</div>
164164
<%- end %>
165165

166-
<%- unless method.skip_description? then %>
166+
<%- unless method.skip_description? %>
167167
<div class="method-description">
168-
<%- if method.mixin_from then %>
168+
<%- if method.mixin_from %>
169169
<div class="mixin-from">
170170
<%= method.singleton ? "Extended" : "Included" %> from <a href="<%= klass.aref_to(method.mixin_from.path) %>"><%= method.mixin_from.full_name %></a>
171171
</div>
172172
<%- end %>
173-
<%- if method.comment then %>
173+
<%- if method.comment %>
174174
<%= method.description.strip %>
175175
<%- else %>
176176
<p class="missing-docs">(Not documented)</p>
177177
<%- end %>
178-
<%- if method.calls_super then %>
178+
<%- if method.calls_super %>
179179
<div class="method-calls-super">
180180
Calls superclass method
181181
<%=
@@ -187,7 +187,7 @@
187187
</div>
188188
<%- end %>
189189

190-
<%- unless method.aliases.empty? then %>
190+
<%- unless method.aliases.empty? %>
191191
<div class="aliases">
192192
Also aliased as: <%= method.aliases.map do |aka|
193193
if aka.parent then # HACK lib/rexml/encodings
@@ -199,7 +199,7 @@
199199
</div>
200200
<%- end %>
201201

202-
<%- if method.is_alias_for then %>
202+
<%- if method.is_alias_for %>
203203
<div class="aliases">
204204
Alias for: <a href="<%= klass.aref_to method.is_alias_for.path %>"><%= h method.is_alias_for.name %></a>
205205
</div>

lib/rdoc/generator/template/aliki/servlet_root.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
<%- gems = installed.select { |_, _, _, type,| type == :gem } %>
4444
<%- missing = gems.reject { |_, _, exists,| exists } %>
45-
<%- unless missing.empty? then %>
45+
<%- unless missing.empty? %>
4646
<h2>Missing Gem Documentation</h2>
4747

4848
<p>You are missing documentation for some of your installed gems.

lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
<%- unless klass.extends.empty? then %>
1+
<%- unless klass.extends.empty? %>
22
<div id="extends-section" class="nav-section">
33
<h3>Extended With Modules</h3>
44

55
<ul class="link-list">
66
<%- klass.extends.each do |ext| %>
7-
<%- unless String === ext.module then %>
8-
<li><a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a></li>
9-
<%- else %>
10-
<li><span class="extend"><%= ext.name %></span></li>
11-
<%- end %>
7+
<li>
8+
<%- unless String === ext.module %>
9+
<a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a>
10+
<%- else %>
11+
<span class="extend"><%= ext.name %></span>
12+
<%- end %>
13+
</li>
1214
<%- end %>
1315
</ul>
1416
</div>

0 commit comments

Comments
 (0)