Rubocop on Vim

 2022-09-18 11:04 UTC  |   Norly Canarias

If you are working with Ruby then you would want to have some guidelines enforced in your codebase. One tool you can use is Rubocop. It analyzes your code and reports those that are not in line with your chosen standard. By default it makes use of the default Ruby community style guide and other common linters, but it allows you to tweak it's behavior (eg. use only specific linters, or set config for each linter).

To use it in Vim we would need to install the following vim plugins using a plug manager of your choice. Personally I use vim-plug.

  Plug 'w0rp/ale'
  Plug 'vim-airline/vim-airline'

Then you would include this snippet in your .vimrc file to enable vim-airline integration with ale. Make sure to reload your vim configuration after installing the plugins and updating the .vimrc file.

Here is an example of Vim and Ale integration in action. I've made some changes so that the status would also display which linter it used to generate the error or warning.

ale_sample

I'm dropping here the link to my vimrc in case you would like to check :)

Tags: