{"id":13428083,"url":"https://github.com/metricfu/metric_fu","last_synced_at":"2025-03-16T01:31:46.959Z","repository":{"id":3892297,"uuid":"4979793","full_name":"metricfu/metric_fu","owner":"metricfu","description":"A fist full of code metrics","archived":false,"fork":true,"pushed_at":"2024-02-27T06:07:37.000Z","size":11410,"stargazers_count":624,"open_issues_count":31,"forks_count":96,"subscribers_count":19,"default_branch":"main","last_synced_at":"2024-10-28T07:45:43.345Z","etag":null,"topics":["code-quality","hacktoberfest","maintainability","software-quality"],"latest_commit_sha":null,"homepage":"http://metricfu.github.com/metric_fu","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jscruggs/metric_fu","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metricfu.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-10T20:10:14.000Z","updated_at":"2024-10-07T17:15:57.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/metricfu/metric_fu","commit_stats":null,"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metricfu%2Fmetric_fu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metricfu%2Fmetric_fu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metricfu%2Fmetric_fu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metricfu%2Fmetric_fu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metricfu","download_url":"https://codeload.github.com/metricfu/metric_fu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814900,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-quality","hacktoberfest","maintainability","software-quality"],"created_at":"2024-07-31T01:00:45.622Z","updated_at":"2025-03-16T01:31:46.531Z","avatar_url":"https://github.com/metricfu.png","language":"Ruby","funding_links":[],"categories":["Coding Style","Code Quality","Ruby","Code Analysis and Metrics","代码风格"],"sub_categories":["Omniauth","Code Metrics"],"readme":"# MetricFu [![Gem Version](https://badge.fury.io/rb/metric_fu.svg)](http://badge.fury.io/rb/metric_fu) [![Test](https://github.com/metricfu/metric_fu/actions/workflows/ruby.yml/badge.svg)](https://github.com/metricfu/metric_fu/actions/workflows/ruby.yml) [![Join the chat at https://gitter.im/metricfu/metric_fu](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/metricfu/metric_fu?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) [![Code Climate](https://codeclimate.com/github/metricfu/metric_fu.svg)](https://codeclimate.com/github/metricfu/metric_fu) [![Inline docs](http://inch-ci.org/github/metricfu/metric_fu.svg)](http://inch-ci.org/github/metricfu/metric_fu)\n\n[MetricFu](http://rdoc.info/github/metricfu/metric_fu/) is a set of tools to provide reports that show which parts of your code might need extra work.\n\nMetrics supported: [Cane](http://github.com/square/cane), [Churn](http://github.com/danmayer/churn), [Flog](https://github.com/seattlerb/flog), [Flay](https://github.com/seattlerb/flay), [Reek](https://github.com/troessner/reek), [Roodi](https://github.com/roodi/roodi), [Saikuro](https://github.com/metricfu/Saikuro), [Code Statistics](https://github.com/bf4/code_metrics), [Hotspots](https://github.com/chiku/hotspots), [SimpleCov](https://github.com/simplecov-ruby/simplecov), [Rcov](https://github.com/relevance/rcov), [Rails Best Practices](https://github.com/flyerhzm/rails_best_practices) (Rails-only).\n\n## Installation\n\nRun:\n\n```\n$ gem install metric_fu\n```\n\nOr add this line to your application's Gemfile:\n\n```ruby\ngem 'metric_fu'\n```\n\nAnd then execute:\n\n```\n$ bundle\n```\n\n### Considerations\n\nMetricFu is [cryptographically signed](http://guides.rubygems.org/security/).\nTo be sure the gem you install hasn't been tampered with:\n\n- Add my public key (if you haven't already) as a trusted certificate `gem cert --add \u003c(curl -Ls https://raw.github.com/metricfu/metric_fu/master/certs/bf4.pem)`\n- `gem install metric_fu -P MediumSecurity`\n\nThe MediumSecurity trust profile will verify signed gems, but allow the installation of unsigned dependencies.\n\nThis is necessary because not all of MetricFu's dependencies are signed, so we cannot use HighSecurity.\n\n## Usage\n\nFrom your application root, run:\n\n```\n$ metric_fu\n```\n\nTo see available options run `metric_fu --help`\n\n## Configuration\n\nMetricFu will attempt to load configuration data from a\n`.metrics` file, if present in your repository root.\n\n```ruby\nMetricFu.report_name # by default, your directory base name\nMetricFu.report_name = 'Something Convenient'\n```\n\n### Example Configuration\n\n```ruby\n# To configure individual metrics...\nMetricFu::Configuration.run do |config|\n  config.configure_metric(:cane) do |cane|\n    cane.enabled = true\n    cane.abc_max = 15\n    cane.line_length = 80\n    cane.no_doc = 'y'\n    cane.no_readme = 'y'\n  end\nend\n\n# Or, alternative format\nMetricFu.configuration.configure_metric(:churn) do |churn|\n  churn.enabled = true\n  churn.ignore_files = 'HISTORY.md, TODO.md'\n  churn.start_date = '6 months ago'\nend\n\n# Or, to (re)configure all metrics\nMetricFu.configuration.configure_metrics.each do |metric|\n  if [:churn, :flay, :flog].include?(metric.name)\n    metric.enabled = true\n  else\n    metric.enabled = false\n  end\nend\n```\n\n### Rails Best Practices\n\n```ruby\nMetricFu::Configuration.run do |config|\n  config.configure_metric(:rails_best_practices) do |rbp|\n    rbp.silent = true\n    rbp.exclude = [\"config/chef\"]\n  end\nend\n```\n\n### Coverage Metrics\n\n```ruby\nMetricFu::Configuration.run do |config|\n  config.configure_metric(:rcov) do |rcov|\n    rcov.coverage_file = MetricFu.run_path.join(\"coverage/rcov/rcov.txt\")\n    rcov.enable\n    rcov.activate\n  end\nend\n```\n\nIf you want metric_fu to actually run rcov itself (1.8 only), don't specify an external file to read from\n\n#### Rcov metrics with Ruby 1.8\n\nTo generate the same metrics metric_fu has been generating run from the root of your project before running metric_fu\n\n```shell\nRAILS_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 \u003e coverage/rcov/rcov.txt\n```\n\n#### Simplecov metrics with Ruby 1.9 and 2.0\n\nAdd to your Gemfile or otherwise install\n\n```ruby\ngem 'simplecov'\n```\n\nModify your [spec_helper](https://github.com/metricfu/metric_fu/blob/master/spec/spec_helper.rb) as per the SimpleCov docs and run your tests before running metric_fu\n\n```ruby\n#in your spec_helper\nrequire 'simplecov'\nrequire 'metric_fu/metrics/rcov/simplecov_formatter'\nSimpleCov.formatter = SimpleCov::Formatter::MetricFu\n# or\nSimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[\n  SimpleCov::Formatter::HTMLFormatter,\n  SimpleCov::Formatter::MetricFu\n  ]\nSimpleCov.start\n```\n\nAdditionally, the `coverage_file` path must be specified as above and must exist.\n\n### Formatters\n\n#### Built-in Formatters\n\nBy default, metric_fu will use the built-in html formatter to generate HTML reports for each metric with pretty graphs.\n\nThese 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\nusing a relative path:\n\n```sh\nmetric_fu --out custom_directory    # outputs to tmp/metric_fu/custom_directory\n```\n\nor a full path:\n\n```sh\nmetric_fu --out $HOME/tmp/metrics      # outputs to $HOME/tmp/metrics\n```\n\nYou 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.\n\n```sh\nmetric_fu --format yaml --out custom_report.yml\n```\n\nOr in Ruby, such as in your `.metrics`\n\n```ruby\n# Specify multiple formatters\n# The second argument, the output file, is optional\nMetricFu::Configuration.run do |config|\n  config.configure_formatter(:html)\n  config.configure_formatter(:yaml, \"customreport.yml\")\n  config.configure_formatter(:yaml)\nend\n```\n\n#### Custom Formatters\n\nYou can customize metric_fu's output format with a custom formatter.\n\nTo create a custom formatter, you simply need to create a class\nthat takes an options hash and responds to one or more notifications:\n\n```ruby\nclass MyCustomFormatter\n  def initialize(opts={}); end    # metric_fu will pass in an output param if provided.\n\n  # Should include one or more of...\n  def start; end           # Sent before metric_fu starts metric measurements.\n  def start_metric(metric); end   # Sent before individual metric is measured.\n  def finish_metric(metric); end   # Sent after individual metric measurement is complete.\n  def finish; end           # Sent after metric_fu has completed all measurements.\n  def display_results; end     # Used to open results in browser, etc.\nend\n```\n\nThen\n\n```shell\nmetric_fu --format MyCustomFormatter\n```\n\nSee [lib/metric_fu/formatter](https://github.com/metricfu/metric_fu/tree/main/lib/metric_fu/formatter) for examples.\n\nMetricFu will attempt to require a custom formatter by\nfully qualified name based on ruby search path. So if you include a custom\nformatter as a gem in your Gemfile, you should be able to use it out of the box.\nBut you may find in certain cases that you need to add a require to\nyour .metrics configuration file.\n\nFor instance, to require a formatter in your app's lib directory `require './lib/my_custom_formatter.rb'`\n\n### Configure Graph Engine\n\nBy default, MetricFu uses the Bluff (JavaScript) graph engine.\n\n```ruby\nMetricFu.configuration.configure_graph_engine(:bluff)\n```\n\nBut you can also use the [Highcharts JS library](https://shop.highsoft.com/)\n\n```ruby\nMetricFu.configuration.configure_graph_engine(:highcharts)\n```\n\nNotice: There was previously a `:gchart` option.\nIt was not properly deprecated in the 4.x series.\n\n## Common problems / debugging\n\n- ['ArgumentError; message invalid byte sequence in US-ASCII'](https://github.com/metricfu/metric_fu/issues/215) may be caused by having a default external encoding that is not UTF-8. You can see this in the output of `metric_fu --debug`\n  - OSX: Ensure you have set `LANG=en_US.UTF-8` and `LC_ALL=en_US.UTF-8`. You can add these to your `~/.profile`.\n\n## Compatibility\n\n- It is currently testing on MRI (\u003e= 1.9.3), JRuby (19 mode), and Rubinius (19 mode). Ruby 1.8 is no longer supported.\n\n- For 1.8.7 support, see version 3.0.0 for partial support, or 2.1.3.7.18.1 (where [Semantic Versioning](http://semver.org/) goes to die)\n\n- MetricFu no longer runs any of the analyzed code. For code coverage, you may use a formatter as documented above\n\n- The Cane, Flog, and Rails Best Practices metrics are disabled when Ripper is not available\n\n## Contributing\n\nTake a look at our [contributing guide](https://github.com/metricfu/metric_fu/blob/master/CONTRIBUTING.md).\nBug reports and pull requests are welcome on GitHub at [https://github.com/metricfu/metric_fu](https://github.com/metricfu/metric_fu). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Code of Conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct/).\n\n## Resources\n\n- [Wiki](https://github.com/metricfu/metric_fu/wiki)\n- [List of code tools](https://github.com/metricfu/metric_fu/wiki/Code-Tools)\n- [Roadmap](https://github.com/metricfu/metric_fu/wiki/Roadmap)\n- [Google Group](https://groups.google.com/forum/#!forum/metric_fu)\n- [Original repository by Jake Scruggs](https://github.com/jscruggs/metric_fu)\n- [Jake's post about stepping down](http://jakescruggs.blogspot.com/2012/08/why-i-abandoned-metricfu.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetricfu%2Fmetric_fu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetricfu%2Fmetric_fu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetricfu%2Fmetric_fu/lists"}