diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-11 09:08:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-11 09:08:44 +0000 |
commit | 6b5f961bef87c70effe57b14d41f9ed882b5d296 (patch) | |
tree | cbdcfbcd679f4560916bdd9a3d9bb5686668d45e /rubocop | |
parent | 79b32f05d4c0e6cedcf14d48bef24fd68e33a7f6 (diff) | |
download | gitlab-ce-6b5f961bef87c70effe57b14d41f9ed882b5d296.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/static_translation_definition.rb | 18 |
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 |