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-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /rubocop/routes_under_scope.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'rubocop/routes_under_scope.rb')
-rw-r--r--rubocop/routes_under_scope.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/rubocop/routes_under_scope.rb b/rubocop/routes_under_scope.rb
new file mode 100644
index 00000000000..3f049bb09fa
--- /dev/null
+++ b/rubocop/routes_under_scope.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module RuboCop
+ # Common code used to implement cops checking routes outside of /-/ scope.
+ #
+ # Examples:
+ # * RuboCop::Cop::PutProjectRoutesUnderScope
+ # * RuboCop::Cop::PutGroupRoutesUnderScope
+ module RoutesUnderScope
+ ROUTE_METHODS = Set.new(%i[resource resources get post put patch delete]).freeze
+
+ def on_send(node)
+ return unless route_method?(node)
+ return unless outside_scope?(node)
+
+ add_offense(node)
+ end
+
+ def outside_scope?(node)
+ node.each_ancestor(:block).none? do |parent|
+ dash_scope?(parent.to_a.first)
+ end
+ end
+
+ def route_method?(node)
+ ROUTE_METHODS.include?(node.method_name)
+ end
+ end
+end