Skip to content

Commit 0260ac8

Browse files
authored
Add Herb linter and fix HTML and ERB linting issues (#1434)
- Added `Herb LSP` to suggested VS Code extension, which will surface ERB/HTML issues in `.rthml` templates. - Fixed all surfaced issues - Added ERB lint step on CI
1 parent ac2a6fb commit 0260ac8

19 files changed

+202
-185
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ jobs:
2727
bundler-cache: true
2828
- name: Run rubocop
2929
run: bundle exec rubocop
30+
- name: Run herb linter
31+
# npx should be available by default so we don't need `setup-node` action
32+
# Don't lint erb files outside of lib as the current directory also includes vendor/bundle
33+
run: npx @herb-tools/linter "lib/**/*.rhtml"

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"marcoroth.herb-lsp"
4+
]
5+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<footer id="validator-badges" role="contentinfo">
2-
<p><a href="https://validator.w3.org/check/referer">Validate</a>
3-
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> <%= RDoc::VERSION %>.
4-
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
2+
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
3+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> <%= RDoc::VERSION %>.</p>
4+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
55
</footer>
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
<meta charset="<%= @options.charset %>">
2-
<meta name="viewport" content="width=device-width, initial-scale=1" />
2+
<meta name="viewport" content="width=device-width, initial-scale=1">
33

44
<title><%= h @title %></title>
55

6-
<%- if defined?(klass) -%>
6+
<%- if defined?(klass) %>
77
<meta name="keywords" content="ruby,<%= h "#{klass.type},#{klass.full_name}" %>">
88

9-
<%- if klass.comment.empty? -%>
9+
<%- if klass.comment.empty? %>
1010
<meta name="description" content="Documentation for the <%= h "#{klass.full_name} #{klass.type}" %>">
11-
<%- else -%>
11+
<%- else %>
1212
<meta name="description" content="<%= h "#{klass.type} #{klass.full_name}: #{excerpt(klass.comment)}" %>">
13-
<%- end -%>
14-
<%- elsif defined?(file) -%>
13+
<%- end %>
14+
<%- elsif defined?(file) %>
1515
<meta name="keywords" content="ruby,documentation,<%= h file.page_name %>">
1616
<meta name="description" content="<%= h "#{file.page_name}: #{excerpt(file.comment)}" %>">
17-
<%- elsif @title -%>
17+
<%- elsif @title %>
1818
<meta name="keywords" content="ruby,documentation,<%= h @title %>">
1919

2020
<%- if @options.main_page and
2121
main_page = @files.find { |f| f.full_name == @options.main_page } then %>
2222
<meta name="description" content="<%= h "#{@title}: #{excerpt(main_page.comment)}" %>">
23-
<%- else -%>
23+
<%- else %>
2424
<meta name="description" content="Documentation for <%= h @title %>">
25-
<%- end -%>
26-
<%- end -%>
25+
<%- end %>
26+
<%- end %>
2727

28-
<%- if canonical_url = @options.canonical_root -%>
28+
<%- if canonical_url = @options.canonical_root %>
2929
<% canonical_url = current.canonical_url if defined?(current) %>
3030
<link rel="canonical" href="<%= canonical_url %>">
31-
<%- end -%>
31+
<%- end %>
3232

3333
<script type="text/javascript">
3434
var rdoc_rel_prefix = "<%= h asset_rel_prefix %>/";
@@ -43,6 +43,6 @@
4343

4444
<link href="<%= h asset_rel_prefix %>/css/fonts.css" rel="stylesheet">
4545
<link href="<%= h asset_rel_prefix %>/css/rdoc.css" rel="stylesheet">
46-
<%- @options.template_stylesheets.each do |stylesheet| -%>
46+
<%- @options.template_stylesheets.each do |stylesheet| %>
4747
<link href="<%= h asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet">
48-
<%- end -%>
48+
<%- end %>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<h3>Extended With Modules</h3>
44

55
<ul class="link-list">
6-
<%- 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>
9-
<%- else -%>
10-
<li><span class="extend"><%= ext.name %></span>
11-
<%- end -%>
12-
<%- end -%>
6+
<%- 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 %>
12+
<%- end %>
1313
</ul>
1414
</div>
15-
<%- end -%>
15+
<%- end %>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<h3>Included Modules</h3>
44

55
<ul class="link-list">
6-
<%- klass.includes.each do |inc| -%>
7-
<%- unless String === inc.module then -%>
8-
<li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a>
9-
<%- else -%>
10-
<li><span class="include"><%= inc.name %></span>
11-
<%- end -%>
12-
<%- end -%>
6+
<%- klass.includes.each do |inc| %>
7+
<%- unless String === inc.module then %>
8+
<li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a></li>
9+
<%- else %>
10+
<li><span class="include"><%= inc.name %></span></li>
11+
<%- end %>
12+
<%- end %>
1313
</ul>
1414
</div>
15-
<%- end -%>
15+
<%- end %>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
<h3>Documentation</h3>
33

44
<ul>
5-
<%- installed.each do |name, href, exists, type, _| -%>
6-
<%- next if type == :extra -%>
5+
<%- installed.each do |name, href, exists, type, _| %>
6+
<%- next if type == :extra %>
77
<li class="folder">
8-
<%- if exists then -%>
8+
<%- if exists then %>
99
<a href="<%= href %>"><%= h name %></a>
10-
<%- else -%>
10+
<%- else %>
1111
<%= h name %>
12-
<%- end -%>
13-
<%- end -%>
12+
<%- end %>
13+
</li>
14+
<%- end %>
1415
</ul>
1516
</div>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<div class="nav-section">
33
<h3>Class Methods</h3>
44
<ul class="link-list" role="directory">
5-
<%- class_methods.each do |meth| -%>
6-
<li <%- if meth.calls_super %>class="calls-super" <%- end %>><a href="#<%= meth.aref %>"><%= h meth.name -%></a></li>
7-
<%- end -%>
5+
<%- class_methods.each do |meth| %>
6+
<li <%- if meth.calls_super %>class="calls-super" <%- end %>><a href="#<%= meth.aref %>"><%= h meth.name %></a></li>
7+
<%- end %>
88
</ul>
99
</div>
1010
<% end %>
@@ -13,9 +13,9 @@
1313
<div class="nav-section">
1414
<h3>Instance Methods</h3>
1515
<ul class="link-list" role="directory">
16-
<%- instance_methods.each do |meth| -%>
17-
<li <%- if meth.calls_super %>class="calls-super" <%- end %>><a href="#<%= meth.aref %>"><%= h meth.name -%></a></li>
18-
<%- end -%>
16+
<%- instance_methods.each do |meth| %>
17+
<li <%- if meth.calls_super %>class="calls-super" <%- end %>><a href="#<%= meth.aref %>"><%= h meth.name %></a></li>
18+
<%- end %>
1919
</ul>
2020
</div>
2121
<% end %>
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
<%- simple_files = @files.select { |f| f.text? } %>
2-
<%- if defined?(current) -%>
3-
<%- dir = current.full_name[%r{\A[^/]+(?=/)}] || current.page_name -%>
4-
<%- end -%>
5-
<%- unless simple_files.empty? then -%>
2+
<%- if defined?(current) %>
3+
<%- dir = current.full_name[%r{\A[^/]+(?=/)}] || current.page_name %>
4+
<%- end %>
5+
<%- unless simple_files.empty? then %>
66
<div id="fileindex-section" class="nav-section">
77
<h3>Pages</h3>
88

99
<ul class="link-list">
10-
<%- simple_files.group_by do |f| -%>
11-
<%- f.full_name[%r{\A[^/]+(?=/)}] || f.page_name -%>
12-
<%- end.each do |n, files| -%>
13-
<%- f = files.shift -%>
14-
<%- if files.empty? -%>
15-
<li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a>
16-
<%- next -%>
17-
<%- end -%>
18-
<li><details<% if dir == n %> open<% end %>><summary><%
10+
<%- simple_files.group_by do |f|
11+
f.full_name[%r{\A[^/]+(?=/)}] || f.page_name
12+
end.each do |n, files| %>
13+
<%- f = files.shift %>
14+
<%- if files.empty? %>
15+
<li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a></li>
16+
<%- next %>
17+
<%- end %>
18+
<li><details<%= ' open' if dir == n %>><summary><%
1919
if n == f.page_name
2020
%><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h n %></a><%
2121
else
2222
%><%= h n %><% files.unshift(f)
2323
end %></summary>
2424
<ul class="link-list">
25-
<%- files.each do |f| -%>
26-
<li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a>
27-
<%- end -%>
28-
</ul></details>
29-
<%- end -%>
25+
<%- files.each do |f| %>
26+
<li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a></li>
27+
<%- end %>
28+
</ul></details></li>
29+
<%- end %>
3030
</ul>
3131
</div>
32-
<%- end -%>
32+
<%- end %>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<%- if klass.type == 'class' && (ancestors = klass.super_classes).any? -%>
1+
<%- if klass.type == 'class' && (ancestors = klass.super_classes).any? %>
22
<div id="parent-class-section" class="nav-section">
33
<h3>Ancestors</h3>
44
<%= generate_ancestor_list(ancestors, klass) %>
55
</div>
6-
<%- end -%>
6+
<%- end %>

0 commit comments

Comments
 (0)