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:
Diffstat (limited to 'rubocop/cop/gitlab')
-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
7 files changed, 54 insertions, 7 deletions
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