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).
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:
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:
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:
Of course, you can change the settings to your personal preferences. Have fun and enjoy exploring Rubocop.