DEV Community

Jayesh Mann
Jayesh Mann

Posted on • Edited on

4 2

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay