From efc46fe6c8ce25f0d2f17053b807b3c321b49d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 26 Aug 2022 23:47:57 +0200 Subject: [PATCH] Add Performance/StringIdentifierArgument rule It was added in rubocop-performance 1.13.0. We were already applying it in most places. We aren't adding it for performance reasons but in order to make the code more consistent. --- .rubocop.yml | 3 +++ app/controllers/concerns/flag_actions.rb | 4 ++-- app/controllers/concerns/polymorphic.rb | 4 ++-- app/models/concerns/skip_validation.rb | 2 +- app/models/direct_upload.rb | 2 +- lib/comment_tree.rb | 2 +- spec/models/related_content_spec.rb | 4 ++-- spec/shared/system/relationable.rb | 4 ++-- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f47dd6fb6..cd70fa112 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -224,6 +224,9 @@ Performance/EndWith: Performance/StartWith: Enabled: true +Performance/StringIdentifierArgument: + Enabled: true + Performance/Sum: Enabled: true diff --git a/app/controllers/concerns/flag_actions.rb b/app/controllers/concerns/flag_actions.rb index acbc96882..7042a04fc 100644 --- a/app/controllers/concerns/flag_actions.rb +++ b/app/controllers/concerns/flag_actions.rb @@ -17,9 +17,9 @@ module FlagActions def flaggable if resource_model.to_s == "Budget::Investment" - instance_variable_get("@investment") + instance_variable_get(:@investment) elsif resource_model.to_s == "Legislation::Proposal" - instance_variable_get("@proposal") + instance_variable_get(:@proposal) else instance_variable_get("@#{resource_model.to_s.downcase}") end diff --git a/app/controllers/concerns/polymorphic.rb b/app/controllers/concerns/polymorphic.rb index 2a5188c26..53d18b21c 100644 --- a/app/controllers/concerns/polymorphic.rb +++ b/app/controllers/concerns/polymorphic.rb @@ -3,9 +3,9 @@ module Polymorphic def resource if resource_model.to_s == "Budget::Investment" - @resource ||= instance_variable_get("@investment") + @resource ||= instance_variable_get(:@investment) elsif resource_model.to_s == "Legislation::Proposal" - @resource ||= instance_variable_get("@proposal") + @resource ||= instance_variable_get(:@proposal) else @resource ||= instance_variable_get("@#{resource_name}") end diff --git a/app/models/concerns/skip_validation.rb b/app/models/concerns/skip_validation.rb index 2a3dbcdc1..7c1a3c549 100644 --- a/app/models/concerns/skip_validation.rb +++ b/app/models/concerns/skip_validation.rb @@ -13,7 +13,7 @@ module SkipValidation _validate_callbacks.each do |callback| if callback.raw_filter.is_a?(validator_class) - callback.raw_filter.instance_variable_set("@attributes", callback.raw_filter.attributes - [field]) + callback.raw_filter.instance_variable_set(:@attributes, callback.raw_filter.attributes - [field]) end end end diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index 6d6eb7470..c5e535906 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -22,7 +22,7 @@ class DirectUpload # Refactor @relation = if @resource.respond_to?(:images) && ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) - @resource.images.send("build", relation_attributtes) + @resource.images.send(:build, relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @resource.send("build_#{resource_relation}", relation_attributtes) else diff --git a/lib/comment_tree.rb b/lib/comment_tree.rb index d5743f311..c43e619c4 100644 --- a/lib/comment_tree.rb +++ b/lib/comment_tree.rb @@ -19,7 +19,7 @@ class CommentTree end def base_comments - if @valuations && commentable.respond_to?("valuations") + if @valuations && commentable.respond_to?(:valuations) commentable.valuations else commentable.comments diff --git a/spec/models/related_content_spec.rb b/spec/models/related_content_spec.rb index 827a50597..a41e5bd64 100644 --- a/spec/models/related_content_spec.rb +++ b/spec/models/related_content_spec.rb @@ -79,11 +79,11 @@ describe RelatedContent do create(:related_content, parent_relationable: parent_relationable, child_relationable: child_relationable, author: build(:user)) 2.times do - related_content.send("score_positive", build(:user)) + related_content.send(:score_positive, build(:user)) end 6.times do - related_content.send("score_negative", build(:user)) + related_content.send(:score_negative, build(:user)) end end diff --git a/spec/shared/system/relationable.rb b/spec/shared/system/relationable.rb index 28612d413..4b744fe35 100644 --- a/spec/shared/system/relationable.rb +++ b/spec/shared/system/relationable.rb @@ -173,11 +173,11 @@ shared_examples "relationable" do |relationable_model_name| related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user)) 2.times do - related_content.send("score_positive", build(:user)) + related_content.send(:score_positive, build(:user)) end 6.times do - related_content.send("score_negative", build(:user)) + related_content.send(:score_negative, build(:user)) end login_as(user)