Add an apply Rails/CompactBlank rubocop rule

In rubocop-rails 2.26.0, the Rails/CompactBlank rule was modified to handle
cases where select(&:present?) is used. After identifying three occurrences
in our code, we've decided to apply this rule as it encourages the use of the
more efficient and clearer method, compact_blank.

By using compact_blank, we improve code clarity and performance, as this method performs the same operation but in a more optimized way.
This commit is contained in:
taitus
2024-10-08 17:12:19 +02:00
parent c50452aec6
commit 29df39b2fa
5 changed files with 7 additions and 4 deletions

View File

@@ -367,6 +367,9 @@ Rails/ActiveRecordCallbacksOrder:
Rails/AddColumnIndex: Rails/AddColumnIndex:
Enabled: true Enabled: true
Rails/CompactBlank:
Enabled: true
Rails/CreateTableWithTimestamps: Rails/CreateTableWithTimestamps:
Enabled: true Enabled: true
Exclude: Exclude:

View File

@@ -7,7 +7,7 @@ module Header
(t("#{namespace}.header.title", default: "") unless skip_section_title), (t("#{namespace}.header.title", default: "") unless skip_section_title),
strip_tags(title), strip_tags(title),
setting["org_name"] setting["org_name"]
].reject(&:blank?).join(" - ") ].compact_blank.join(" - ")
end end
heading_tag = if %w[admin management moderation sdg_management valuation].include?(namespace) heading_tag = if %w[admin management moderation sdg_management valuation].include?(namespace)

View File

@@ -4,7 +4,7 @@ class SDG::Goals::PlainTagListComponent < ApplicationComponent
private private
def tags def tags
[*goal_tags, see_more_link].select(&:present?) [*goal_tags, see_more_link].compact_blank
end end
def goal_tags def goal_tags

View File

@@ -4,7 +4,7 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent
private private
def tags def tags
[*target_tags, see_more_link].select(&:present?) [*target_tags, see_more_link].compact_blank
end end
def target_tags def target_tags

View File

@@ -13,7 +13,7 @@ class Shared::LinkListComponent < ApplicationComponent
private private
def present_links def present_links
links.select(&:present?) links.compact_blank
end end
def list_items def list_items