123456789_123456789_123456789_123456789_123456789_

Full reference for the rubocop command-line interface. For a tutorial introduction, see Getting Started.

Command-line flags

For more details check the available command-line options:

$ rubocop -h

To specify multiple cops for one flag, separate cops with commas and no spaces:

$ rubocop --only Rails/Blank,Layout/HeredocIndentation,Naming/FileName
Command flag Description

<code>-a/--autocorrect</code>

Autocorrect offenses (only when it’s safe). See Autocorrect.

<code>--auto-correct</code>

Deprecated alias of <code>-a/--autocorrect</code>.

<code>-A/--autocorrect-all</code>

Autocorrect offenses (safe and unsafe). See Autocorrect.

<code>--auto-correct-all</code>

Deprecated alias of <code>-A/--autocorrect-all</code>.

<code>--auto-gen-config</code>

Generate a configuration file acting as a TODO list.

<code>--[no-]color</code>

Force color output on or off.

<code>-c/--config</code>

Run with specified config file.

<code>-C/--cache</code>

Store and reuse results for faster operation.

<code>-d/--debug</code>

Displays some extra debug output.

<code>--disable-all-cops</code>

Run with all cops disabled by default, except <code>Lint/Syntax</code>. Overrides <code>AllCops/EnabledByDefault</code> and <code>AllCops/DisabledByDefault</code> in configuration files.

<code>--disable-pending-cops</code>

Run without pending cops.

<code>--disable-uncorrectable</code>

Used with --autocorrect to annotate any offenses that do not support autocorrect with <code>rubocop:todo</code> comments.

<code>-D/--[no-]display-cop-names</code>

Displays cop names in offense messages. Default is true.

<code>--display-time</code>

Display elapsed time in seconds.

<code>--display-only-fail-level-offenses</code>

Only output offense messages at the specified <code>--fail-level</code> or above.

<code>--display-only-correctable</code>

Only output correctable offense messages.

<code>--display-only-safe-correctable</code>

Only output safe correctable offense messages.

<code>--enable-all-cops</code>

Run with all cops enabled, including those disabled by default. Overrides <code>AllCops/EnabledByDefault</code> and <code>AllCops/DisabledByDefault</code> in configuration files.

<code>--enable-pending-cops</code>

Run with pending cops.

<code>--except</code>

Run all cops enabled by configuration except the specified cop(s) and/or departments.

<code>--exclude-limit</code>

Limit how many individual files <code>--auto-gen-config</code> can list in Exclude parameters, default is 15.

<code>-E/--extra-details</code>

Displays extra details in offense messages.

<code>-f/--format</code>

Choose a formatter, see Formatters.

<code>-F/--fail-fast</code>

Inspect files in order of modification time and stop after the first file with offenses.

<code>--fail-level</code>

Minimum severity for exit with error code. Full severity name or upper case initial can be given. Normally, autocorrected offenses are ignored. Use A or autocorrect if you’d like any autocorrectable offense to trigger failure, regardless of severity.

<code>--force-exclusion</code>

Force excluding files specified in the configuration Exclude even if they are explicitly passed as arguments.

<code>--only-recognized-file-types</code>

Inspect files given on the command line only if they are listed in AllCops/Include parameters of user configuration or default configuration.

<code>-h/--help</code>

Print usage information.

<code>--ignore-disable-comments</code>

Report offenses even if they have been manually disabled with a <code>rubocop:disable</code> or <code>rubocop:todo</code> directive.

<code>--ignore-parent-exclusion</code>

Ignores all Exclude: settings from all .rubocop.yml files present in parent folders. This is useful when you are importing submodules when you want to test them without being affected by the parent module’s rubocop settings.

<code>--ignore-unrecognized-cops</code>

Ignore unrecognized cops or departments in the config.

<code>--init</code>

Generate a .rubocop.yml file in the current directory.

<code>-l/--lint</code>

Run only lint cops.

<code>-L/--list-target-files</code>

List all files RuboCop will inspect.

<code>--[no-]auto-gen-only-exclude</code>

Generate only Exclude parameters and not Max when running <code>--auto-gen-config</code>, except if the number of files with offenses is bigger than <code>exclude-limit</code>. Default is false.

<code>--[no-]auto-gen-timestamp</code>

Include the date and time when <code>--auto-gen-config</code> was run in the config file it generates. Default is true.

<code>--[no-]offense-counts</code>

Show offense counts in config file generated by <code>--auto-gen-config</code>. Default is true.

<code>--only</code>

Run only the specified cop(s) and/or cops in the specified departments.

<code>-o/--out</code>

Write output to a file instead of STDOUT.

<code>--[no-]parallel</code>

Use available CPUs to execute inspection in parallel. Default is parallel.

<code>--raise-cop-error</code>

Raise cop-related errors with cause and location. This is used to prevent cops from failing silently. Default is false.

<code>--plugin</code>

Plugin RuboCop extension file (see Loading Plugin Extensions).

<code>-r/--require</code>

Require Ruby file (see Loading Legacy Extensions).

<code>--regenerate-todo</code>

Regenerate the TODO list using the same options as the last time it was generated with <code>--auto-gen-config</code> (generation options can be overridden).

<code>--safe</code>

Run only safe cops.

<code>--safe-auto-correct</code>

Deprecated alias of <code>-a/--autocorrect</code>.

<code>--show-cops</code>

Shows available cops and their configuration. You can use * as a wildcard.

<code>--show-docs-url</code>

Shows URLs for documentation pages of supplied cops.

<code>--stderr</code>

Write all output to stderr except for the autocorrected source. This is especially useful when combined with <code>--autocorrect</code> and <code>--stdin</code>.

<code>-s/--stdin</code>

Pipe source from STDIN. This is useful for editor integration. Takes one argument, a path, relative to the root of the project. RuboCop will use this path to determine which cops are enabled (via eg. Include/Exclude), and so that certain cops like Naming/FileName can be checked.

<code>--editor-mode</code>

Optimize real-time feedback in editors, adjusting behaviors for editing experience. Editors that run RuboCop directly (e.g., by shelling out) encounter the same issues as with <code>--lsp</code>. This option is designed for such editors.

<code>-S/--display-style-guide</code>

Display style guide URLs in offense messages.

<code>-x/--fix-layout</code>

Autocorrect only code layout (formatting) offenses.

<code>-v/--version</code>

Displays the current version and exits.

<code>-V/--verbose-version</code>

Displays the current version plus the version of Parser and Ruby.

Default command-line options are loaded from .rubocop and RUBOCOP_OPTS and are combined with command-line options that are explicitly passed to rubocop. Thus, the options have the following order of precedence (from highest to lowest):

  1. Explicit command-line options

  2. Options from RUBOCOP_OPTS environment variable

  3. Options from .rubocop file.

Exit codes

RuboCop exits with the following status codes:

  • 0 if no offenses are found or if the severity of all offenses are less than <code>--fail-level</code>. (By default, if you use <code>--autocorrect</code>, offenses which are autocorrected do not cause RuboCop to fail.)

  • 1 if one or more offenses equal or greater to <code>--fail-level</code> are found. (By default, this is any offense which is not autocorrected.)

  • 2 if RuboCop terminates abnormally due to invalid configuration, invalid CLI options, or an internal error.

Parallel Processing

RuboCop enables the <code>--parallel</code> option by default. This option allows for parallel processing using the number of available CPUs based on Etc.nprocessors. If the default number of parallel processes causes excessive consumption of CPU and memory, you can adjust the number of parallel processes using the <code>$PARALLEL_PROCESSOR_COUNT</code> environment variable. Here is how to set the parallel processing to use two CPUs:

$ PARALLEL_PROCESSOR_COUNT=2 bundle exec rubocop

Alternatively, specifying <code>--no-parallel</code> will disable parallel processing.