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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 18:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 18:07:45 +0300
commitf1a40d0db939dfe8ff95d385e652ff72566be765 (patch)
treecdca36cb171cdffff2739c37c23e74914e57a836 /rubocop
parentac1dca43baa7b3b1ac7d60d89ad60fdeefed0b80 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/ban_catch_throw.rb34
-rw-r--r--rubocop/cop/gitlab/keys-first-and-values-first.rb2
2 files changed, 35 insertions, 1 deletions
diff --git a/rubocop/cop/ban_catch_throw.rb b/rubocop/cop/ban_catch_throw.rb
new file mode 100644
index 00000000000..42301d5512f
--- /dev/null
+++ b/rubocop/cop/ban_catch_throw.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ # Bans the use of 'catch/throw', as exceptions are better for errors and
+ # they are equivalent to 'goto' for flow control, with all the problems
+ # that implies.
+ #
+ # @example
+ # # bad
+ # catch(:error) do
+ # throw(:error)
+ # end
+ #
+ # # good
+ # begin
+ # raise StandardError
+ # rescue StandardError => err
+ # # ...
+ # end
+ #
+ class BanCatchThrow < RuboCop::Cop::Cop
+ MSG = "Do not use catch or throw unless a gem's API demands it."
+
+ def on_send(node)
+ receiver, method_name, _ = *node
+
+ return unless receiver.nil? && %i[catch throw].include?(method_name)
+
+ add_offense(node, location: :expression)
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/gitlab/keys-first-and-values-first.rb b/rubocop/cop/gitlab/keys-first-and-values-first.rb
index 9b68957cba2..544f9800304 100644
--- a/rubocop/cop/gitlab/keys-first-and-values-first.rb
+++ b/rubocop/cop/gitlab/keys-first-and-values-first.rb
@@ -26,7 +26,7 @@ module RuboCop
elsif node.descendants.first.method_name == :keys
'.each_key'
else
- throw("Expect '.values.first' or '.keys.first', but get #{node.descendants.first.method_name}.first")
+ throw("Expect '.values.first' or '.keys.first', but get #{node.descendants.first.method_name}.first") # rubocop:disable Cop/BanCatchThrow
end
upto_including_keys_or_values = node.descendants.first.source_range