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.

Security

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

Bundler

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

Gemspec

Gemspec cops check for style and bad practices in gemspec files, e.g. rubocop.gemspec.

Available cops

In the following section you find all available cops:

Department Layout

Department Lint

Department Style