Running
rubocop
Check all Ruby files here
rubocop <path> ...
Check given files or dirs
rubocop -L
List files that would be inspected
rubocop -F
Stop after first file with offenses
rubocop --parallel
Use all CPUs
rubocop -s <path> < <file>
Check stdin as if at path
Used by editor integrations.
rubocop --force-exclusion <path>
Honour Exclude for explicit paths
Needed so editors and pre-commit hooks skip excluded files.
rubocop -c <file>
Use another config file
rubocop -r <lib>
Require a Ruby file or extension
rubocop -v / -V
Show version / full versions
rubocop --ignore-parent-exclusion
Ignore Exclude from parent configs
Choosing cops
rubocop --only <Cop>,<Dept>
Run only these cops or departments
rubocop --except <Cop>
Run all but these
rubocop -l
Lint cops only
rubocop --safe
Skip cops not marked safe
rubocop --show-cops [<Cop>]
Print cops and their settings
rubocop --enable-pending-cops
Turn on pending cops
rubocop --disable-pending-cops
Keep pending cops off
rubocop --only-recognized-file-types
Skip files not matching Include
Output
rubocop -f <name>
Pick an output formatter
rubocop -f simple
Offenses grouped by file
rubocop -f offenses
Count offenses per cop
rubocop -f worst
Files with most offenses
rubocop -f files
Only list offending files
rubocop -f json -o <file>
Machine readable report
rubocop -f github
GitHub Actions annotations
rubocop -f emacs
One line per offense
rubocop -f <name> -f <name2> -o
<file>
Several formatters at once
Each -f applies to the -o that follows it.
rubocop -E
Show extra details in messages
rubocop --[no-]color
Force colours on or off
rubocop --fail-level <sev>
Minimum severity that fails
rubocop --display-only-fail-level-offenses
Hide offenses below fail level
Config files
rubocop --init
Write a starter .rubocop.yml
rubocop --auto-gen-config
Write .rubocop_todo.yml
Also adds inherit_from: .rubocop_todo.yml to .rubocop.yml.
rubocop --regenerate-todo
Redo the TODO file with last options
rubocop --auto-gen-config --exclude-limit <n>
Files listed before cop is disabled
Default 15.
rubocop --auto-gen-only-exclude
Only Exclude, never Max
rubocop --no-auto-gen-timestamp
Stable diffs of the TODO file
rubocop --no-offense-counts
Omit counts in the TODO file
RUBOCOP_OPTS="<flags>"
Default options from environment
.rubocop
Default CLI options file, one per line
YAML keys
inherit_from: <file>
Include other configs
inherit_gem: { <gem>: <file> }
Use a config shipped in a gem
plugins: - <name>
Load extension plugins
Newer extensions such as rubocop-rails use plugins; older
style uses require.
require: - <lib>
Load extension by require
AllCops: NewCops: enable
Opt into pending cops
AllCops: TargetRubyVersion: <x.y>
Set Ruby version to parse as
AllCops: Exclude: - <glob>
Skip paths everywhere
AllCops: SuggestExtensions: false
Silence extension hints
<Dept>/<Cop>: Enabled: false
Disable a cop
<Dept>/<Cop>: Exclude: - <glob>
Skip paths for one cop
<Dept>/<Cop>: Max: <n>
Tune a numeric limit
<Dept>/<Cop>: Severity: <level>
Change severity of a cop
<Dept>: Enabled: false
Disable a whole department
AllCops: FailLevel: <sev>
Config form of --fail-level