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>2021-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /rubocop/cop
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'rubocop/cop')
-rw-r--r--rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb2
-rw-r--r--rubocop/cop/gitlab/finder_with_find_by.rb2
-rw-r--r--rubocop/cop/gitlab/httparty.rb4
-rw-r--r--rubocop/cop/gitlab/json.rb4
-rw-r--r--rubocop/cop/gitlab/keys-first-and-values-first.rb2
-rw-r--r--rubocop/cop/gitlab/module_with_instance_variables.rb4
-rw-r--r--rubocop/cop/gitlab/namespaced_class.rb39
-rw-r--r--rubocop/cop/gitlab/predicate_memoization.rb6
-rw-r--r--rubocop/cop/migration/add_concurrent_foreign_key.rb2
-rw-r--r--rubocop/cop/migration/add_concurrent_index.rb2
-rw-r--r--rubocop/cop/migration/add_index.rb2
-rw-r--r--rubocop/cop/migration/add_limit_to_text_columns.rb31
-rw-r--r--rubocop/cop/migration/add_timestamps.rb2
-rw-r--r--rubocop/cop/migration/datetime.rb2
-rw-r--r--rubocop/cop/migration/hash_index.rb2
-rw-r--r--rubocop/cop/migration/remove_column.rb2
-rw-r--r--rubocop/cop/migration/remove_concurrent_index.rb2
-rw-r--r--rubocop/cop/migration/remove_index.rb2
-rw-r--r--rubocop/cop/migration/safer_boolean_column.rb2
-rw-r--r--rubocop/cop/migration/timestamps.rb2
-rw-r--r--rubocop/cop/migration/update_column_in_batches.rb2
-rw-r--r--rubocop/cop/project_path_helper.rb2
-rw-r--r--rubocop/cop/rspec/factories_in_migration_specs.rb2
23 files changed, 106 insertions, 16 deletions
diff --git a/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb b/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
index eba38c1630f..e1c6a984e75 100644
--- a/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
+++ b/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
# Cop that blacklists keyword arguments usage in Sidekiq workers
diff --git a/rubocop/cop/gitlab/finder_with_find_by.rb b/rubocop/cop/gitlab/finder_with_find_by.rb
index 764a5073143..8fa9fe4a2f9 100644
--- a/rubocop/cop/gitlab/finder_with_find_by.rb
+++ b/rubocop/cop/gitlab/finder_with_find_by.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
module Gitlab
diff --git a/rubocop/cop/gitlab/httparty.rb b/rubocop/cop/gitlab/httparty.rb
index 8acebff624d..20f0c381e11 100644
--- a/rubocop/cop/gitlab/httparty.rb
+++ b/rubocop/cop/gitlab/httparty.rb
@@ -4,13 +4,13 @@ module RuboCop
module Cop
module Gitlab
class HTTParty < RuboCop::Cop::Cop
- MSG_SEND = <<~EOL.freeze
+ MSG_SEND = <<~EOL
Avoid calling `HTTParty` directly. Instead, use the Gitlab::HTTP
wrapper. To allow request to localhost or the private network set
the option :allow_local_requests in the request call.
EOL
- MSG_INCLUDE = <<~EOL.freeze
+ MSG_INCLUDE = <<~EOL
Avoid including `HTTParty` directly. Instead, use the Gitlab::HTTP
wrapper. To allow request to localhost or the private network set
the option :allow_local_requests in the request call.
diff --git a/rubocop/cop/gitlab/json.rb b/rubocop/cop/gitlab/json.rb
index 8c9027223aa..7cc719aca09 100644
--- a/rubocop/cop/gitlab/json.rb
+++ b/rubocop/cop/gitlab/json.rb
@@ -4,7 +4,7 @@ module RuboCop
module Cop
module Gitlab
class Json < RuboCop::Cop::Cop
- MSG_SEND = <<~EOL.freeze
+ MSG = <<~EOL
Avoid calling `JSON` directly. Instead, use the `Gitlab::Json`
wrapper. This allows us to alter the JSON parser being used.
EOL
@@ -14,7 +14,7 @@ module RuboCop
PATTERN
def on_send(node)
- add_offense(node, location: :expression, message: MSG_SEND) if json_node?(node)
+ add_offense(node) if json_node?(node)
end
def autocorrect(node)
diff --git a/rubocop/cop/gitlab/keys-first-and-values-first.rb b/rubocop/cop/gitlab/keys-first-and-values-first.rb
index 544f9800304..e9bf266cdd7 100644
--- a/rubocop/cop/gitlab/keys-first-and-values-first.rb
+++ b/rubocop/cop/gitlab/keys-first-and-values-first.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
module Gitlab
diff --git a/rubocop/cop/gitlab/module_with_instance_variables.rb b/rubocop/cop/gitlab/module_with_instance_variables.rb
index dd8bd2dfdf0..40cdc0d3a57 100644
--- a/rubocop/cop/gitlab/module_with_instance_variables.rb
+++ b/rubocop/cop/gitlab/module_with_instance_variables.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
module Gitlab
class ModuleWithInstanceVariables < RuboCop::Cop::Cop
- MSG = <<~EOL.freeze
+ MSG = <<~EOL
Do not use instance variables in a module. Please read this
for the rationale behind it:
diff --git a/rubocop/cop/gitlab/namespaced_class.rb b/rubocop/cop/gitlab/namespaced_class.rb
new file mode 100644
index 00000000000..1f1fd280922
--- /dev/null
+++ b/rubocop/cop/gitlab/namespaced_class.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Gitlab
+ # Cop that enforces use of namespaced classes in order to better identify
+ # high level domains within the codebase.
+
+ # @example
+ # # bad
+ # class MyClass
+ # end
+ #
+ # # good
+ # module MyDomain
+ # class MyClass
+ # end
+ # end
+
+ class NamespacedClass < RuboCop::Cop::Cop
+ MSG = 'Classes must be declared inside a module indicating a product domain namespace. For more info: https://gitlab.com/gitlab-org/gitlab/-/issues/212156'
+
+ def_node_matcher :compact_namespaced_class?, <<~PATTERN
+ (class (const (const ...) ...) ...)
+ PATTERN
+
+ def on_module(node)
+ @namespaced = true
+ end
+
+ def on_class(node)
+ return if @namespaced
+
+ add_offense(node) unless compact_namespaced_class?(node)
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/gitlab/predicate_memoization.rb b/rubocop/cop/gitlab/predicate_memoization.rb
index 3c25d61d087..4c851f90238 100644
--- a/rubocop/cop/gitlab/predicate_memoization.rb
+++ b/rubocop/cop/gitlab/predicate_memoization.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
module Gitlab
class PredicateMemoization < RuboCop::Cop::Cop
- MSG = <<~EOL.freeze
+ MSG = <<~EOL
Avoid using `@value ||= query` inside predicate methods in order to
properly memoize `false` or `nil` values.
https://docs.gitlab.com/ee/development/utilities.html#strongmemoize
@@ -12,7 +14,7 @@ module RuboCop
return unless predicate_method?(node)
select_offenses(node).each do |offense|
- add_offense(offense, location: :expression)
+ add_offense(offense)
end
end
diff --git a/rubocop/cop/migration/add_concurrent_foreign_key.rb b/rubocop/cop/migration/add_concurrent_foreign_key.rb
index 31cf426b2d4..957bd30af63 100644
--- a/rubocop/cop/migration/add_concurrent_foreign_key.rb
+++ b/rubocop/cop/migration/add_concurrent_foreign_key.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/add_concurrent_index.rb b/rubocop/cop/migration/add_concurrent_index.rb
index a2e4ac72565..510f98ce373 100644
--- a/rubocop/cop/migration/add_concurrent_index.rb
+++ b/rubocop/cop/migration/add_concurrent_index.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/add_index.rb b/rubocop/cop/migration/add_index.rb
index 4aea3c0cce3..7415880e554 100644
--- a/rubocop/cop/migration/add_index.rb
+++ b/rubocop/cop/migration/add_index.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/add_limit_to_text_columns.rb b/rubocop/cop/migration/add_limit_to_text_columns.rb
index b2e37ad5137..126e4e21f22 100644
--- a/rubocop/cop/migration/add_limit_to_text_columns.rb
+++ b/rubocop/cop/migration/add_limit_to_text_columns.rb
@@ -20,6 +20,10 @@ module RuboCop
(def :down ...)
PATTERN
+ def_node_matcher :set_text_limit?, <<~PATTERN
+ (send _ :text_limit ...)
+ PATTERN
+
def_node_matcher :add_text_limit?, <<~PATTERN
(send _ :add_text_limit ...)
PATTERN
@@ -111,20 +115,31 @@ module RuboCop
limit_found = false
node.each_descendant(:send) do |send_node|
- next unless add_text_limit?(send_node)
-
- limit_table = send_node.children[2].value
- limit_attribute = send_node.children[3].value
-
- if limit_table == table_name && limit_attribute == attribute_name
- limit_found = true
- break
+ if set_text_limit?(send_node)
+ limit_found = matching_set_text_limit?(send_node, attribute_name)
+ elsif add_text_limit?(send_node)
+ limit_found = matching_add_text_limit?(send_node, table_name, attribute_name)
end
+
+ break if limit_found
end
!limit_found
end
+ def matching_set_text_limit?(send_node, attribute_name)
+ limit_attribute = send_node.children[2].value
+
+ limit_attribute == attribute_name
+ end
+
+ def matching_add_text_limit?(send_node, table_name, attribute_name)
+ limit_table = send_node.children[2].value
+ limit_attribute = send_node.children[3].value
+
+ limit_table == table_name && limit_attribute == attribute_name
+ end
+
def encrypted_attribute_name?(attribute_name)
attribute_name.to_s.start_with?('encrypted_')
end
diff --git a/rubocop/cop/migration/add_timestamps.rb b/rubocop/cop/migration/add_timestamps.rb
index ba32d6a9960..d16e8b1f45b 100644
--- a/rubocop/cop/migration/add_timestamps.rb
+++ b/rubocop/cop/migration/add_timestamps.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/datetime.rb b/rubocop/cop/migration/datetime.rb
index 5a6cdc74ca4..51e0c3e5a22 100644
--- a/rubocop/cop/migration/datetime.rb
+++ b/rubocop/cop/migration/datetime.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/hash_index.rb b/rubocop/cop/migration/hash_index.rb
index 3206b73bd3d..dba202ef0e3 100644
--- a/rubocop/cop/migration/hash_index.rb
+++ b/rubocop/cop/migration/hash_index.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'set'
require_relative '../../migration_helpers'
diff --git a/rubocop/cop/migration/remove_column.rb b/rubocop/cop/migration/remove_column.rb
index fffb4ab7fab..f63df71467c 100644
--- a/rubocop/cop/migration/remove_column.rb
+++ b/rubocop/cop/migration/remove_column.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/remove_concurrent_index.rb b/rubocop/cop/migration/remove_concurrent_index.rb
index 2328740cf36..8c2c6fb157e 100644
--- a/rubocop/cop/migration/remove_concurrent_index.rb
+++ b/rubocop/cop/migration/remove_concurrent_index.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/remove_index.rb b/rubocop/cop/migration/remove_index.rb
index 4df3b1ba756..15c2f37b4b0 100644
--- a/rubocop/cop/migration/remove_index.rb
+++ b/rubocop/cop/migration/remove_index.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/safer_boolean_column.rb b/rubocop/cop/migration/safer_boolean_column.rb
index 22d5d37a83d..06bb24707bd 100644
--- a/rubocop/cop/migration/safer_boolean_column.rb
+++ b/rubocop/cop/migration/safer_boolean_column.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/timestamps.rb b/rubocop/cop/migration/timestamps.rb
index 6cf5648b996..5584d49ee8c 100644
--- a/rubocop/cop/migration/timestamps.rb
+++ b/rubocop/cop/migration/timestamps.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/migration/update_column_in_batches.rb b/rubocop/cop/migration/update_column_in_batches.rb
index b1c43393f6a..d23e0d28380 100644
--- a/rubocop/cop/migration/update_column_in_batches.rb
+++ b/rubocop/cop/migration/update_column_in_batches.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative '../../migration_helpers'
module RuboCop
diff --git a/rubocop/cop/project_path_helper.rb b/rubocop/cop/project_path_helper.rb
index f3810622eb1..bc2454e5b1f 100644
--- a/rubocop/cop/project_path_helper.rb
+++ b/rubocop/cop/project_path_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop
class ProjectPathHelper < RuboCop::Cop::Cop
diff --git a/rubocop/cop/rspec/factories_in_migration_specs.rb b/rubocop/cop/rspec/factories_in_migration_specs.rb
index 65c7638a0f4..732e0d92bbd 100644
--- a/rubocop/cop/rspec/factories_in_migration_specs.rb
+++ b/rubocop/cop/rspec/factories_in_migration_specs.rb
@@ -15,7 +15,7 @@ module RuboCop
# let(:user) { users.create!(name: 'User 1', username: 'user1') }
class FactoriesInMigrationSpecs < RuboCop::Cop::Cop
MESSAGE = "Don't use FactoryBot.%s in migration specs, use `table` instead.".freeze
- FORBIDDEN_METHODS = %i[build build_list create create_list].freeze
+ FORBIDDEN_METHODS = %i[build build_list create create_list attributes_for].freeze
def_node_search :forbidden_factory_usage?, <<~PATTERN
(send {(const nil? :FactoryBot) nil?} {#{FORBIDDEN_METHODS.map(&:inspect).join(' ')}} ...)