Skip to content

Commit 60e1d72

Browse files
committed
handle bootlint output
1 parent 512e2c9 commit 60e1d72

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

Dangerfile

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@ require 'nokogiri'
2323

2424
pwd = Dir.pwd + '/'
2525

26-
def print_errors_summary(program, errors, link)
26+
def print_errors_summary(program, errors, link = '')
27+
return if errors == 0
28+
29+
msg = ''
2730
if errors == 1
28-
message("#{program} reports about #{errors} error. Please, fix it. See also: <a href=\"#{link}\">#{link}</a>")
31+
msg = "#{program} reports about #{errors} error. Please, fix it."
2932
elsif errors > 0
30-
message("#{program} reports about #{errors} errors. Please, fix them. See also: <a href=\"#{link}\">#{link}</a>")
33+
msg = "#{program} reports about #{errors} errors. Please, fix them."
34+
end
35+
36+
unless link.empty?
37+
msg << " See also: <a href=\"#{link}\">#{link}</a>"
3138
end
39+
40+
message(msg)
3241
end
3342

3443
# Handle `mvn checkstyle:check` results
@@ -170,6 +179,40 @@ else
170179
end
171180
end
172181

182+
# Handle `bootlint` output
183+
#
184+
# Example:
185+
# src/main/webapp/WEB-INF/views/series/info.html:123:12 E013 Only columns (`.col-*-*`) may be children of `.row`s
186+
# src/main/webapp/WEB-INF/views/site/events.html:197:7 E013 Only columns (`.col-*-*`) may be children of `.row`s
187+
#
188+
# For details, look up the lint problem IDs in the Bootlint wiki:
189+
# https://github.com/twbs/bootlint/wiki
190+
# 3 lint error(s) found across 20 file(s).
191+
#
192+
bootlint_output = 'bootlint.log'
193+
unless File.file?(bootlint_output)
194+
warn("Couldn't find #{bootlint_output}. Result of bootlint is unknown")
195+
else
196+
errors_count = 0
197+
File.readlines(bootlint_output).each do |line|
198+
if line !~ /:\d+:\d+/
199+
next
200+
end
201+
202+
errors_count += 1
203+
204+
parsed = line.match(/^(?<file>[^:]+):(?<line>\d+):\d+ (?<code>[^ ]+) (?<msg>.*)/)
205+
msg = parsed['msg']
206+
lineno = parsed['line']
207+
file = parsed['file']
208+
code = parsed['code']
209+
file = github.html_link("#{file}#L#{lineno}")
210+
fail("bootlint error in #{file}:\n#{code}: #{msg}. ([Details](https://github.com/twbs/bootlint/wiki/#{code}))")
211+
end
212+
# TODO: add link to wiki page (#316)
213+
print_errors_summary 'bootlint', errors_count
214+
end
215+
173216
# Handle `rflint` output
174217
rflint_output = 'rflint.log'
175218
unless File.file?(rflint_output)

0 commit comments

Comments
 (0)