From b14174961b3a841a3f9484896e25be60b9fa27b7 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 19 Apr 2023 17:41:36 +0100 Subject: [PATCH] (CONT-792) - Correct Style/IfUnlessModifier --- .rubocop_todo.yml | 13 ------------- .../postgresql/postgresql_acls_to_resources_hash.rb | 4 +--- .../functions/postgresql/postgresql_password.rb | 4 +--- lib/puppet/provider/postgresql_psql/ruby.rb | 4 +--- .../provider/postgresql_replication_slot/ruby.rb | 4 +--- lib/puppet/type/postgresql_psql.rb | 4 +--- spec/acceptance/server/grant_role_spec.rb | 4 +--- spec/acceptance/server/grant_spec.rb | 4 +--- spec/acceptance/server/schema_spec.rb | 4 +--- spec/acceptance/z_alternative_pgdata_spec.rb | 4 +--- 10 files changed, 9 insertions(+), 40 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8dad7a1794..5e525a0d40 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -160,19 +160,6 @@ Style/ClassAndModuleChildren: Exclude: - 'lib/puppet/util/postgresql_validator.rb' -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb' - - 'lib/puppet/functions/postgresql/postgresql_password.rb' - - 'lib/puppet/provider/postgresql_psql/ruby.rb' - - 'lib/puppet/provider/postgresql_replication_slot/ruby.rb' - - 'lib/puppet/type/postgresql_psql.rb' - - 'spec/acceptance/server/grant_role_spec.rb' - - 'spec/acceptance/server/grant_spec.rb' - - 'spec/acceptance/server/schema_spec.rb' - - 'spec/acceptance/z_alternative_pgdata_spec.rb' # Offense count: 2 Style/MixinUsage: diff --git a/lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb b/lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb index f49c40c4e8..49dd4ccf65 100644 --- a/lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb +++ b/lib/puppet/functions/postgresql/postgresql_acls_to_resources_hash.rb @@ -38,9 +38,7 @@ def default_impl(acls, id, offset) } if parts[0] == 'local' resource['auth_method'] = parts[3] - if parts.length > 4 - resource['auth_option'] = parts.last(parts.length - 4).join(' ') - end + resource['auth_option'] = parts.last(parts.length - 4).join(' ') if parts.length > 4 elsif %r{^\d}.match?(parts[4]) resource['address'] = parts[3] + ' ' + parts[4] resource['auth_method'] = parts[5] diff --git a/lib/puppet/functions/postgresql/postgresql_password.rb b/lib/puppet/functions/postgresql/postgresql_password.rb index 1f27fb5bba..350ae2f86d 100644 --- a/lib/puppet/functions/postgresql/postgresql_password.rb +++ b/lib/puppet/functions/postgresql/postgresql_password.rb @@ -28,9 +28,7 @@ end def default_impl(username, password, sensitive = false, hash = 'md5', salt = nil) - if password.is_a?(String) && password.match?(%r{^(md5|SCRAM-SHA-256).+}) - return password - end + return password if password.is_a?(String) && password.match?(%r{^(md5|SCRAM-SHA-256).+}) password = password.unwrap if password.respond_to?(:unwrap) pass = if hash == 'md5' diff --git a/lib/puppet/provider/postgresql_psql/ruby.rb b/lib/puppet/provider/postgresql_psql/ruby.rb index 1cfbbca094..eeba6723f7 100644 --- a/lib/puppet/provider/postgresql_psql/ruby.rb +++ b/lib/puppet/provider/postgresql_psql/ruby.rb @@ -9,9 +9,7 @@ def run_unless_sql_command(sql) end def run_sql_command(sql) - if resource[:search_path] - sql = "set search_path to #{Array(resource[:search_path]).join(',')}; #{sql}" - end + sql = "set search_path to #{Array(resource[:search_path]).join(',')}; #{sql}" if resource[:search_path] command = [resource[:psql_path]] command.push('-d', resource[:db]) if resource[:db] diff --git a/lib/puppet/provider/postgresql_replication_slot/ruby.rb b/lib/puppet/provider/postgresql_replication_slot/ruby.rb index 3a711308e4..31271cc51b 100644 --- a/lib/puppet/provider/postgresql_replication_slot/ruby.rb +++ b/lib/puppet/provider/postgresql_replication_slot/ruby.rb @@ -15,9 +15,7 @@ def self.instances def self.prefetch(resources) instances.each do |i| slot = resources[i.name] - if slot - slot.provider = i - end + slot.provider = i if slot end end diff --git a/lib/puppet/type/postgresql_psql.rb b/lib/puppet/type/postgresql_psql.rb index 88039d4380..2db3cd34b4 100644 --- a/lib/puppet/type/postgresql_psql.rb +++ b/lib/puppet/type/postgresql_psql.rb @@ -110,9 +110,7 @@ def matches(value) validate do |values| Array(values).each do |value| - unless %r{\w+=}.match?(value) - raise ArgumentError, "Invalid environment setting '#{value}'" - end + raise ArgumentError, "Invalid environment setting '#{value}'" unless %r{\w+=}.match?(value) end end end diff --git a/spec/acceptance/server/grant_role_spec.rb b/spec/acceptance/server/grant_role_spec.rb index c9935f0c16..6a32dc03e8 100644 --- a/spec/acceptance/server/grant_role_spec.rb +++ b/spec/acceptance/server/grant_role_spec.rb @@ -8,9 +8,7 @@ let(:group) { 'test_group' } let(:password) { 'psql_grant_role_pw' } let(:version) do - if os[:family] == 'redhat' && os[:release].start_with?('5') - '8.1' - end + '8.1' if os[:family] == 'redhat' && os[:release].start_with?('5') end let(:pp_one) do <<-MANIFEST.unindent diff --git a/spec/acceptance/server/grant_spec.rb b/spec/acceptance/server/grant_spec.rb index 98d50a9e2a..41b977eb96 100644 --- a/spec/acceptance/server/grant_spec.rb +++ b/spec/acceptance/server/grant_spec.rb @@ -79,9 +79,7 @@ class { 'postgresql::server': } end it 'is expected to run idempotently' do - if Gem::Version.new(postgresql_version) >= Gem::Version.new('8.4.0') - idempotent_apply(pp) - end + idempotent_apply(pp) if Gem::Version.new(postgresql_version) >= Gem::Version.new('8.4.0') end it 'is expected to GRANT USAGE ON LANGUAGE plpgsql to ROLE' do diff --git a/spec/acceptance/server/schema_spec.rb b/spec/acceptance/server/schema_spec.rb index 61a3f720bd..dc2bc5d6c3 100644 --- a/spec/acceptance/server/schema_spec.rb +++ b/spec/acceptance/server/schema_spec.rb @@ -4,9 +4,7 @@ describe 'postgresql::server::schema:' do let(:version) do - if os[:family] == 'redhat' && os[:release].start_with?('5') - '8.1' - end + '8.1' if os[:family] == 'redhat' && os[:release].start_with?('5') end let(:pp) do <<-MANIFEST.unindent diff --git a/spec/acceptance/z_alternative_pgdata_spec.rb b/spec/acceptance/z_alternative_pgdata_spec.rb index c3b581f02f..7c717c4344 100644 --- a/spec/acceptance/z_alternative_pgdata_spec.rb +++ b/spec/acceptance/z_alternative_pgdata_spec.rb @@ -7,9 +7,7 @@ describe 'postgresql::server', skip: 'IAC-1286' do before(:each) do - if os[:family] == 'sles' - skip "These test's currently do not work on SLES/Suse modules" - end + skip "These test's currently do not work on SLES/Suse modules" if os[:family] == 'sles' end it 'on an alternative pgdata location' do