Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

rubycritic

A Ruby code quality reporter

Subscribe to updates I use rubycritic


Statistics on rubycritic

Number of watchers on Github 2024
Number of open issues 37
Average time to close an issue about 1 month
Main language JavaScript
Average time to merge a PR 6 days
Open pull requests 18+
Closed pull requests 25+
Last commit over 1 year ago
Repo Created about 6 years ago
Repo Last Updated over 1 year ago
Size 2.49 MB
Organization / Authorwhitesmith
Contributors16
Page Updated
Do you use rubycritic? Leave a review!
View open issues (37)
View rubycritic activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating rubycritic for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

RubyCritic

Gem Version Build Status Code Climate

RubyCritic Icon

RubyCritic is a gem that wraps around static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code.

Table of Contents

Overview

This gem provides features such as:

  1. An overview of your project:

RubyCritic overview screenshot

  1. An index of the project files with their respective number of smells:

RubyCritic code index screenshot

  1. An index of the smells detected:

RubyCritic smells index screenshot

  1. When analysing code like the following:
  class Dirty
    def awful(x, y)
      if y
        @screen = widgets.map {|w| w.each {|key| key += 3}}
      end
    end
  end

It basically turns something like this:

Reek output screenshot

Into something like this:

RubyCritic file code screenshot

  1. It uses your source control system (only Git, Mercurial and Perforce are currently supported) to compare your currently uncommitted changes with your last commit.

Warning: If your code is not as you expect it to be after running RubyCritic, please check your source control system stash.

Checkout the /docs if you want to read more about our core metrics.

Getting Started

RubyCritic can be installed with the following command:

$ gem install rubycritic

If you'd rather install RubyCritic using Bundler, add this line to your application's Gemfile:

gem "rubycritic", require: false

And then execute:

$ bundle

Usage

Running rubycritic with no arguments will analyse all the Ruby files in the current directory:

$ rubycritic

Alternatively you can pass rubycritic a list of files and directories to check:

$ rubycritic app lib/foo.rb

For a full list of the command-line options run:

$ rubycritic --help
Command flag Description
-v / --version Displays the current version and exits
-p / --path Set path where report will be saved (tmp/rubycritic by default)
-f / --format Report smells in the given format: html (default; will open in a browser), json, console.
-s / --minimum-score Set a minimum score (FLOAT: ex: 96.28)
--mode-ci Use CI mode (faster, but only analyses last commit)
--deduplicate-symlinks De-duplicate symlinks based on their final target
--suppress-ratings Suppress letter ratings
--no-browser Do not open html report with browser

Analyzer Configuration

  • Reek: RubyCritic utilizes Reek's default configuration loading mechanism. This means that if you have an existing Reek configuration file, you can just put this into your project root and RubyCritic will respect this configuration.
  • flay: We use flay's default configuration.
  • flog: We use flog's default configuration with a couple of smaller tweaks:
    • all: Forces flog to report scores on all classes and methods. Without this option flog will only give results up to a certain threshold.
    • continue: Makes it so that flog does not abort when a ruby file cannot be parsed.
    • methods: Configures flog to skip code outside of methods. It prevents flog from reporting on the methods private and protected. It also prevents flog from reporting on Rails methods like before_action and has_many.

Alternative Usage Methods

If you're fond of Guard you might like guard-rubycritic. It automatically analyses your Ruby files as they are modified.

For continuous integration, you can give Jenkins CI a spin. With it, you can easily build your own (poor-man's) Code Climate!

Rake Task

You can use RubyCritic as Rake command in its most simple form like this:

require "rubycritic/rake_task"

RubyCritic::RakeTask.new

A more sophisticated Rake task that would make use of all available configuration options could look like this:

RubyCritic::RakeTask.new do |task|
  # Name of RubyCritic task. Defaults to :rubycritic.
  task.name    = 'something_special'

  # Glob pattern to match source files. Defaults to FileList['.'].
  task.paths   = FileList['vendor/**/*.rb']

  # You can pass all the options here in that are shown by "rubycritic -h" except for
  # "-p / --path" since that is set separately. Defaults to ''.
  task.options = '--mode-ci --format json'

  # Defaults to false
  task.verbose = true
end

RubyCritic will try to open the generated report with a browser by default. If you don't want this you can prevent this behaviour by setting the options correspondingly:

RubyCritic::RakeTask.new do |task|
  task.options = '--no-browser'
end

Compatibility

RubyCritic is supporting Ruby versions:

  • 2.1
  • 2.2
  • 2.3
  • 2.4

Improving RubyCritic

RubyCritic doesn't have to remain a second choice to other code quality analysis services. Together, we can improve it and continue to build on the great code metric tools that are available in the Ruby ecosystem.

Arguably, the better_errors gem only got popular after receiving a (pretty awesome) Pull Request that changed its page design.

Similarly, Pull Requests that improve the look and feel of the gem, that tweak the calculation of ratings or that fix existing issues will be most welcome. Just commenting on an issue and giving some insight into how something should work will be appreciated. No contribution is too small.

See RubyCritic's contributing guidelines about how to proceed.

Contributors

RubyCritics initial author was Guilherme Simes.

The current core team consists of:

Credits

Whitesmith

RubyCritic is maintained and funded by Whitesmith. Tweet your questions or suggestions to @Whitesmithco.

rubycritic open issues Ask a question     (View All Issues)
  • almost 3 years UI/UX improvements for the current system
  • about 3 years Reek configuration not being picked up
  • about 3 years Progress bar added in 2.4.0 added to json output
  • about 3 years CI mode does not run only on the diff from master
  • over 3 years Rubycritic does not handle inline classes very well
  • over 3 years When specify more directories = mess in git repository
  • over 3 years Missing status label (old/new)
  • over 3 years Complexity vs Churn graph: Log scaling option wise?
  • over 3 years Overall Score?
  • over 3 years Option to run analysers in parallel
  • over 3 years Summary of all RubyCritic features that are lacking documentation.
  • over 3 years RoadMap
  • almost 4 years Define a first version of our public API
  • almost 4 years Remove dependencies between analysers
  • about 4 years Extract SourceControl subdirectory to gem?
  • about 4 years Highlight entire indentical block on DuplicateCode smell
  • about 4 years Code view Filter/Search
  • over 4 years Option To Display Raw Scores Instead of Letter Grades
  • over 4 years Allow configuring date range of Churn calculation
  • over 4 years Settings file
  • about 5 years Ignore/exclude files
rubycritic open pull requests (View All Pulls)
  • Generates report inside rails application
  • allow to use rubocop 0.40.0
  • Support Perforce source control system for Churn metric
  • Add and increase a bit the turboThreshold of Highcharts.
  • Add missing method 'head_reference' for Perforce source control
  • [Fixes #60] Implement search and filter on code and smells view
  • Compare only the modified files between two branches
  • [Fixes #187] Fix code navigation links
  • Use a real progress bar for ruby critic
  • Fix a RuboCop offenses
  • Update the "Getting Started"
  • Accept a float as the minimum score
  • Traverse git history only once
  • Update application.js
  • RuboCop Auto Correct: Sytle/SpecialGlobalVars
  • Update tests for ruby 2.5
  • Fix wrong label for churn in the code file template
  • [CHANGE] Update parser, rainbow, rubocop
rubycritic list of languages used
Other projects in JavaScript