The Ruby
Linter/Formatter that
Serves and Protects
RuboCop is a Ruby static code checker (linter) and formatter based on the community-driven Ruby Style Guide
Basic Usage
$ gem install rubocop
If you'd rather install using bundler, add a line for it in your Gemfile
(set the require option to false, as it is a standalone tool):
gem 'rubocop', require: false
Find & autocorrect offenses
Check and automatically fix offenses on your Ruby code based on the Ruby Community Style Guide.
Learn moreConfigure cops
Edit the .rubocop.yml configuration file to enable/disable certain cops (checks) and alter their behavior.
Learn moreExtend with plugins
Extend RuboCop with additional cops and formatters. There are many official and third-party extensions available.
Learn more
user_greeting.rb
1# frozen_string_literal: true
2
3# Manages user greeting logic
4class UserGreeting
5 def sayHello(name)
6 if name.nil?
7 name = "stranger"
8 end
9
10 msg = "Hello, #{name}!"
11
12 if msg.length > 20
13 puts msg.upcase
14 end
15
16 return msg
17 end
18end
19
Plugins
.rubocop.yml
1# It's possible to extend RuboCop with additional cops and formatters.
2# Learn more
3#
4# Official Extensions maintained by the RuboCop's team:
5# (clicking on them leads to their GitHub repo)
6
7---
8plugins:
9 - rubocop-performance # Performance optimization analysis
10 - rubocop-rails # Rails-specific analysis
11 - rubocop-rspec # Rspec-specific analysis
12 - rubocop-minitest # Minitest-specific analysis
13 - rubocop-rake # Rake-specific analysis
14 - rubocop-sequel # Code style checking for Sequel gem
15 - rubocop-thread_safety # Thread-safety analysis
16 - rubocop-capybara # Capybara-specific analysis
17 - rubocop-factory_bot # factory_bot-specific analysis
18 - rubocop-rspec_rails # RSpec Rails-specific analysis
19 - rubocop-i18n # i18n wrapper function analysis (gettext and rails-i18n)
20
21# Third-party Extensions:
22# https://docs.rubocop.org/rubocop/extensions.html#third-party-extensions
23
The Ruby linter used by the community
640M+
Downloads
12.8k+
GitHub Stars
580+
Cops