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>2019-12-20 12:07:57 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 12:07:57 +0300
commit7881eb30eaa8b01dbcfe87faa09927c75c7d6e45 (patch)
tree298bc8d2c62b2f2c29cb8ecbcf3de3eaaa6466d9 /rubocop
parent64b66e0cb6d1bfd27abf24e06653f00bddb60597 (diff)
Add latest changes from gitlab-org/gitlab@12-6-stable-ee
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/avoid_route_redirect_leading_slash.rb4
-rw-r--r--rubocop/cop/graphql/authorize_types.rb5
-rw-r--r--rubocop/cop/ignored_columns.rb20
-rw-r--r--rubocop/cop/migration/add_column.rb5
-rw-r--r--rubocop/cop/put_group_routes_under_scope.rb43
-rw-r--r--rubocop/cop/put_project_routes_under_scope.rb43
-rw-r--r--rubocop/rubocop.rb3
7 files changed, 119 insertions, 4 deletions
diff --git a/rubocop/cop/avoid_route_redirect_leading_slash.rb b/rubocop/cop/avoid_route_redirect_leading_slash.rb
index 261d151fb1b..d66e434dc9c 100644
--- a/rubocop/cop/avoid_route_redirect_leading_slash.rb
+++ b/rubocop/cop/avoid_route_redirect_leading_slash.rb
@@ -7,10 +7,10 @@ module RuboCop
#
# @example
# # bad
- # root to: redirect('/-/instance/statistics/conversational_development_index')
+ # root to: redirect('/-/instance/statistics/dev_ops_score')
#
# # good
- # root to: redirect('-/instance/statistics/conversational_development_index')
+ # root to: redirect('-/instance/statistics/dev_ops_score')
#
class AvoidRouteRedirectLeadingSlash < RuboCop::Cop::Cop
diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb
index c69ce10f1c5..7aaa9299362 100644
--- a/rubocop/cop/graphql/authorize_types.rb
+++ b/rubocop/cop/graphql/authorize_types.rb
@@ -34,7 +34,10 @@ module RuboCop
end
def whitelisted?(class_node)
- return false unless class_node&.const_name
+ class_const = class_node&.const_name
+
+ return false unless class_const
+ return true if class_const.end_with?('Enum')
WHITELISTED_TYPES.any? { |whitelisted| class_node.const_name.include?(whitelisted) }
end
diff --git a/rubocop/cop/ignored_columns.rb b/rubocop/cop/ignored_columns.rb
new file mode 100644
index 00000000000..14bcfa04ae1
--- /dev/null
+++ b/rubocop/cop/ignored_columns.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ # Cop that blacklists the usage of Group.public_or_visible_to_user
+ class IgnoredColumns < RuboCop::Cop::Cop
+ MSG = 'Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.'
+
+ def_node_matcher :ignored_columns?, <<~PATTERN
+ (send (self) :ignored_columns)
+ PATTERN
+
+ def on_send(node)
+ return unless ignored_columns?(node)
+
+ add_offense(node, location: :expression)
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/migration/add_column.rb b/rubocop/cop/migration/add_column.rb
index 2530d6477e8..a25bd843559 100644
--- a/rubocop/cop/migration/add_column.rb
+++ b/rubocop/cop/migration/add_column.rb
@@ -8,7 +8,10 @@ module RuboCop
class AddColumn < RuboCop::Cop::Cop
include MigrationHelpers
- WHITELISTED_TABLES = [:application_settings].freeze
+ WHITELISTED_TABLES = %i[
+ application_settings
+ plan_limits
+ ].freeze
MSG = '`add_column` with a default value requires downtime, ' \
'use `add_column_with_default` instead'.freeze
diff --git a/rubocop/cop/put_group_routes_under_scope.rb b/rubocop/cop/put_group_routes_under_scope.rb
new file mode 100644
index 00000000000..bcdde01fdb5
--- /dev/null
+++ b/rubocop/cop/put_group_routes_under_scope.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ # Checks for a group routes outside '/-/' scope.
+ # For more information see: https://gitlab.com/gitlab-org/gitlab/issues/29572
+ class PutGroupRoutesUnderScope < RuboCop::Cop::Cop
+ MSG = 'Put new group routes under /-/ scope'
+
+ def_node_matcher :dash_scope?, <<~PATTERN
+ (:send nil? :scope (hash <(pair (sym :path)(str "groups/*group_id/-")) ...>))
+ PATTERN
+
+ def on_send(node)
+ return unless in_group_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_group_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?('group.rb')
+ end
+
+ def resource?(node)
+ node.method_name == :resource ||
+ node.method_name == :resources
+ end
+ end
+ end
+end
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..1465c73d570 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -14,6 +14,8 @@ 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/put_group_routes_under_scope'
require_relative 'cop/migration/add_column'
require_relative 'cop/migration/add_concurrent_foreign_key'
require_relative 'cop/migration/add_concurrent_index'
@@ -53,3 +55,4 @@ require_relative 'cop/group_public_or_visible_to_user'
require_relative 'cop/inject_enterprise_edition_module'
require_relative 'cop/graphql/authorize_types'
require_relative 'cop/graphql/descriptions'
+require_relative 'cop/ignored_columns'