forked from jscruggs/metric_fu
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76bf2f
commit 8a23da5
Showing
16 changed files
with
478 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ spec/reports | |
test/tmp | ||
test/version_tmp | ||
tmp | ||
|
||
*.swp | ||
tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env ruby_noexec_wrapper | ||
require 'rubygems' | ||
|
||
require 'metric_fu_requires' | ||
|
||
gem 'parallel', MetricFu::MetricVersion.parallel | ||
version = MetricFu::MetricVersion.cane | ||
gem 'cane', version | ||
load Gem.bin_path('cane', 'cane', version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'cane' | ||
|
||
module MetricFu | ||
class Cane < Generator | ||
attr_reader :violations, :total_violations | ||
|
||
def emit | ||
command = %Q{mf-cane#{abc_max_param}#{style_measure_param}#{no_doc_param}} | ||
mf_debug = "** #{command}" | ||
@output = `#{command}` | ||
end | ||
|
||
def analyze | ||
@violations = violations_by_category | ||
extract_total_violations | ||
end | ||
|
||
def to_h | ||
{:cane => {:total_violations => @total_violations, :violations => @violations}} | ||
end | ||
private | ||
|
||
def abc_max_param | ||
MetricFu.cane[:abc_max] ? " --abc-max #{MetricFu.cane[:abc_max]}" : "" | ||
end | ||
|
||
def style_measure_param | ||
MetricFu.cane[:line_length] ? " --style-measure #{MetricFu.cane[:line_length]}" : "" | ||
end | ||
|
||
def no_doc_param | ||
MetricFu.cane[:no_doc] == 'y' ? " --no-doc" : "" | ||
end | ||
|
||
def violations_by_category | ||
violations_output = @output.scan(/(.*?)\n\n(.*?)\n\n/m) | ||
violations_output.each_with_object({}) do |(category_desc, violation_list), violations| | ||
category = category_from(category_desc) | ||
violations[category] = violations_for(category, violation_list) | ||
end | ||
end | ||
|
||
def category_from(description) | ||
category_descriptions = { | ||
:abc_complexity => /ABC complexity/, | ||
:line_style => /style requirements/, | ||
:comment => /comment/ | ||
} | ||
category_descriptions.find {|k,v| description =~ v}[0] | ||
end | ||
|
||
def violations_for(category, violation_list) | ||
violation_type_for(category).parse(violation_list) | ||
end | ||
|
||
def violation_type_for(category) | ||
case category | ||
when :abc_complexity | ||
CaneViolations::AbcComplexity | ||
when :line_style | ||
CaneViolations::LineStyle | ||
when :comment | ||
CaneViolations::Comment | ||
end | ||
end | ||
|
||
def extract_total_violations | ||
total = @output.match(/Total Violations: (\d+)/)[1] | ||
@total_violations = total.to_i if total | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module MetricFu | ||
class CaneGrapher < Grapher | ||
attr_accessor :cane_violations, :labels | ||
|
||
def initialize | ||
super | ||
@cane_violations = [] | ||
@labels = {} | ||
end | ||
|
||
def get_metrics(metrics, date) | ||
if metrics && metrics[:cane] | ||
@cane_violations.push(metrics[:cane][:total_violations].to_i) | ||
@labels.update( { @labels.size => date }) | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MetricFu::Configuration.run do |config| | ||
config.add_metric(:cane) | ||
config.add_graph(:cane) | ||
config.configure_metric(:cane, { | ||
:dirs_to_cane => MetricFu.code_dirs, | ||
:abc_max => 15, | ||
:line_length => 80, | ||
:no_doc => 'n', | ||
:filetypes => ['rb'] | ||
}) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<html> | ||
<head> | ||
<title>Cane Results</title> | ||
<style> | ||
<%= inline_css("css/default.css") %> | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Cane Results</h1> | ||
<a href="index.html">back to menu</a> | ||
<h2>Total Violations: <%= @cane[:total_violations] %></h2> | ||
<p><a href='https://github.com/square/cane'>Cane</a> reports code quality threshold violations.</p> | ||
|
||
<% graph_name = 'cane' %> | ||
<% if MetricFu.configuration.graph_engine == :gchart %> | ||
<img src="<%= graph_name %>.png?<%= Time.now.to_i %>" /> | ||
<% else %> | ||
<canvas id="graph"></canvas> | ||
<script language="javascript" src="<%= graph_name %>.js?<%= Time.now.to_i %>" type="text/javascript"></script> | ||
<% end %> | ||
|
||
<% if @cane[:violations][:abc_complexity] && @cane[:violations][:abc_complexity].size > 0 %> | ||
<h3>Methods exceeding allowed Abc complexity (<%= @cane[:violations][:abc_complexity].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Method</th> | ||
<th>Complexity</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:abc_complexity].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:file]%></td> | ||
<td><%=violation[:method]%></td> | ||
<td><%=violation[:complexity]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<% if @cane[:violations][:line_style] && @cane[:violations][:line_style].size > 0 %> | ||
<h3>Lines violating style requirements (<%= @cane[:violations][:line_style].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Description</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:line_style].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:line]%></td> | ||
<td><%=violation[:description]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<% if @cane[:violations][:comment] && @cane[:violations][:comment].size > 0 %> | ||
<h3>Class definitions requiring comments (<%= @cane[:violations][:comment].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Class</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:comment].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:line]%></td> | ||
<td><%=violation[:class_name]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<p>Generated on <%= Time.now.localtime %></p> | ||
</body> | ||
</html> |
69 changes: 69 additions & 0 deletions
69
lib/metric_fu/metrics/cane/template_standard/cane.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<html> | ||
<head> | ||
<title>Cane Results</title> | ||
<style> | ||
<%= inline_css("default.css") %> | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Cane Results</h1> | ||
<a href="index.html">back to menu</a> | ||
<h2>Total Violations: <%= @cane[:total_violations] %></h2> | ||
<p><a href='https://github.com/square/cane'>Cane</a> reports code quality threshold violations.</p> | ||
<% if @cane[:violations][:abc_complexity] && @cane[:violations][:abc_complexity].size > 0 %> | ||
<h3>Methods exceeding allowed Abc complexity (<%= @cane[:violations][:abc_complexity].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Method</th> | ||
<th>Complexity</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:abc_complexity].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:file]%></td> | ||
<td><%=violation[:method]%></td> | ||
<td><%=violation[:complexity]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<% if @cane[:violations][:line_style] && @cane[:violations][:line_style].size > 0 %> | ||
<h3>Lines violating style requirements (<%= @cane[:violations][:line_style].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Description</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:line_style].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:line]%></td> | ||
<td><%=violation[:description]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<% if @cane[:violations][:comment] && @cane[:violations][:comment].size > 0 %> | ||
<h3>Class definitions requiring comments (<%= @cane[:violations][:comment].size %>)</h3> | ||
<table> | ||
<tr> | ||
<th>File</th> | ||
<th>Description</th> | ||
</tr> | ||
<% count = 0 %> | ||
<% @cane[:violations][:comment].each do |violation| %> | ||
<tr class='<%= cycle("light", "dark", count) %>'> | ||
<td><%=violation[:line]%></td> | ||
<td><%=violation[:class_name]%></td> | ||
</tr> | ||
<% count += 1 %> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
<p>Generated on <%= Time.now.localtime %></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module MetricFu | ||
module CaneViolations | ||
class AbcComplexity | ||
def self.parse(violation_list) | ||
violation_list.split(/\n/).map do |violation| | ||
file, method, complexity = violation.split | ||
{:file => file, :method => method, :complexity => complexity} | ||
end | ||
end | ||
end | ||
|
||
class LineStyle | ||
def self.parse(violation_list) | ||
violation_list.split(/\n/).map do |violation| | ||
line, description = violation.split(/\s{2,}/).reject{|x|x.strip==''} | ||
{:line => line, :description => description} | ||
end | ||
end | ||
end | ||
|
||
class Comment | ||
def self.parse(violation_list) | ||
violation_list.split(/\n/).map do |violation| | ||
line, class_name = violation.split | ||
{:line => line, :class_name => class_name} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.