va-ruby-style
This is a ruby gem that holds Visible Alpha's default set of coding style rules. It's basically a rubocop wrapper designed with the purpose of sharing a common set of rules across multiple ruby projects.
Installation
Install the gem directly:
gem install va-ruby-style
Or add it to your Gemfile:
gem 'va-ruby-style'
Setup
The gem can be easily set up both in new or existing projects (even if already using rubocop directly), although the configuration process will be slightly different.
New projects
This is the easiest form: simply add the gem to the project's Gemfile and run va_ruby_style init. This command will create the project's .rubocop.yml file.
From this moment, we're able to use rubocop normally and check if all files follow the specified base style rules.
Existing projects
For existing projects, the process will be slightly different since a .rubocop.yml file might already exist.
The init command will not overwrite existing rubocop configuration files so, the existing .rubocop.yml should be removed before running the va-ruby-style init command. In addition to that, rubocop should be removed from the Gemfile, since it's no longer a direct project dependency.
After that, the following rubocop commands should be run:
rubocop -ato fix any offenses that can be automatically fixed in the existing files (according to the new set of rules);rubocop --auto-gen-configto add offenses that can't be automatically fixed to therubocop_todo.ymlfile.
Note: Rules should not be disabled/enabled directly in project files, where an offense occurs. The rubocop_todo.yml file should be used to centralize all existing and pending offenses instead.
Extending the default set of rules
The generated .rubocop.yml file includes a default set of rules set in the gem's default.yml file. These rules can be changed and/or new rules can be added to a specific project though.
In order to add a new rule (not included in the default set of rules), simply add it after the inherit_gem setup:
inherit_gem:
va-ruby-style:
- default.yml
ProjectSpecificRule:
Enabled: true
To extend and/or modify an existing rule, reference it and add the necessary modifiers (Ex.: exclude particular files):
inherit_gem:
va-ruby-style:
- default.yml
Style/MethodCallWithArgsParentheses:
Exclude:
- 'Gemfile'
- 'db/migrate/*'