rubocop
Analyze and enforce Ruby code style
TLDR
Check all files in the current directory (including subdirectories)
Check one or more specific files or directories
Write output to file
View list of cops (linter rules)
Exclude a cop
Run only specified cops
Auto-correct files (experimental)
SYNOPSIS
rubocop [options] [file1 file2 ...]
PARAMETERS
-a, --auto-correct
Automatically correct detected offenses (where possible).-A, --auto-correct-all
Automatically correct all detected offenses (where possible).--[no-]color
Force color output on or off.-c, --config FILE
Specify configuration file to use.-d, --debug
Display debug information.-D, --display-cop-names
Display cop names in the output.-f, --force-exclusion
Force exclusion even when files are explicitly specified.-F, --fail-fast
Stop processing on the first error.-h, --help
Show help message and exit.-l, --lint
Run only lint cops.-o, --out FILE
Write output to a file.-P, --parallel
Parallel code analysis using available CPU cores.-R, --require FILE
Require a Ruby file.-s, --silent
Silence all output except for errors.-v, --version
Show version and exit.
DESCRIPTION
RuboCop is a Ruby static code analyzer and formatter, based on the community Ruby style guide. It analyzes Ruby code, detecting potential style issues, syntax problems, and code smells.
It can automatically correct many style issues, improving code consistency and maintainability. RuboCop is highly configurable, allowing users to customize its behavior to align with project-specific style preferences.
It helps to enforce a consistent coding style across a Ruby project, making it easier for teams to collaborate and reducing the likelihood of errors. It analyzes code based on a set of configurable rules, or 'cops', and reports violations. RuboCop is widely used in the Ruby community and is considered an essential tool for maintaining high-quality Ruby code.
CONFIGURATION
RuboCop's behavior is primarily controlled by a configuration file, typically named .rubocop.yml
, located in the project's root directory. This file specifies which cops are enabled, their configuration settings, and any files or directories to exclude from analysis.
Configuration files can inherit settings from other files, allowing for shared configurations across multiple projects. It uses YAML format for configuration.
COPS
RuboCop's rules are called 'cops'. Each cop focuses on a specific aspect of Ruby code style or best practices.
Cops can be enabled or disabled individually, and their behavior can be customized using configuration options. RuboCop provides a wide range of built-in cops covering various aspects of Ruby development.
SEE ALSO
reek(1), brakeman(1)