diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-11 21:13:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-11 21:13:14 +0300 |
commit | 9e40efa6a6cb39c0a4a6d7d43f7445e2d6e25172 (patch) | |
tree | 3b5db6c0284b8c37d6afcae4e1340c3fe57c90f9 /rubocop | |
parent | d06e4d855aed9148571c7fd95fe02f208a017dd3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/lint/last_keyword_argument.rb | 89 | ||||
-rw-r--r-- | rubocop/rubocop-ruby27.yml | 9 | ||||
-rw-r--r-- | rubocop/rubocop-ruby30.yml | 16 |
3 files changed, 0 insertions, 114 deletions
diff --git a/rubocop/cop/lint/last_keyword_argument.rb b/rubocop/cop/lint/last_keyword_argument.rb deleted file mode 100644 index f50c25f7924..00000000000 --- a/rubocop/cop/lint/last_keyword_argument.rb +++ /dev/null @@ -1,89 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module Lint - # This cop only works if there are files from deprecation_toolkit. You can - # generate these files by: - # - # 1. Running specs with RECORD_DEPRECATIONS=1 - # 1. Downloading the complete set of deprecations/ files from a CI - # pipeline (see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47720) - class LastKeywordArgument < RuboCop::Cop::Base - extend RuboCop::Cop::AutoCorrector - - MSG = 'Using the last argument as keyword parameters is deprecated' - - DEPRECATIONS_GLOB = File.expand_path('../../../deprecations/**/*.yml', __dir__) - KEYWORD_DEPRECATION_STR = 'maybe ** should be added to the call' - - def on_send(node) - return if target_ruby_version >= 3.0 - - arg = get_last_argument(node) - return unless arg - - return unless known_match?(processed_source.file_path, node.first_line, node.method_name.to_s) - - return if arg.children.first.respond_to?(:kwsplat_type?) && arg.children.first&.kwsplat_type? - - # parser thinks `a: :b, c: :d` is hash type, it's actually kwargs - return if arg.hash_type? && !arg.source.match(/\A{/) - - add_offense(arg) do |corrector| - if arg.hash_type? - kwarg = arg.source.sub(/\A{\s*/, '').sub(/\s*}\z/, '') - corrector.replace(arg, kwarg) - elsif arg.splat_type? - corrector.insert_before(arg, '*') - else - corrector.insert_before(arg, '**') - end - end - end - - private - - def get_last_argument(node) - return node.arguments[-2] if node.block_argument? - - node.arguments.last - end - - def known_match?(file_path, line_number, method_name) - method_name = 'initialize' if method_name == 'new' - - return unless self.class.keyword_warnings[method_name] - - file_path_from_root = file_path.sub(File.expand_path('../../..', __dir__), '') - file_and_line = "#{file_path_from_root}:#{line_number}" - - self.class.keyword_warnings[method_name].any? do |warning| - warning.include?(file_and_line) - end - end - - def self.keyword_warnings - @keyword_warnings ||= keywords_list - end - - def self.keywords_list - hash = Dir.glob(DEPRECATIONS_GLOB).each_with_object({}) do |file, hash| - hash.merge!(YAML.safe_load(File.read(file))) - end - - 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 - end -end diff --git a/rubocop/rubocop-ruby27.yml b/rubocop/rubocop-ruby27.yml deleted file mode 100644 index 29957defeb0..00000000000 --- a/rubocop/rubocop-ruby27.yml +++ /dev/null @@ -1,9 +0,0 @@ -# RuboCop configuration adjustments during the transition time from Ruby 2.7 to -# Ruby 3.0. This configuration should be removed after the transition has been -# completed. - -# These cops are enabled in Ruby 3.0 (rubocop-30.yml). -Style/MutableConstant: - Enabled: false -Style/RedundantFreeze: - Enabled: false diff --git a/rubocop/rubocop-ruby30.yml b/rubocop/rubocop-ruby30.yml deleted file mode 100644 index b984d761b80..00000000000 --- a/rubocop/rubocop-ruby30.yml +++ /dev/null @@ -1,16 +0,0 @@ -# RuboCop configuration adjustments during the transition time from Ruby 2.7 to -# Ruby 3.0. -# -# After the transition has been completed: -# * Move all configuration which enabled or tweaked cops to .rubocop.yml. -# * Remove all remaining configuration. - -# These cops are disabled in Ruby 2.7 (rubocop-27.yml). -Style/MutableConstant: - Enabled: true -Style/RedundantFreeze: - Enabled: true - -# No longer needed because Ruby 3.0 will fail due to kwargs issues. -Lint/LastKeywordArgument: - Enabled: false |