146

Language / Framework: Ruby
Checks: 300
Categories: Complexity, Security, Clarity, Performance, Bug Risk, Style
RuboCop Version: 0.52.1 (other versions including RuboCop 1.48.1 available by channels)

Our RuboCop plugin provides style and quality checks for Ruby code. RuboCop includes support for MRI 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 and 2.6, jRuby in 2.0 mode, and Rubinius 2.0+.

🚧

A fix in the beta channel was recently implemented, removing a gem that prevented some cops from working correctly. If you experience a sudden uptick in reported issues by the engine, be aware that this might be the cause.

Enable the Plugin

To enable the RuboCop plugin for your project, add the following to your .codeclimate.yml configuration file: ​

  1. Commit a .codeclimate.yml to the root of all branches in your repository.
  2. Add an plugins node.
  3. Mark rubocop as enabled: true.
plugins:
  rubocop:
    enabled: true

More information about the CLI is available in the README here: https://github.com/codeclimate/codeclimate

Configure the Plugin

Default configuration

Our Rubocop plugin uses the default configuration found here.

RuboCop supports configuration via a .rubocop.yml configuration file as detailed in RuboCop's documentation. Edit your .rubocop.yml to select rules and tune thresholds that best meet the requirements of your team.

A complete list of available "cops" can be found by scanning the file lists for each cop category:

Using a non-standard configuration file

Some users may want to keep their configuration in a file named something other than .rubocop.yml. You can specify an alternate file name in your .codeclimate.yml:

plugins:
  rubocop:
    enabled: true
    config:
      file: my_rubocop.yml

Using rubocop's newer versions

Newer versions of rubocop can be set up before they are enabled by default. You can specify which channel you want in the .codeclimate.yml:

plugins:
  rubocop:
    enabled: true
    channel: rubocop-0-79

Available channels can be found here.

❗️

Using newer versions of RuboCop vs the Rubocop Plugin default

You might encounter errors if you rely on Code Climate to infer a RuboCop configuration file for you.

  • To avoid that, be sure to have a version-specific .rubocop.yml in your repo.

Customizing Checks and Thresholds

Users can adjust their RuboCop configuration through a variety of means, including:

  • Directly disable a check in their .codeclimate.yml file:
plugins:
  rubocop:
    enabled: true
    checks:
      Rubocop/Metrics/ClassLength:
        enabled: false
  • Enable and disable rules by specifying Enabled: true or false under Rule name in their .rubocop.yml
  • Comment inline
    • for x in (0..19) # rubocop:disable Style/AvoidFor
  • Configure tolerance for violations (including complexity) by tuning the threshold in their .rubocop.yml under the Rule name. For instance:

RuboCop provides several different metrics which can be used to help assess the maintainability of code, including: