Using Rubocop in Atom

Recently our team started using Rubocop to maintain code styling. Most of us currently use Atom because it is a tremendously beautiful and versatile text editor. Out of the box, Rubocop is a command line tool. This works fine, but it’s nice to get instant feedback as your are editing your code in Atom.

Enter the world of linter + linter-rubocop; two Atom plugins that automatically inspect your code in real time for any problems defined in your Rubocop files. Installing them is dead simple:

1. In your terminal, run apm install linter (if not already installed).
2. Run apm install linter-rubocop.

This automatically uses the default Rubocop configuration. That’s fine, but what if your team already has a rubocop.yml file you want to use? No problem.

In Atom, go to the package settings for linter-rubocop. Scroll down to settings. Enter something like this:

Screen Shot 2016-09-08 at 11.21.16 AM

This controls the command you want to execute when the linter runs. I set the --config /Users/aualdrich/rubocop.yml to tell Rubocop to use the settings our team likes. You can set this to whatever file you already use.

Now, there are a couple of additional settings you’ll probably want to configure for the linter. Here’s a screenshot of what mine look like:

Screen Shot 2016-09-08 at 11.34.59 AM

In particular, I set the “Show Error Panel” to on. This shows all your errors down at the bottom of Atom. If it is too annoying, you can toggle it down at the bottom left:

Screen Shot 2016-09-08 at 11.36.28 AM

Of course, you can change the settings to your personal preferences. Have fun and enjoy exploring Rubocop.

view on github

Ready to get started?