Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ConfigObsoletion so that parameters can be deprecated but still accepted #9100

Merged
merged 1 commit into from Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/change_update_configobsoletion_so_that.md
@@ -0,0 +1 @@
* [#9100](https://github.com/rubocop-hq/rubocop/pull/9100): Update `ConfigObsoletion` so that parameters can be deprecated but still accepted. ([@dvandersluis][])
18 changes: 15 additions & 3 deletions lib/rubocop/config_obsoletion.rb
Expand Up @@ -104,6 +104,7 @@ class ConfigObsoletion
OBSOLETE_COPS = Hash[*(RENAMED_COPS + MOVED_COPS + REMOVED_COPS +
REMOVED_COPS_WITH_REASON + SPLIT_COPS).flatten]

# Parameters can be deprecated but not disabled by setting `severity: :warning`
OBSOLETE_PARAMETERS = [
{
cops: %w[Layout/SpaceAroundOperators Style/SpaceAroundOperators],
Expand Down Expand Up @@ -214,8 +215,11 @@ class ConfigObsoletion
}
].freeze

attr_reader :warnings

def initialize(config)
@config = config
@warnings = []
end

def reject_obsolete_cops_and_parameters
Expand Down Expand Up @@ -256,9 +260,17 @@ def obsolete_enforced_style_message(cop, param, enforced_style, alternative)
end

def obsolete_parameters
OBSOLETE_PARAMETERS.map do |params|
obsolete_parameter_message(params[:cops], params[:parameters],
params[:alternative])
OBSOLETE_PARAMETERS.collect do |params|
messages = obsolete_parameter_message(params[:cops], params[:parameters],
params[:alternative])

# Warnings are collected separately and not added to the error message
if messages && params.fetch(:severity, :error) == :warning
@warnings.concat(messages)
next
end

messages
end
end

Expand Down
9 changes: 8 additions & 1 deletion lib/rubocop/config_validator.rb
Expand Up @@ -42,7 +42,7 @@ def validate
ConfigLoader.default_configuration.key?(key)
end

@config_obsoletion.reject_obsolete_cops_and_parameters
check_obsoletions

alert_about_unrecognized_cops(invalid_cop_names)
check_target_ruby
Expand All @@ -68,6 +68,13 @@ def validate_section_presence(name)

attr_reader :target_ruby

def check_obsoletions
@config_obsoletion.reject_obsolete_cops_and_parameters
return unless @config_obsoletion.warnings.any?

warn Rainbow("Warning: #{@config_obsoletion.warnings.join("\n")}").yellow
end

def check_target_ruby
return if target_ruby.supported?

Expand Down