From bcd4d326389479b394d10558b93a1ba5beff789b Mon Sep 17 00:00:00 2001 From: ydah Date: Fri, 24 May 2024 20:43:41 +0900 Subject: [PATCH] Change step with new_cop command for rubocop-rspec_rails before: ``` Do 4 steps: 1. Modify the description of RSpecRails/CopName in config/default.yml 2. Implement your new cop in the generated file! 3. Commit your new cop with a message such as e.g. "Add new `RSpecRails/CopName` cop" 4. Run `bundle exec rake changelog:new` to generate a changelog entry ``` after: ``` Do 4 steps: 1. Modify the description of RSpecRails/CopName in config/default.yml 2. Implement your new cop in the generated file! 3. Commit your new cop with a message such as e.g. "Add new `RSpecRails/CopName` cop" 4. Add an entry about new cop to CHANGELOG.md ``` --- Rakefile | 3 ++- lib/rubocop/rspec_rails/cop/generator.rb | 25 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 lib/rubocop/rspec_rails/cop/generator.rb diff --git a/Rakefile b/Rakefile index d4c34f14..49351c98 100644 --- a/Rakefile +++ b/Rakefile @@ -88,13 +88,14 @@ task default: %i[build_config spec desc 'Generate a new cop template' task :new_cop, [:cop] do |_task, args| require 'rubocop' + require_relative 'lib/rubocop/rspec_rails/cop/generator' cop_name = args.fetch(:cop) do warn "usage: bundle exec rake 'new_cop[Department/Name]'" exit! end - generator = RuboCop::Cop::Generator.new(cop_name) + generator = RuboCop::RSpecRails::Cop::Generator.new(cop_name) generator.write_source generator.write_spec generator.inject_require( diff --git a/lib/rubocop/rspec_rails/cop/generator.rb b/lib/rubocop/rspec_rails/cop/generator.rb new file mode 100644 index 00000000..ca8ce767 --- /dev/null +++ b/lib/rubocop/rspec_rails/cop/generator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module RuboCop + module RSpecRails + module Cop + # Source and spec generator for new cops + # + # This generator will take a cop name and generate a source file + # and spec file when given a valid qualified cop name. + # @api private + class Generator < RuboCop::Cop::Generator + def todo + <<~TODO + Do 4 steps: + 1. Modify the description of #{badge} 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" + TODO + end + end + end + end +end