Add and apply Naming/PredicateMethod RuboCop 1.76 rule

This rule was introduced in RuboCop 1.76.0 to ensure methods ending
in '?' return boolean.

This commit applies suggested renames and code cleanup:
- Renames 'is_active?' to 'active_class' since it returns a string
- Renames 'parsed_value' to 'in_favor?' and 'is_request_active' to end with '?'
  for boolean semantics
- Skips false positives like 'save', 'auto_labels' or 'save_requiring_finish_signup',
  which are not predicate methods.
This commit is contained in:
taitus
2025-06-16 11:40:55 +02:00
parent d123297ba6
commit b9bffeb321
6 changed files with 15 additions and 7 deletions

View File

@@ -354,6 +354,14 @@ Naming/BlockForwarding:
- "app/controllers/management/base_controller.rb"
- "app/controllers/subscriptions_controller.rb"
Naming/PredicateMethod:
Enabled: true
Exclude:
- "app/models/local_census_records/import.rb"
- "app/models/user.rb"
- "app/models/verification/management/email.rb"
- "config/initializers/foundation_form_builder.rb"
Naming/RescuedExceptionsVariableName:
Enabled: true

View File

@@ -9,7 +9,7 @@
<p><%= t("sdg.goals.help.description") %></p>
<ul class="tabs" id="help_tabs" data-deep-link="true" data-tabs>
<% goals.each do |goal| %>
<li class="tabs-title <%= is_active?(goal) %>">
<li class="tabs-title <%= active_class(goal) %>">
<%= link_to "#goal_#{goal.code}_tab" do %>
<% render SDG::Goals::IconComponent.new(goal) %>
<% end %>
@@ -19,7 +19,7 @@
<div class="tabs-content" data-tabs-content="help_tabs">
<% goals.each do |goal| %>
<div id="goal_<%= goal.code %>_tab" class="tabs-panel <%= is_active?(goal) %>">
<div id="goal_<%= goal.code %>_tab" class="tabs-panel <%= active_class(goal) %>">
<h2><%= goal.code_and_title %></h2>
<p><%= sanitize t("sdg.goals.goal_#{goal.code}.description") %></p>
<%= render SDG::Goals::TargetsComponent.new(goal) %>

View File

@@ -11,7 +11,7 @@ class SDG::Goals::HelpPageComponent < ApplicationComponent
private
def is_active?(goal)
def active_class(goal)
"is-active" if goal.code == 1
end
end

View File

@@ -35,14 +35,14 @@ class Shared::VoteButtonComponent < ApplicationComponent
end
def vote
@vote ||= Vote.find_or_initialize_by(votable: votable, voter: current_user, vote_flag: parsed_value)
@vote ||= Vote.find_or_initialize_by(votable: votable, voter: current_user, vote_flag: in_favor?)
end
def already_voted?
vote.persisted?
end
def parsed_value
def in_favor?
value == "yes"
end
end

View File

@@ -52,7 +52,7 @@ module ProposalsDashboardHelper
dashboard_action&.proposed_action?
end
def is_request_active(id)
def request_active?(id)
controller_name == "dashboard" && action_name == "new_request" && dashboard_action&.id == id
end

View File

@@ -72,7 +72,7 @@
<% resources.each do |resource| %>
<li>
<%= link_to new_request_proposal_dashboard_action_path(proposal, resource),
class: ("submenu-active" if is_request_active(resource.id)) do %>
class: ("submenu-active" if request_active?(resource.id)) do %>
<span data-tooltip title="<%= resource.short_description %>">
<%= resource.title %>
</span>