Skip to content

Commit

Permalink
Merge pull request #1445 from koic/fix_an_error_when_using_target_rai…
Browse files Browse the repository at this point in the history
…ls_version

[Fix #1442] Fix an incorrect behavior when using `AllCops: TargetRailsVersion`
  • Loading branch information
koic authored Feb 17, 2025
2 parents d8bb510 + da9d36f commit 063bf20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_when_using_target_rails_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1442](https://github.com/rubocop/rubocop-rails/issues/1442): Fix an incorrect behavior when using `AllCops: TargetRailsVersion`. ([@koic][])
17 changes: 17 additions & 0 deletions lib/rubocop/rails/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,25 @@ def rules(_context)

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

# FIXME: This is a dirty hack relying on a private constant to prevent
# "Warning: AllCops does not support TargetRailsVersion parameter".
# It should be updated to a better design in the future.
without_warnings do
ConfigValidator.const_set(:COMMON_PARAMS, ConfigValidator::COMMON_PARAMS.dup << 'TargetRailsVersion')
end

LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
end

private

def without_warnings
original_verbose = $VERBOSE
$VERBOSE = nil
yield
ensure
$VERBOSE = original_verbose
end
end
end
end

0 comments on commit 063bf20

Please sign in to comment.