From 716896e8cac8a516cd36efada8c8c5f383b63f62 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 13 Jan 2021 18:10:55 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- rubocop/cop/lint/last_keyword_argument.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'rubocop') diff --git a/rubocop/cop/lint/last_keyword_argument.rb b/rubocop/cop/lint/last_keyword_argument.rb index 0910577ad67..9652c1ace8d 100644 --- a/rubocop/cop/lint/last_keyword_argument.rb +++ b/rubocop/cop/lint/last_keyword_argument.rb @@ -52,11 +52,14 @@ module RuboCop def known_match?(file_path, line_number, method_name) file_path_from_root = file_path.sub(File.expand_path('../../..', __dir__), '') + file_and_line = "#{file_path_from_root}:#{line_number}" method_name = 'initialize' if method_name == 'new' - self.class.keyword_warnings.any? do |warning| - warning.include?("#{file_path_from_root}:#{line_number}") && warning.include?("called method `#{method_name}'") + return unless self.class.keyword_warnings[method_name] + + self.class.keyword_warnings[method_name].any? do |warning| + warning.include?(file_and_line) end end @@ -69,7 +72,16 @@ module RuboCop hash.merge!(YAML.safe_load(File.read(file))) end - hash.values.flatten.select { |str| str.include?(KEYWORD_DEPRECATION_STR) }.uniq + hash.values.flatten.each_with_object({}) do |str, results| + next unless str.include?(KEYWORD_DEPRECATION_STR) + + match_data = str.match(/called method `([^\s]+)'/) + next unless match_data + + key = match_data[1] + results[key] ||= [] + results[key] << str + end end end end -- cgit v1.2.3