Skip to content

Commit da9d36f

Browse files
committed
[Fix #1442] Fix an incorrect behavior when using AllCops: TargetRailsVersion
This PR fixes an incorrect behavior when using `AllCops: TargetRailsVersion`. This suppresses the following warning when `TargetRailsVersion` is defined on the user side: ```console $ bundle exec rubocop (snip) Warning: AllCops does not support TargetRailsVersion parameter. Supported parameters are: - RubyInterpreters - Include - Exclude - DefaultFormatter - DisplayCopNames - DisplayStyleGuide - StyleGuideBaseURL - DocumentationBaseURL - DocumentationExtension - ExtraDetails - StyleGuideCopsOnly - EnabledByDefault - DisabledByDefault - NewCops - UseCache - MaxFilesInCache - CacheRootDirectory - AllowSymlinksInCacheRootDirectory - TargetRubyVersion - ParserEngine - SuggestExtensions - ActiveSupportExtensionsEnabled - StringLiteralsFrozenByDefault ``` This is a dirty hack relying on a private constant to prevent the warning. It should be updated to a better design in the future. Fixes #1442.
1 parent 405faca commit da9d36f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1442](https://github.com/rubocop/rubocop-rails/issues/1442): Fix an incorrect behavior when using `AllCops: TargetRailsVersion`. ([@koic][])

lib/rubocop/rails/plugin.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ def rules(_context)
2424

2525
ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
2626

27+
# FIXME: This is a dirty hack relying on a private constant to prevent
28+
# "Warning: AllCops does not support TargetRailsVersion parameter".
29+
# It should be updated to a better design in the future.
30+
without_warnings do
31+
ConfigValidator.const_set(:COMMON_PARAMS, ConfigValidator::COMMON_PARAMS.dup << 'TargetRailsVersion')
32+
end
33+
2734
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
2835
end
36+
37+
private
38+
39+
def without_warnings
40+
original_verbose = $VERBOSE
41+
$VERBOSE = nil
42+
yield
43+
ensure
44+
$VERBOSE = original_verbose
45+
end
2946
end
3047
end
3148
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy