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>2020-09-19 04:45:44 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-19 04:45:44 +0300
commit85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch)
tree9160f299afd8c80c038f08e1545be119f5e3f1e1 /rubocop/cop/static_translation_definition.rb
parent15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff)
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'rubocop/cop/static_translation_definition.rb')
-rw-r--r--rubocop/cop/static_translation_definition.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/rubocop/cop/static_translation_definition.rb b/rubocop/cop/static_translation_definition.rb
index 736d8767342..55956d9665b 100644
--- a/rubocop/cop/static_translation_definition.rb
+++ b/rubocop/cop/static_translation_definition.rb
@@ -21,6 +21,8 @@ module RuboCop
method_name = node.children[1]
return unless TRANSLATION_METHODS.include?(method_name)
+ translation_memoized = false
+
node.each_ancestor do |ancestor|
receiver, _ = *ancestor
break if lambda_node?(receiver) # translations defined in lambda nodes should be allowed
@@ -30,6 +32,14 @@ module RuboCop
break
end
+
+ translation_memoized = true if memoization?(ancestor)
+
+ if translation_memoized && class_method_definition?(ancestor)
+ add_offense(node, location: :expression)
+
+ break
+ end
end
end
@@ -38,6 +48,14 @@ module RuboCop
def constant_assignment?(node)
node.type == :casgn
end
+
+ def memoization?(node)
+ node.type == :or_asgn
+ end
+
+ def class_method_definition?(node)
+ node.type == :defs
+ end
end
end
end