Skip to content

Commit 44b6665

Browse files
committed
Dangerfile: handle bootlint output.
1 parent 2af2181 commit 44b6665

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
@@ -9,12 +9,21 @@ require 'nokogiri'
99

1010
pwd = Dir.pwd + '/'
1111

12-
def print_errors_summary(program, errors, link)
12+
def print_errors_summary(program, errors, link = '')
13+
return if errors == 0
14+
15+
msg = ''
1316
if errors == 1
14-
message("#{program} reports about #{errors} error. Please, fix it. See also: <a href=\"#{link}\">#{link}</a>")
17+
msg = "#{program} reported about #{errors} error. Please, fix it."
1518
elsif errors > 0
16-
message("#{program} reports about #{errors} errors. Please, fix them. See also: <a href=\"#{link}\">#{link}</a>")
19+
msg = "#{program} reported about #{errors} errors. Please, fix them."
20+
end
21+
22+
unless link.empty?
23+
msg << " See also: <a href=\"#{link}\">#{link}</a>"
1724
end
25+
26+
message(msg)
1827
end
1928

2029
# Handle `mvn checkstyle:check` results
@@ -205,6 +214,40 @@ else
205214
end
206215
end
207216

217+
# Handle `bootlint` output
218+
#
219+
# Example:
220+
# src/main/webapp/WEB-INF/views/series/info.html:123:12 E013 Only columns (`.col-*-*`) may be children of `.row`s
221+
# src/main/webapp/WEB-INF/views/site/events.html:197:7 E013 Only columns (`.col-*-*`) may be children of `.row`s
222+
#
223+
# For details, look up the lint problem IDs in the Bootlint wiki:
224+
# https://github.com/twbs/bootlint/wiki
225+
# 3 lint error(s) found across 20 file(s).
226+
#
227+
bootlint_output = 'bootlint.log'
228+
unless File.file?(bootlint_output)
229+
warn("Couldn't find #{bootlint_output}. Result of bootlint is unknown")
230+
else
231+
errors_count = 0
232+
File.readlines(bootlint_output).each do |line|
233+
if line !~ /:\d+:\d+/
234+
next
235+
end
236+
237+
errors_count += 1
238+
239+
parsed = line.match(/^(?<file>[^:]+):(?<line>\d+):\d+ (?<code>[^ ]+) (?<msg>.*)/)
240+
msg = parsed['msg']
241+
lineno = parsed['line']
242+
file = parsed['file']
243+
code = parsed['code']
244+
file = github.html_link("#{file}#L#{lineno}")
245+
fail("bootlint error in #{file}:\n#{code}: #{msg}. ([Details](https://github.com/twbs/bootlint/wiki/#{code}))")
246+
end
247+
# TODO: add link to wiki page (#316)
248+
print_errors_summary 'bootlint', errors_count
249+
end
250+
208251
# Handle `rflint` output
209252
#
210253
# Example:

0 commit comments

Comments
 (0)