From 03d9d5e38c843c938fc2ad81d81c8bc1cb073822 Mon Sep 17 00:00:00 2001 From: Justin Searls Date: Mon, 1 May 2023 09:39:58 -0400 Subject: [PATCH] Add TargetRailsVersion to default.yml After discovering that a valid configuration can't be created programmatically if it includes `TargetRailsVersion` without [patching it in](https://github.com/rubocop/rubocop-rails/blob/master/lib/rubocop/rails/inject.rb#L14) by doing an `instance_variable_set` on the `ConfigLoader`'s `@default_configuration`, it seems appropriate to explicitly list this property even though it's specific to rubocop-rails. For example, before this commit, running: ```ruby RuboCop::Config.create({ "AllCops" => { "TargetRailsVersion" => 5.2 } }, "some_path") ``` Will emit this warning: ``` Warning: AllCops does not support TargetRailsVersion parameter. Supported parameters are: - RubyInterpreters - Include - Exclude - DefaultFormatter - DisplayCopNames - DisplayStyleGuide - StyleGuideBaseURL - DocumentationBaseURL - ExtraDetails - StyleGuideCopsOnly - EnabledByDefault - DisabledByDefault - NewCops - UseCache - MaxFilesInCache - CacheRootDirectory - AllowSymlinksInCacheRootDirectory - TargetRubyVersion - SuggestExtensions - ActiveSupportExtensionsEnabled ``` Even though this is the domain of a plugin, it seems appropriate to add it since: 1. `ActiveSupportExtensionsEnabled` has similarly been added (perhaps for the same reason?) 2. RuboCop itself (and not rubocop-rails) actually contains the logic handling this setting in [Config](/lib/rubocop/config.rb#L249-L258) --- config/default.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/default.yml b/config/default.yml index e489328a4184..faa2b918a132 100644 --- a/config/default.yml +++ b/config/default.yml @@ -156,6 +156,8 @@ AllCops: rubocop-capybara: [capybara] # Enable/Disable checking the methods extended by Active Support. ActiveSupportExtensionsEnabled: false + # Used by rubocop-rails to set the version of Rails used by the inspected code + TargetRailsVersion: ~ #################### Bundler ###############################