Skip to content

Instantly share code, notes, and snippets.

@johncarney
Created May 19, 2016 01:35
Show Gist options
  • Select an option

  • Save johncarney/3d333f544e3c8358ea72dd5936d52f75 to your computer and use it in GitHub Desktop.

Select an option

Save johncarney/3d333f544e3c8358ea72dd5936d52f75 to your computer and use it in GitHub Desktop.
Convert output of reek to GitHub-flavoured Markdown
#!/usr/bin/env ruby
# Converts the output from reek to GitHub-flavoured Markdown.
#
# Usage:
# Basically pipe the output from reek through this script.
#
# reek --sort-by smelliness app lib | ruby reek-to-markdown.rb
def scan_line(line, pattern)
scanned = line.scan(pattern)
yield *scanned.first unless scanned.empty?
end
def parse_file(line)
scan_line(line, /\A\s*(.+?)\s+--\s+\d+\s+warnings?:\s*\z/) do |file|
"#{file}:"
end
end
def parse_smell(line)
scan_line(line, /\A\s+(\[[^\]]+\]):([^:]+):\s*([^\[]+?)\s*\[([^\]]+)\]\s*\z/) do |line, smell, description, link|
"- [ ] [#{smell}](#{link}) #{description} #{line}"
end
end
ARGF.each_line do |line|
if file = parse_file(line)
puts file
elsif smell = parse_smell(line)
puts smell
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment