Linters
What is RuboCop? An introduction to the Ruby linter and code formatter
RuboCop is a Ruby linter and code formatter based on the community Ruby Style Guide. It checks Ruby code against that guide, reports problems and fixes most of them automatically. It has existed since 2012.
- Tool
- RuboCop
- Made by
- RuboCop
- Official site
- rubocop.org
- Category
- Linters
Who makes RuboCop
RuboCop is developed under the RuboCop name, and the project's official website is linked below. Several of its plugins are maintained by the RuboCop team, which keeps framework and library support close to the core tool.
Official website: rubocop.org
What RuboCop is for
RuboCop's job is to keep Ruby code consistent and correct. It checks code against the community Ruby Style Guide and covers four broad areas: bugs, style, layout and complexity. Because it is configurable to team preferences, the guide acts as a starting point rather than a fixed rule set.
RuboCop never executes the code it inspects. It parses source into a syntax tree using Prism or the parser gem, so a run reads your files without running them.
Who RuboCop is for
RuboCop is aimed at Ruby developers and at teams that want to enforce a Ruby style guide. A single developer can use it to catch problems early. A team can use it to settle style questions once, in configuration, instead of in code review.
Notable capabilities
RuboCop combines a large set of organised checks with several ways to apply fixes and adopt it gradually.
Its main capabilities are:
- Cops and departments: checks are organised as cops within departments such as Lint, Style, Layout, Naming, Metrics and Security. Cops are split into those on by default, pending cops that become active in the next major release, and opt-in cops.
- Safe and risky autocorrection: rubocop -a applies only corrections that cannot change code behaviour, while -A also applies riskier ones. The --diff option previews the patch without modifying any files.
- Formatting: the Layout cops let RuboCop act as a formatter, and rubocop -x runs only those cops.
- Configuration: settings live in a single .rubocop.yml, which can inherit from a shared config.
- Gradual adoption: the --auto-gen-config option records existing offenses in .rubocop_todo.yml, which eases adoption on old codebases.
- Extensibility: plugins add framework and library knowledge, and projects can write custom cops for in-house conventions.
- Editor support: a built-in language server gives editors live offenses and quick fixes.
- Cross-file checks: an optional rubydex gem enables a whole-project index. This feature is experimental and requires Ruby 3.2 or newer.
How RuboCop fits linters
Within the linters category, RuboCop is the Ruby-specific entry. It combines linting and formatting in one tool, so a Ruby project can cover both style enforcement and bug-oriented checks without a separate formatter.
In Linthelm's wider niche of linters, static analysis and code quality, RuboCop sits at the style-and-correctness end. Its Lint, Metrics and Security departments reach beyond style, while the opt-in and pending cop categories let a team control how quickly new checks take effect.
For speed, a --server mode keeps a warm process for fast runs. It is unavailable on Windows and JRuby.
Frequently asked questions
What is RuboCop used for?
RuboCop is used to lint and format Ruby code. It checks code against the community Ruby Style Guide, reports problems and fixes most of them automatically.
What is the difference between rubocop -a and -A?
rubocop -a applies only corrections that cannot change code behaviour. -A also applies riskier corrections.
Can RuboCop be added to an old codebase?
Yes. The --auto-gen-config option records existing offenses in .rubocop_todo.yml, which eases adoption on old codebases.
Does RuboCop run my Ruby code?
No. RuboCop never executes the code. It parses it into a syntax tree using Prism or the parser gem.
Does RuboCop work in editors?
Yes. It includes a built-in language server that gives editors live offenses and quick fixes.
Linthelm is independent and is not affiliated with RuboCop. Product names belong to their owners. Features change; confirm details on the official website.