Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 22:34:23 +0300
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 22:34:23 +0300
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /rubocop
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/lint/last_keyword_argument.rb26
-rw-r--r--rubocop/cop/rspec/expect_gitlab_tracking.rb2
-rw-r--r--rubocop/cop/rspec/web_mock_enable.rb39
-rw-r--r--rubocop/rubocop.rb2
4 files changed, 62 insertions, 7 deletions
diff --git a/rubocop/cop/lint/last_keyword_argument.rb b/rubocop/cop/lint/last_keyword_argument.rb
index 430ea66e9a1..9652c1ace8d 100644
--- a/rubocop/cop/lint/last_keyword_argument.rb
+++ b/rubocop/cop/lint/last_keyword_argument.rb
@@ -16,7 +16,7 @@ module RuboCop
KEYWORD_DEPRECATION_STR = 'maybe ** should be added to the call'
def on_send(node)
- arg = node.arguments.last
+ arg = get_last_argument(node)
return unless arg
return unless known_match?(processed_source.file_path, node.first_line, node.method_name.to_s)
@@ -44,13 +44,22 @@ module RuboCop
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)
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
@@ -63,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
diff --git a/rubocop/cop/rspec/expect_gitlab_tracking.rb b/rubocop/cop/rspec/expect_gitlab_tracking.rb
index ba658558705..e3f790f851c 100644
--- a/rubocop/cop/rspec/expect_gitlab_tracking.rb
+++ b/rubocop/cop/rspec/expect_gitlab_tracking.rb
@@ -53,8 +53,6 @@ module RuboCop
)
PATTERN
- RESTRICT_ON_SEND = [:expect, :allow].freeze
-
def on_send(node)
return unless expect_gitlab_tracking?(node)
diff --git a/rubocop/cop/rspec/web_mock_enable.rb b/rubocop/cop/rspec/web_mock_enable.rb
new file mode 100644
index 00000000000..bcf7f95dbbd
--- /dev/null
+++ b/rubocop/cop/rspec/web_mock_enable.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module RSpec
+ class WebMockEnable < RuboCop::Cop::Cop
+ # This cop checks for `WebMock.disable_net_connect!` usage in specs and
+ # replaces it with `webmock_enable!`
+ #
+ # @example
+ #
+ # # bad
+ # WebMock.disable_net_connect!
+ # WebMock.disable_net_connect!(allow_localhost: true)
+ #
+ # # good
+ # webmock_enable!
+
+ MESSAGE = 'Use webmock_enable! instead of calling WebMock.disable_net_connect! directly.'
+
+ def_node_matcher :webmock_disable_net_connect?, <<~PATTERN
+ (send (const nil? :WebMock) :disable_net_connect! ...)
+ PATTERN
+
+ def on_send(node)
+ if webmock_disable_net_connect?(node)
+ add_offense(node, location: :expression, message: MESSAGE)
+ end
+ end
+
+ def autocorrect(node)
+ lambda do |corrector|
+ corrector.replace(node, 'webmock_enable!')
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index 08e09747ae2..c8a573410d8 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -1,4 +1,4 @@
# frozen_string_literal: true
# Auto-require all cops under `rubocop/cop/**/*.rb`
-Dir[File.join(__dir__, 'cop', '**', '*.rb')].each(&method(:require))
+Dir[File.join(__dir__, 'cop', '**', '*.rb')].sort.each(&method(:require))