Table of Contents
This gem provides features such as:
- An overview of your project:
- An index of the project files with their respective number of smells:
- An index of the smells detected:
- 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
endIt basically turns something like this:
Into something like this:
- 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.
RubyCritic can be installed with the following command:
$ gem install rubycriticIf you'd rather install RubyCritic using Bundler, add this line to your application's Gemfile:
gem "rubycritic", :require => falseAnd then execute:
$ bundleRunning rubycritic with no arguments will analyse all the Ruby files in the
current directory:
$ rubycriticAlternatively you can pass rubycritic a list of files and directories to check:
$ rubycritic app lib/foo.rbFor 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 |
--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 |
Reek:RubyCriticutilizesReek's default configuration loading mechanism. This means that if you have an existingReekconfiguration file, you can just put this into your project root andRubyCriticwill respect this configuration.flay: We useflay's default configuration.flog: We useflog's default configuration with a couple of smaller tweaks:all: Forcesflogto report scores on all classes and methods. Without this optionflogwill only give results up to a certain threshold.continue: Makes it so thatflogdoes not abort when a ruby file cannot be parsed.methods: Configuresflogto skip code outside of methods. It preventsflogfrom reporting on the "methods"privateandprotected. It also preventsflogfrom reporting on Rails methods likebefore_actionandhas_many.
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!
You can use RubyCritic as Rake command in its most simple form like this:
require "rubycritic/rake_task"
RubyCritic::RakeTask.newA 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
endRubyCritic 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'
endRubyCritic is supporting:
- 2.1
- 2.2
- 2.3
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.
RubyCritics initial author was Guilherme Simões.
The current core team consists of:
RubyCritic is maintained and funded by Whitesmith. Tweet your questions or suggestions to @Whitesmithco.






