Cops

In RuboCop lingo the various checks performed on the code are called cops. Each cop is responsible for detecting one particular offense. There are several cop departments, grouping the cops by class of offense. A short description of the different departments is provided below.

Many of the Style and Layout cops have configuration options, allowing them to enforce different coding conventions.

You can also load custom cops.

Style

Style cops check for stylistic consistency of your code. Many of the them are based on the Ruby Style Guide.

Layout

Layout cops inspect your code for consistent use of indentation, alignment, and white space.

Lint

Lint cops check for ambiguities and possible errors in your code.

RuboCop implements, in a portable way, all built-in MRI lint checks (ruby -wc) and adds a lot of extra lint checks of its own.

You can run only the Lint cops like this:

$ rubocop -l

The -l/--lint option can be used together with --only to run all the enabled Lint cops plus a selection of other cops.

Disabling Lint cops is generally a bad idea.

Metrics

Metrics cops deal with properties of the source code that can be measured, such as class length, method length, etc. Generally speaking, they have a configuration parameter called Max and when running rubocop --auto-gen-config, this parameter will be set to the highest value found for the inspected code.

Naming

Naming cops check for naming issue of your code, such as method name, constant name, file name, etc.

Performance

Performance cops catch Ruby idioms which are known to be slower than another, semantically equivalent idiom.

Security

Security cops checks for method calls and constructs which are known to be associated with potential security issues.

Rails

Rails cops are specific to the Ruby on Rails framework. Unlike all other cop types they are not used by default, and you have to request them explicitly:

$ rubocop -R

or add the following directive to your .rubocop.yml:

Rails:
  Enabled: true

Bundler

Bundler cops check for style or bad practices in Bundler files, e.g. Gemfile.

Available cops

In the following section you find all available cops:

Department Bundler

Department Layout

Department Lint

Department Metrics

Department Naming

Department Performance

Department Rails

Department Security

Department Style