From 9459cb677d38eb8867932adc3d2b59d28c9b019a Mon Sep 17 00:00:00 2001 From: Tejas Bubane Date: Mon, 20 Apr 2020 23:44:27 +0530 Subject: [PATCH] Allow Generator to take version_added parameter Other libraries like `rubocop-rspec` which rely on rubocop's generator will be able to provide in their own version. --- lib/rubocop/cop/generator.rb | 5 +++-- spec/rubocop/cop/generator_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/cop/generator.rb b/lib/rubocop/cop/generator.rb index 8c34e2bfb11..c46dc08113d 100644 --- a/lib/rubocop/cop/generator.rb +++ b/lib/rubocop/cop/generator.rb @@ -132,11 +132,12 @@ def inject_require(root_file_path: 'lib/rubocop.rb') ).inject end - def inject_config(config_file_path: 'config/default.yml') + def inject_config(config_file_path: 'config/default.yml', + version_added: bump_minor_version) injector = ConfigurationInjector.new(configuration_file_path: config_file_path, badge: badge, - version_added: bump_minor_version) + version_added: version_added) injector.inject do output.puts(format(CONFIGURATION_ADDED_MESSAGE, diff --git a/spec/rubocop/cop/generator_spec.rb b/spec/rubocop/cop/generator_spec.rb index 48f12af2534..c726e40d219 100644 --- a/spec/rubocop/cop/generator_spec.rb +++ b/spec/rubocop/cop/generator_spec.rb @@ -280,6 +280,28 @@ def on_send(node) "#{path}.\n") end end + + context 'with version provided' do + it 'uses the provided version' do + expect(File).to receive(:write).with(path, <<~YAML) + Style/Alias: + Enabled: true + + Style/FakeCop: + Description: 'TODO: Write a description of the cop.' + Enabled: pending + VersionAdded: '1.52' + + Style/Lambda: + Enabled: true + + Style/SpecialGlobalVars: + Enabled: true + YAML + + generator.inject_config(config_file_path: path, version_added: '1.52') + end + end end describe '#snake_case' do