Skip to content

Commit

Permalink
Merge pull request #510 from jstraw/rubocop-fixes-may4th
Browse files Browse the repository at this point in the history
Fix Heredoc rubocop and Disable Style/ClassAndModuleChildren where needed
  • Loading branch information
LukasAud authored May 10, 2023
2 parents 8300062 + f99add9 commit 79e37cf
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 255 deletions.
23 changes: 0 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Max: 20

# Offense count: 114
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'lib/puppet/type/ini_subsetting.rb'
- 'spec/acceptance/ini_setting_spec.rb'
- 'spec/acceptance/ini_subsetting_spec.rb'
- 'spec/unit/puppet/provider/ini_setting/inheritance_spec.rb'
- 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb'
- 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb'
- 'spec/unit/puppet/util/ini_file_spec.rb'

# Offense count: 12
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Expand Down Expand Up @@ -98,13 +85,3 @@ RSpec/NamedSubject:
RSpec/NestedGroups:
Max: 6

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/puppet/util/external_iterator.rb'
- 'lib/puppet/util/ini_file.rb'
- 'lib/puppet/util/ini_file/section.rb'
- 'lib/puppet/util/setting_value.rb'
4 changes: 2 additions & 2 deletions lib/puppet/type/ini_subsetting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def is_to_s(value) # rubocop:disable Naming/PredicateName : Changing breaks the
end

newparam(:insert_type) do
desc <<-EOF
desc <<-DOCUMENTATION
Where the new subsetting item should be inserted
* :start - insert at the beginning of the line.
* :end - insert at the end of the line (default).
* :before - insert before the specified element if possible.
* :after - insert after the specified element if possible.
* :index - insert at the specified index number.
EOF
DOCUMENTATION

newvalues(:start, :end, :before, :after, :index)
defaultto(:end)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/external_iterator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Puppet::Util
module Puppet::Util # rubocop:disable Style/ClassAndModuleChildren
#
# external_iterator.rb
#
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require File.expand_path('external_iterator', __dir__)
require File.expand_path('ini_file/section', __dir__)

module Puppet::Util
module Puppet::Util # rubocop:disable Style/ClassAndModuleChildren
#
# ini_file.rb
#
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/ini_file/section.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Puppet::Util::IniFile
class Puppet::Util::IniFile # rubocop:disable Style/ClassAndModuleChildren
#
# section.rb
#
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/setting_value.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Puppet::Util
module Puppet::Util # rubocop:disable Style/ClassAndModuleChildren
# This class can work with a list of subsettings inside
# an ini file setting string to add, remove, extract and set their values.
class SettingValue
Expand Down
44 changes: 22 additions & 22 deletions spec/acceptance/ini_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

context 'when ensure parameter => present for global and section' do
pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'ensure => present for section':
ensure => present,
path => "#{basedir}/ini_setting.ini",
Expand All @@ -59,7 +59,7 @@
setting => 'four',
value => 'five',
}
EOS
MANIFEST

it_behaves_like 'has_content', "#{basedir}/ini_setting.ini", pp, %r{four = five\R\R\[one\]\Rtwo = three}
end
Expand All @@ -76,15 +76,15 @@
apply_manifest(ipp)
end

pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'ensure => absent for key/value':
ensure => absent,
path => "#{basedir}/ini_setting.ini",
section => 'one',
setting => 'two',
value => 'three',
}
EOS
MANIFEST

it 'applies the manifest twice' do
expect { idempotent_apply(pp) }.not_to raise_error
Expand Down Expand Up @@ -119,15 +119,15 @@
run_shell("rm #{basedir}/ini_setting.ini", expect_failures: true)
end

pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'ensure => absent for global':
ensure => absent,
path => "#{basedir}/ini_setting.ini",
section => '',
setting => 'four',
value => 'five',
}
EOS
MANIFEST

it 'applies the manifest twice' do
expect { idempotent_apply(pp) }.not_to raise_error
Expand All @@ -148,28 +148,28 @@

describe 'path parameter' do
context 'when path => foo' do
pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'path => foo':
ensure => present,
section => 'one',
setting => 'two',
value => 'three',
path => 'foo',
}
EOS
MANIFEST

it_behaves_like 'has_error', 'foo', pp, %r{must be fully qualified}
end
end

context 'when ensure parameter => present and only section' do
pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'ensure => present for section':
ensure => present,
path => "#{basedir}/ini_setting.ini",
section => 'one',
}
EOS
MANIFEST

it_behaves_like 'has_content', "#{basedir}/ini_setting.ini", pp, %r{\[one\]}
end
Expand All @@ -181,7 +181,7 @@
{ value: 'public_value', matcher: %r{initial_value.*public_value}, show_diff: true },
{ value: 'secret_value', matcher: %r{redacted sensitive information.*redacted sensitive information}, show_diff: false },
{ value: 'md5_value', matcher: %r{\{md5\}881671aa2bbc680bc530c4353125052b.*\{md5\}ed0903a7fa5de7886ca1a7a9ad06cf51}, show_diff: :md5 }].each do |i|
pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'test_show_diff':
ensure => present,
section => 'test',
Expand All @@ -190,7 +190,7 @@
path => "#{basedir}/test_show_diff.ini",
show_diff => #{i[:show_diff]}
}
EOS
MANIFEST

context "when show_diff => #{i[:show_diff]}" do
res = apply_manifest(pp, expect_changes: true)
Expand All @@ -206,15 +206,15 @@
end

describe 'values with spaces in the value part at the beginning or at the end' do
pp = <<-EOS
pp = <<-MANIFEST
ini_setting { 'path => foo':
ensure => present,
section => 'one',
setting => 'two',
value => ' 123',
path => '#{basedir}/ini_setting.ini',
}
EOS
MANIFEST

it_behaves_like 'has_content', "#{basedir}/ini_setting.ini", pp, %r{\[one\]\Rtwo = 123}
end
Expand All @@ -238,7 +238,7 @@
context 'when event is triggered' do
context 'when update setting value' do
let(:update_value_manifest) do
<<-EOS
<<-MANIFEST
notify { foo:
notify => Ini_Setting['updateSetting'],
}
Expand All @@ -251,7 +251,7 @@
value => "newValue",
refreshonly => true,
}
EOS
MANIFEST
end

before(:each) do
Expand All @@ -271,7 +271,7 @@

context 'when remove setting value' do
let(:remove_setting_manifest) do
<<-EOS
<<-MANIFEST
notify { foo:
notify => Ini_Setting['removeSetting'],
}
Expand All @@ -283,7 +283,7 @@
setting => 'valueinsection1',
refreshonly => true,
}
EOS
MANIFEST
end

before(:each) do
Expand All @@ -305,7 +305,7 @@
context 'when not receiving an event' do
context 'when does not update setting' do
let(:does_not_update_value_manifest) do
<<-EOS
<<-MANIFEST
file { "#{basedir}/ini_setting.ini":
ensure => present,
notify => Ini_Setting['updateSetting'],
Expand All @@ -318,7 +318,7 @@
value => "newValue",
refreshonly => true,
}
EOS
MANIFEST
end

before(:each) do
Expand All @@ -339,7 +339,7 @@

context 'when does not remove setting' do
let(:does_not_remove_setting_manifest) do
<<-EOS
<<-MANIFEST
file { "#{basedir}/ini_setting.ini":
ensure => present,
notify => Ini_Setting['removeSetting'],
Expand All @@ -352,7 +352,7 @@
setting => 'valueinsection1',
refreshonly => true,
}
EOS
MANIFEST
end

before(:each) do
Expand Down
24 changes: 12 additions & 12 deletions spec/acceptance/ini_subsetting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end

describe 'ensure, section, setting, subsetting, & value parameters => present with subsections' do
pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { 'ensure => present for alpha':
ensure => present,
path => "#{basedir}/ini_subsetting.ini",
Expand All @@ -64,23 +64,23 @@
value => 'trons',
require => Ini_subsetting['ensure => present for alpha'],
}
EOS
MANIFEST

describe file("#{basedir}/ini_subsetting.ini") do
it_behaves_like 'has_content', "#{basedir}/ini_subsetting.ini", pp, %r{\[one\]\Rkey = alphabet betatrons}
end
end

describe 'ensure => absent' do
pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { 'ensure => absent for subsetting':
ensure => absent,
path => "#{basedir}/ini_subsetting.ini",
section => 'one',
setting => 'key',
subsetting => 'alpha',
}
EOS
MANIFEST

it 'applies the manifest twice' do
expect { idempotent_apply(pp) }.not_to raise_error
Expand All @@ -100,7 +100,7 @@
end

describe 'delete_if_empty => true' do
pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { 'ensure => absent for alpha':
ensure => absent,
path => "#{basedir}/ini_subsetting.ini",
Expand All @@ -117,7 +117,7 @@
subsetting => 'beta',
delete_if_empty => true,
}
EOS
MANIFEST

it 'applies the manifest twice' do
run_shell("echo -e [one]\\\\nkey = alphabet betatrons > #{basedir}/ini_subsetting.ini", expect_failures: true)
Expand Down Expand Up @@ -163,7 +163,7 @@
run_shell("rm #{path}", expect_failures: true)
end

pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { '#{parameter.first}':
ensure => #{(parameter.length > 1) ? 'present' : 'absent'},
path => '#{path}',
Expand All @@ -173,7 +173,7 @@
subsetting => '#{parameter.first}',
value => '#{(parameter.length > 1) ? parameter[1] : ''}'
}
EOS
MANIFEST

it 'applies the manifest twice' do
expect { idempotent_apply(pp) }.not_to raise_error
Expand All @@ -199,7 +199,7 @@
{ value: 'public_value', matcher: %r{initial_value.*public_value}, show_diff: true },
{ value: 'secret_value', matcher: %r{redacted sensitive information.*redacted sensitive information}, show_diff: false },
{ value: 'md5_value', matcher: %r{\{md5\}881671aa2bbc680bc530c4353125052b.*\{md5\}ed0903a7fa5de7886ca1a7a9ad06cf51}, show_diff: :md5 }].each do |i|
pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { 'test_show_diff':
ensure => present,
section => 'test',
Expand All @@ -209,7 +209,7 @@
path => "#{basedir}/test_show_diff.ini",
show_diff => #{i[:show_diff]}
}
EOS
MANIFEST

context "when show_diff => #{i[:show_diff]}" do
res = apply_manifest(pp, expect_changes: true)
Expand Down Expand Up @@ -251,7 +251,7 @@
},
].each do |params|
context "with '#{params[:insert_type]}' makes '#{params[:content]}'" do
pp = <<-EOS
pp = <<-MANIFEST
ini_subsetting { "a":
ensure => present,
section => 'one',
Expand Down Expand Up @@ -282,7 +282,7 @@
insert_type => '#{params[:insert_type]}',
insert_value => '#{params[:insert_value]}',
}
EOS
MANIFEST

it_behaves_like 'has_content', "#{basedir}/insert_types.ini", pp, params[:content]
end
Expand Down
Loading

0 comments on commit 79e37cf

Please sign in to comment.