A fist full of code metrics
Ruby HTML CSS JavaScript
Pull request Compare This branch is 1126 commits ahead, 1 commit behind jscruggs:master.
Latest commit 6ec57f2 Mar 3, 2017 @bergholdt bergholdt committed on GitHub Merge pull request #298 from phylor/fix/gem_version
Cannot run metric_fu because gem dependency regex fails
Failed to load latest commit information.
bin Capture metric output when executing Nov 6, 2013
certs Update expired cert Jan 22, 2015
checksum Add checksum for metric_fu-4.12.0.gem Jun 18, 2015
config Rubocop cleanup Feb 27, 2015
etc Update CONTRIBUTORS; erd Jun 18, 2015
gem_tasks Rubocop cleanup Feb 27, 2015
lib fixed regex for cases when ".freeze" is included Feb 2, 2017
spec Merge branch 'master' into feature/windows-ci Nov 3, 2016
.gitignore gitignore overcommit Sep 23, 2016
.metrics Centralize usage examples in README.md; remove from .metrics Feb 27, 2014
.rspec update to rspec2 Jan 9, 2013
.rubocop.yml Rubocop cleanup Feb 27, 2015
.rubocop_todo.yml Rubocop cleanup Feb 27, 2015
.simplecov SimpleCov updates Jan 27, 2015
.travis.yml Ruby 2.2 Passes now Feb 27, 2015
.yardopts Remove metric_fu_requires Nov 6, 2013
AUTHORS Move George to Contributors list (new) Sep 25, 2013
CONTRIBUTING.md Remove trailing whitespace Apr 28, 2014
DEV.md Update CONTRIBUTORS / erc.png May 4, 2014
Gemfile FFI 1.9.14 is latest supporting 1.9.3 on windows Jan 20, 2017
Guardfile Rubocop cleanup Feb 27, 2015
HISTORY.md Remove premature release number header. Jan 23, 2017
MIT-LICENSE Updating docs for 2.1.0 release Mar 1, 2011
README.md Added maintenance notice Sep 18, 2016
Rakefile SimpleCov updates Jan 27, 2015
TODO.md Update TODO re: code_statistics May 23, 2013
appveyor.yml Removed bundle env from appveyor.yml Nov 3, 2016
metric_fu.gemspec Upgraded roodi to v5.0.0 Nov 3, 2016


MetricFu Gem Version Build Status

Join the chat at https://gitter.im/metricfu/metric_fu

Code Climate Inline docs Dependency Status



MetricFu needs maintainers. If you are up for helping out, please left a note in issue 280. MetricFu is free and open source code that belongs to everyone. Benjamin (@bf4) hasn't been working on MetricFu for a while, which is a great opportunity for you to step up!


gem install metric_fu

If you have trouble installing the gem

  • try adding metric_fu to your Gemfile and bundling.
  • file a ticket on the issues page.

MetricFu is cryptographically signed. To be sure the gem you install hasn't been tampered with:

  • Add my public key (if you haven't already) as a trusted certificate gem cert --add <(curl -Ls https://raw.github.com/metricfu/metric_fu/master/certs/bf4.pem)
  • gem install metric_fu -P MediumSecurity

The MediumSecurity trust profile will verify signed gems, but allow the installation of unsigned dependencies.

This is necessary because not all of MetricFu's dependencies are signed, so we cannot use HighSecurity.


From your application root. Running via Rake is still supported.




Code and Bug Reports

Questions, Problems, Suggestions, etc.


MetricFu will attempt to load configuration data from a .metrics file, if present in your repository root.

MetricFu.report_name # by default, your directory base name
MetricFu.report_name = 'Something Convenient'

Example Configuration

# To configure individual metrics...
MetricFu::Configuration.run do |config|
  config.configure_metric(:cane) do |cane|
    cane.enabled = true
    cane.abc_max = 15
    cane.line_length = 80
    cane.no_doc = 'y'
    cane.no_readme = 'y'

# Or, alternative format
MetricFu.configuration.configure_metric(:churn) do |churn|
  churn.enabled = true
  churn.ignore_files = 'HISTORY.md, TODO.md'
  churn.start_date = '6 months ago'

# Or, to (re)configure all metrics
MetricFu.configuration.configure_metrics.each do |metric|
  if [:churn, :flay, :flog].include?(metric.name)
    metric.enabled = true
    metric.enabled = false

Rails Best Practices

MetricFu::Configuration.run do |config|
  config.configure_metric(:rails_best_practices) do |rbp|
    rbp.silent = true
    rbp.exclude = ["config/chef"]

Coverage Metrics

MetricFu::Configuration.run do |config|
  config.configure_metric(:rcov) do |rcov|
    rcov.coverage_file = MetricFu.run_path.join("coverage/rcov/rcov.txt")

If you want metric_fu to actually run rcov itself (1.8 only), don't specify an external file to read from

Rcov metrics with Ruby 1.8

To generate the same metrics metric_fu has been generating run from the root of your project before running metric_fu

RAILS_ENV=test rcov $(ruby -e "puts Dir['{spec,test}/**/*_{spec,test}.rb'].join(' ')") --sort coverage --no-html --text-coverage --no-color --profile --exclude-only '.*' --include-file "\Aapp,\Alib" -Ispec > coverage/rcov/rcov.txt

Simplecov metrics with Ruby 1.9 and 2.0

Add to your Gemfile or otherwise install

gem 'simplecov'

Modify your spec_helper as per the SimpleCov docs and run your tests before running metric_fu

#in your spec_helper
require 'simplecov'
require 'metric_fu/metrics/rcov/simplecov_formatter'
SimpleCov.formatter = SimpleCov::Formatter::MetricFu
# or
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[

Additionally, the coverage_file path must be specified as above and must exist.


Built-in Formatters

By default, metric_fu will use the built-in html formatter to generate HTML reports for each metric with pretty graphs.

These reports are generated in metric_fu's output directory (tmp/metric_fu/output) by default. You can customize the output directory by specifying an out directory at the command line using a relative path:

metric_fu --out custom_directory    # outputs to tmp/metric_fu/custom_directory

or a full path:

metric_fu --out $HOME/tmp/metrics      # outputs to $HOME/tmp/metrics

You can specify a different formatter at the command line by referencing a built-in formatter or providing the fully-qualified name of a custom formatter.

metric_fu --format yaml --out custom_report.yml

Or in Ruby, such as in your .metrics

# Specify multiple formatters
# The second argument, the output file, is optional
MetricFu::Configuration.run do |config|
  config.configure_formatter(:yaml, "customreport.yml")

Custom Formatters

You can customize metric_fu's output format with a custom formatter.

To create a custom formatter, you simply need to create a class that takes an options hash and responds to one or more notifications:

class MyCustomFormatter
  def initialize(opts={}); end    # metric_fu will pass in an output param if provided.

  # Should include one or more of...
  def start; end           # Sent before metric_fu starts metric measurements.
  def start_metric(metric); end   # Sent before individual metric is measured.
  def finish_metric(metric); end   # Sent after individual metric measurement is complete.
  def finish; end           # Sent after metric_fu has completed all measurements.
  def display_results; end     # Used to open results in browser, etc.


metric_fu --format MyCustomFormatter

See lib/metric_fu/formatter/ for examples.

MetricFu will attempt to require a custom formatter by fully qualified name based on ruby search path. So if you include a custom formatter as a gem in your Gemfile, you should be able to use it out of the box. But you may find in certain cases that you need to add a require to your .metrics configuration file.

For instance, to require a formatter in your app's lib directory require './lib/my_custom_formatter.rb'

Configure Graph Engine

By default, MetricFu uses the Bluff (JavaScript) graph engine.


But it you may also use the Highcharts JS library


Notice: There was previously a :gchart option. It was not properly deprecated in the 4.x series.

Common problems / debugging


  • It is currently testing on MRI (>= 1.9.3), JRuby (19 mode), and Rubinius (19 mode). Ruby 1.8 is no longer supported.

  • For 1.8.7 support, see version 3.0.0 for partial support, or (where Semantic Versioning goes to die)

  • MetricFu no longer runs any of the analyzed code. For code coverage, you may use a formatter as documented above

  • The Cane, Flog, and Rails Best Practices metrics are disabled when Ripper is not available


There is some useful-but-out-of-date documentation about configuring metric_fu at http://metricfu.github.io/metric_fu and a change log in the the HISTORY file.


This is the official repository for metric_fu. The original repository by Jake Scruggs at https://github.com/jscruggs/metric_fu has been deprecated.


Original Resources:

Bitdeli Badge