Skip to content

Instantly share code, notes, and snippets.

@ZabdiAG
Created March 16, 2016 19:04
Show Gist options
  • Save ZabdiAG/b0af3c773fa50bf8e70c to your computer and use it in GitHub Desktop.
Save ZabdiAG/b0af3c773fa50bf8e70c to your computer and use it in GitHub Desktop.
Resume rubocop implementation in contalink project
##Short description about Rubocopy
On his official github(https://github.com/bbatsov/rubocop) it says:
"RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide."
##Steps to install
Just run the command:
$ gem install rubocop
##How to use it
Just run the "rubocop" command, and the file/folder to analyze the code, that's all. The command will look for errors/offenses and it will print out to terminal with a brief description
##Samples with dev-contalink
These samples where ran on branch master.
$ cd /PATH/TO/CONTALINK
$ rubocop app/controllers/usuarios_controller.rb
It will print out something like this
Inspecting 1 file
W
Offenses:
app/controllers/usuarios_controller.rb:2:1: C: Class has too many lines. [333/100]
class UsuariosController < ApplicationController ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/usuarios_controller.rb:2:1: C: Missing top-level class documentation comment.
class UsuariosController < ApplicationController
^^^^^
app/controllers/usuarios_controller.rb:3:41: C: Use the new Ruby 1.9 hash syntax.
before_filter :authenticate_usuario!, :except => [:index, :createUser, :createFirstUser, :password_recovery]
^^^^^^^^^^
1 file inspected, 279 offenses detected
Or you can pass as a folder as an argument, like this:
$ rubocop app/controllers/
It will print out something like this:
Inspecting 118 files
WWWCWWCCWCWWWCCCCWWWWCWWCWCCCCCCCCWWCCCCCCCCCCWCCWWWWWWCWWCCWCCWWWWWCWWWCCWWWCCWWWWWWCWWCCCCWWCWWCCCWWWCCWCWCCCWWCWWCC
Offenses:
app/controllers/cuenta_empresas_controller.rb:2:1: C: Missing top-level class documentation comment.
class CuentaEmpresasController < ApplicationController
^^^^^
118 files inspected, 15161 offenses detected
Of course, when you pass a folder as an argument, rubocop will check all the files and print out the errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment