Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Style/SoleNestedConditional cop #10068

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

archanaserver
Copy link
Contributor

Reviewed and optimized nested conditionals flagged by the Style/SoloNestedConditional cop.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing tests appear to be related to your changes. Additionally, after applying these changes, there is a need to fix the indentations.

@@ -13,9 +13,9 @@ def resource_scope(options = {})
protected

def clear_session_locale_on_update
if params[:user] && editing_self?
if params[:user] && editing_self? && params[:user][:locale].try(:empty?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if params[:user] && editing_self? && params[:user][:locale].try(:empty?)
user_params = params[:user]
if user_params && editing_self? && user_params[:locale].blank?

@@ -619,11 +619,9 @@ def create_interfaces(vm, attrs, cluster_id)
raise Foreman::Exception.new("Interface network or vnic profile are missing.") if (interface[:network].nil? && interface[:vnic_profile].nil?)
interface[:network] = get_ovirt_id(cluster_networks, 'network', interface[:network]) if interface[:network].present?
interface[:vnic_profile] = get_ovirt_id(profiles, 'vnic profile', interface[:vnic_profile]) if interface[:vnic_profile].present?
if (interface[:network].present? && interface[:vnic_profile].present?)
unless (profiles.select { |profile| profile.network.id == interface[:network] }).present?
if (interface[:network].present? && interface[:vnic_profile].present?) && !(profiles.select { |profile| profile.network.id == interface[:network] }).present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (interface[:network].present? && interface[:vnic_profile].present?) && !(profiles.select { |profile| profile.network.id == interface[:network] }).present?
if interface[:network].present? && interface[:vnic_profile].present? && profiles.none? { |profile| profile.network.id == interface[:network] }

@@ -9,12 +9,10 @@ class << base
module ClassMethods
# ensures that the correct STI object is created when :type is passed.
def new(attributes = nil, &block)
if attributes.is_a?(Hash) && (type = attributes.with_indifferent_access.delete(:type)) && !type.empty?
if (klass = type.constantize) != self
if attributes.is_a?(Hash) && (type = attributes.with_indifferent_access.delete(:type)) && !type.empty? && ((klass = type.constantize) != self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if attributes.is_a?(Hash) && (type = attributes.with_indifferent_access.delete(:type)) && !type.empty? && ((klass = type.constantize) != self)
if attributes.is_a?(Hash) && (type = attributes.with_indifferent_access.delete(:type)).present? && (klass = type.constantize) != self

unless q.nil?
if processed > 0
# rubocop:enable Rails/FindEach
if !q.nil? && (processed > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !q.nil? && (processed > 0)
if q && processed.positive?

Comment on lines +26 to 28
if @condition.present? && !@condition.call
return
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if @condition.present? && !@condition.call
return
end
return if @condition.present? && !@condition.call

Comment on lines +50 to 52
if notification_already_exists?(item) && !@force_repost
next
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if notification_already_exists?(item) && !@force_repost
next
end
next if notification_already_exists?(item) && !@force_repost

Comment on lines +77 to 79
if legacy_dhcp_api? && (other.attrs[:hostname].present? && attrs[:hostname].present?)
to_compare << :hostname
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if legacy_dhcp_api? && (other.attrs[:hostname].present? && attrs[:hostname].present?)
to_compare << :hostname
end
to_compare << :hostname if legacy_dhcp_api? && other.attrs[:hostname].present? && attrs[:hostname].present?

@archanaserver archanaserver mentioned this pull request Mar 6, 2024
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
2 participants