diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /rubocop/cop/put_project_routes_under_scope.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'rubocop/cop/put_project_routes_under_scope.rb')
-rw-r--r-- | rubocop/cop/put_project_routes_under_scope.rb | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/rubocop/cop/put_project_routes_under_scope.rb b/rubocop/cop/put_project_routes_under_scope.rb index 02189f43ea0..cddb147324f 100644 --- a/rubocop/cop/put_project_routes_under_scope.rb +++ b/rubocop/cop/put_project_routes_under_scope.rb @@ -1,43 +1,19 @@ # frozen_string_literal: true +require_relative '../routes_under_scope' + module RuboCop module Cop # Checks for a project routes outside '/-/' scope. # For more information see: https://gitlab.com/gitlab-org/gitlab/issues/29572 class PutProjectRoutesUnderScope < RuboCop::Cop::Cop + include RoutesUnderScope + MSG = 'Put new project routes under /-/ scope' def_node_matcher :dash_scope?, <<~PATTERN (:send nil? :scope (:str "-")) PATTERN - - def on_send(node) - return unless in_project_routes?(node) - return unless resource?(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 in_project_routes?(node) - path = node.location.expression.source_buffer.name - dirname = File.dirname(path) - filename = File.basename(path) - - dirname.end_with?('config/routes') && - filename.end_with?('project.rb') - end - - def resource?(node) - node.method_name == :resource || - node.method_name == :resources - end end end end |