|
1 | 1 | = Development
|
2 | 2 |
|
3 | 3 | This page describes considerations when developing RSpec Rails-specific cops. It is intended to be a complement to the general https://docs.rubocop.org/rubocop/development.html[RuboCop development documentation].
|
| 4 | + |
| 5 | +== Create a new cop |
| 6 | + |
| 7 | +NOTE: Clone the repository and run `bundle install` if not done yet. |
| 8 | +The following rake task can only be run inside the rubocop project directory itself. |
| 9 | + |
| 10 | +Use the bundled rake task `new_cop` to generate a cop template: |
| 11 | + |
| 12 | +[source,sh] |
| 13 | +---- |
| 14 | +$ bundle exec rake 'new_cop[RSpecRails/CopName]' |
| 15 | +[create] lib/rubocop/cop/rspec_rails/cop_name.rb |
| 16 | +[create] spec/rubocop/cop/rspec_rails/cop_name_spec.rb |
| 17 | +[modify] lib/rubocop/cop/rspec_rails_cops.rb - `require_relative 'rspec_rails/cop_name'` was injected. |
| 18 | +[modify] A configuration for the cop is added into config/default.yml. |
| 19 | +Do 4 steps: |
| 20 | + 1. Modify the description of RSpecRails/CopName in config/default.yml |
| 21 | + 2. Implement your new cop in the generated file! |
| 22 | + 3. Add an entry about new cop to CHANGELOG.md |
| 23 | + 4. Commit your new cop with a message such as |
| 24 | + e.g. "Add new `#{badge}` cop" |
| 25 | +---- |
| 26 | + |
| 27 | +=== Choose a Name |
| 28 | + |
| 29 | +Use the following rules to give the new cop a name: |
| 30 | + |
| 31 | +* Pick a department. See the xref:cops.adoc[list of existing departments] |
| 32 | +* The name is self-explanatory |
| 33 | +* The name explains the offense the cop detects, e.g. `ExtraSpacing` |
| 34 | +* The name starts with a noun instead of a verb, e.g. `ArrayAlignment` instead of `AlignArray` |
| 35 | +* The name is easy to understand, e.g. `IndentationStyle` instead of just `Tab` |
| 36 | +* The name is specific, e.g. `DuplicateHashKey` instead of just `DuplicateKey` |
| 37 | +* The name is neutral when possible and accommodates multiple styles when feasible, e.g. `EmptyLineBeforeBegin`. |
| 38 | +* The name uses commonly-used terms, e.g. `RedundantPercentI` instead of `RedundantPercentSymbolArray` |
| 39 | +* The name uses correct terms, e.g. arguments in a method call, and parameters in a method signature |
| 40 | +* Lines with no symbols are called "empty", not "blank", e.g. `LeadingEmptyLines` instead of `LeadingBlankLines` |
| 41 | +* Prefer "redundant" to "unneeded", e.g. `RedundantSelf` instead of `UnneededSelf` |
| 42 | + |
| 43 | +See the https://github.com/rubocop/rubocop-rspec/blob/dad11fc2d341f88d395b7196f78c7ba67fcb4c17/config/obsoletion.yml["renamed" section of `config/obsoletion.yml`] |
| 44 | +for good and bad examples (old name is on the left, new name on the right). |
0 commit comments