From 3c2d74cdaee2456ac78c32392a43c36ac312ff52 Mon Sep 17 00:00:00 2001 From: ydah Date: Fri, 24 May 2024 20:40:18 +0900 Subject: [PATCH 1/2] Add document about Create a new cop --- docs/modules/ROOT/pages/development.adoc | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/modules/ROOT/pages/development.adoc b/docs/modules/ROOT/pages/development.adoc index c0a7f710..1f2ad394 100644 --- a/docs/modules/ROOT/pages/development.adoc +++ b/docs/modules/ROOT/pages/development.adoc @@ -1,3 +1,44 @@ = Development 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]. + +== Create a new cop + +NOTE: Clone the repository and run `bundle install` if not done yet. +The following rake task can only be run inside the rubocop project directory itself. + +Use the bundled rake task `new_cop` to generate a cop template: + +[source,sh] +---- +$ bundle exec rake 'new_cop[RSpecRails/CopName]' +[create] lib/rubocop/cop/rspec_rails/cop_name.rb +[create] spec/rubocop/cop/rspec_rails/cop_name_spec.rb +[modify] lib/rubocop/cop/rspec_rails_cops.rb - `require_relative 'rspec_rails/cop_name'` was injected. +[modify] A configuration for the cop is added into config/default.yml. +Do 4 steps: + 1. Modify the description of RSpecRails/CopName in config/default.yml + 2. Implement your new cop in the generated file! + 3. Add an entry about new cop to CHANGELOG.md + 4. Commit your new cop with a message such as + e.g. "Add new `#{badge}` cop" +---- + +=== Choose a Name + +Use the following rules to give the new cop a name: + +* Pick a department. See the xref:cops.adoc[list of existing departments] +* The name is self-explanatory +* The name explains the offense the cop detects, e.g. `ExtraSpacing` +* The name starts with a noun instead of a verb, e.g. `ArrayAlignment` instead of `AlignArray` +* The name is easy to understand, e.g. `IndentationStyle` instead of just `Tab` +* The name is specific, e.g. `DuplicateHashKey` instead of just `DuplicateKey` +* The name is neutral when possible and accommodates multiple styles when feasible, e.g. `EmptyLineBeforeBegin`. +* The name uses commonly-used terms, e.g. `RedundantPercentI` instead of `RedundantPercentSymbolArray` +* The name uses correct terms, e.g. arguments in a method call, and parameters in a method signature +* Lines with no symbols are called "empty", not "blank", e.g. `LeadingEmptyLines` instead of `LeadingBlankLines` +* Prefer "redundant" to "unneeded", e.g. `RedundantSelf` instead of `UnneededSelf` + +See the https://github.com/rubocop/rubocop-rspec/blob/dad11fc2d341f88d395b7196f78c7ba67fcb4c17/config/obsoletion.yml["renamed" section of `config/obsoletion.yml`] +for good and bad examples (old name is on the left, new name on the right). From 3bc33de7cf04ba281be9bd0047f7d3da72bc338f Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Fri, 24 May 2024 16:51:18 +0300 Subject: [PATCH 2/2] Better sourc of good and bad examples --- docs/modules/ROOT/pages/development.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/development.adoc b/docs/modules/ROOT/pages/development.adoc index 1f2ad394..d88aa647 100644 --- a/docs/modules/ROOT/pages/development.adoc +++ b/docs/modules/ROOT/pages/development.adoc @@ -40,5 +40,5 @@ Use the following rules to give the new cop a name: * Lines with no symbols are called "empty", not "blank", e.g. `LeadingEmptyLines` instead of `LeadingBlankLines` * Prefer "redundant" to "unneeded", e.g. `RedundantSelf` instead of `UnneededSelf` -See the https://github.com/rubocop/rubocop-rspec/blob/dad11fc2d341f88d395b7196f78c7ba67fcb4c17/config/obsoletion.yml["renamed" section of `config/obsoletion.yml`] +See the https://github.com/rubocop/rubocop/blob/12fd014e255617a08b7b42aa5df0745e7382af88/config/obsoletion.yml#L4["renamed" section of `config/obsoletion.yml`] for good and bad examples (old name is on the left, new name on the right).