diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 18:06:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 18:06:11 +0000 |
commit | 4f05a630951858cc2b7dafada27f3dcf87ba29bd (patch) | |
tree | 1b87468300c53594465ca10f89e082651a08707c /rubocop | |
parent | 7cdd70dcec27402e89e65451b4b1feb75b5eb267 (diff) | |
download | gitlab-ce-4f05a630951858cc2b7dafada27f3dcf87ba29bd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/put_project_routes_under_scope.rb | 43 | ||||
-rw-r--r-- | rubocop/rubocop.rb | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/rubocop/cop/put_project_routes_under_scope.rb b/rubocop/cop/put_project_routes_under_scope.rb new file mode 100644 index 00000000000..02189f43ea0 --- /dev/null +++ b/rubocop/cop/put_project_routes_under_scope.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +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 + 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 diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index 159892ae0c1..49d582bf034 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -14,6 +14,7 @@ require_relative 'cop/avoid_break_from_strong_memoize' require_relative 'cop/avoid_route_redirect_leading_slash' require_relative 'cop/line_break_around_conditional_block' require_relative 'cop/prefer_class_methods_over_module' +require_relative 'cop/put_project_routes_under_scope' require_relative 'cop/migration/add_column' require_relative 'cop/migration/add_concurrent_foreign_key' require_relative 'cop/migration/add_concurrent_index' |