DEV Community 👩‍💻👨‍💻

Jayesh Mann
Jayesh Mann

Posted on • Updated on

Rubocop - Linting QuickStart for Ruby

Knowledge Base: Lint, or a linter, is a static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs.

Make sure you have your ruby environment(check compatibility) working before proceeding.

Installation

Simply run

% gem install rubocop
Enter fullscreen mode Exit fullscreen mode

Configuration

Create a .rubocop.yml file in your home(% cd ~) directory for all ruby projects. Alternatively, you can create it in your project directory.

Default Configuration

Default Configuration

Recommended Configuration

Jayesh's rubocop configuration


Usage

Check

In your project's directory,

% rubocop
Enter fullscreen mode Exit fullscreen mode

or you can specify a file or a directory of your choosing.

% rubocop lib/file.rb spec/
Enter fullscreen mode Exit fullscreen mode

If you don't have rubocop on your terminal, try bundle exec rubocop

Correct

% rubocop -a
Enter fullscreen mode Exit fullscreen mode

Knowledge Base: Only safe offenses will be fixed with -a


Official Links

Official Website

Official Documentation

Community Ruby Style Guide

All rules

Here is the list of rules with their categories:
https://docs.rubocop.org/rubocop/cops.html


More Guides

RuboCop: How to install and configure

Installing and Running Rubocop


License: AGPL-3.0-or-later

Top comments (0)

🤔 Did you know?

 
🎙 DEV hosts some podcasts that you can find on our Podcasts page.