From 1547e35cd9fa76e94a168a931a8a0f5e7e459dfd Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 4 Apr 2023 15:57:14 +0100 Subject: [PATCH 01/53] (CONT-783) - PDK update --- Gemfile | 46 +++++++++++++++++++++++----------------------- Rakefile | 1 - metadata.json | 4 ++-- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index 1881afe1..8456bee1 100644 --- a/Gemfile +++ b/Gemfile @@ -14,31 +14,31 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "voxpupuli-puppet-lint-plugins", '~> 3.1', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false - gem "puppetlabs_spec_helper", '>= 3.0.0', '< 5.0.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false - gem "dependency_checker", '~> 0.2', require: false - gem "parallel_tests", '~> 3.4', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", '= 1.15.2', require: false + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.6.1', require: false + gem "rubocop-performance", '= 1.9.1', require: false + gem "rubocop-rspec", '= 2.0.1', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", '= 1.15.2', require: false end group :system_tests do - gem "puppet_litmus", '<= 0.34.6', require: false, platforms: [:ruby] - gem "serverspec", '~> 2.41', require: false + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 0f8754eb..53152e21 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,6 @@ require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? diff --git a/metadata.json b/metadata.json index ce0b268e..6d421475 100644 --- a/metadata.json +++ b/metadata.json @@ -105,6 +105,6 @@ } ], "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "heads/main-0-g9375381", - "pdk-version": "2.6.1" + "template-ref": "heads/main-0-g604a3ec", + "pdk-version": "2.7.0" } From bd83b884848e6219ca0fd5c832befa1ab9e66919 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 4 Apr 2023 15:57:39 +0100 Subject: [PATCH 02/53] (CONT-783) - add puppet8/drop puppet6 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 6d421475..aa35a77a 100644 --- a/metadata.json +++ b/metadata.json @@ -101,7 +101,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.0.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", From b0707717d95a366cc255ec0fb097accc3838f637 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 4 Apr 2023 15:58:43 +0100 Subject: [PATCH 03/53] (CONT-783) - update rubocop gems --- Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 8456bee1..7fad5040 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ group :development do gem "pry", '~> 0.10', require: false gem "simplecov-console", '~> 0.5', require: false gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false + gem "rubocop", '~> 1.48.1', require: false + gem "rubocop-performance", '~> 1.16', require: false + gem "rubocop-rspec", '~> 2.19', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", '= 1.15.2', require: false end From fc7fe061f1256c08193154cb446a5d8d4e87cc23 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 4 Apr 2023 16:01:38 +0100 Subject: [PATCH 04/53] (CONT-783) - update .rubocop.yml --- .rubocop.yml | 443 +-------------------------------------------------- 1 file changed, 4 insertions(+), 439 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 31e8248f..c7723f48 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,8 +3,11 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' Include: - "**/*.rb" Exclude: @@ -79,441 +82,3 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false From 01d3e09334cdc2d2b72334e4ad549c44216bb136 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 11:53:58 +0100 Subject: [PATCH 05/53] (CONT-783) - Correct Layout/ClosingHeredocIndentation --- .rubocop.yml | 2 ++ spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c7723f48..83745bcb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ --- +inherit_from: .rubocop_todo.yml + require: - rubocop-performance - rubocop-rspec diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index d1f448eb..e452ed7c 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -951,7 +951,7 @@ def self.file_path -nonstandard- shoes = purple -EOS + EOS end expected_content_one = <<-EOS @@ -1468,7 +1468,7 @@ def self.file_path [section1] # foo=foovalue # bar=bar2 -EOS + EOS end expected_content_one = <<-EOS From 21706297020e005f3aad279d63a06be25898e423 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 11:59:52 +0100 Subject: [PATCH 06/53] (CONT-783) - Correct Layout/EmptyLineAfterGuardClause --- lib/puppet/provider/ini_setting/ruby.rb | 1 + lib/puppet/type/ini_setting.rb | 1 + lib/puppet/util/ini_file.rb | 6 ++++++ lib/puppet/util/setting_value.rb | 2 ++ 4 files changed, 10 insertions(+) diff --git a/lib/puppet/provider/ini_setting/ruby.rb b/lib/puppet/provider/ini_setting/ruby.rb index c182d2b1..5ccb6793 100644 --- a/lib/puppet/provider/ini_setting/ruby.rb +++ b/lib/puppet/provider/ini_setting/ruby.rb @@ -10,6 +10,7 @@ def self.instances self.file_path, and that will provide the value for the path to the ini file.' raise(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded') unless respond_to?(:file_path) + # figure out what to do about the seperator ini_file = Puppet::Util::IniFile.new(file_path, '=') resources = [] diff --git a/lib/puppet/type/ini_setting.rb b/lib/puppet/type/ini_setting.rb index 474c4f4c..16635322 100644 --- a/lib/puppet/type/ini_setting.rb +++ b/lib/puppet/type/ini_setting.rb @@ -148,6 +148,7 @@ def refresh if self[:ensure] == :absent && self[:refreshonly] return provider.destroy end + # update the value in the provider, which will save the value to the ini file provider.value = self[:value] if self[:refreshonly] end diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 2eaf401a..3342745e 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -110,6 +110,7 @@ def set_value(*args) def remove_setting(section_name, setting) section = @sections_hash[section_name] return unless section.existing_setting?(setting) + # If the setting is found, we have some work to do. # First, we remove the line from our array of lines: remove_line(section, setting) @@ -125,6 +126,7 @@ def remove_setting(section_name, setting) decrement_section_line_numbers(section_index + 1) return unless section.empty? + # By convention, it's time to remove this newly emptied out section lines.delete_at(section.start_line) decrement_section_line_numbers(section_index + 1) @@ -247,6 +249,7 @@ def read_section(name, start_line, line_iter) def update_line(section, setting, value) (section.start_line..section.end_line).each do |line_num| next unless (match = @setting_regex.match(lines[line_num])) + if match[2] == setting lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}" end @@ -256,6 +259,7 @@ def update_line(section, setting, value) def remove_line(section, setting) (section.start_line..section.end_line).each do |line_num| next unless (match = @setting_regex.match(lines[line_num])) + if match[2] == setting lines.delete_at(line_num) end @@ -292,6 +296,7 @@ def self.readlines(path) # rubocop:disable Lint/IneffectiveAccessModifier : Atte # be used to mimic the whitespace from the comment line def find_commented_setting(section, setting) return nil if section.new_section? + (section.start_line..section.end_line).each do |line_num| next unless (match = @commented_setting_regex.match(lines[line_num])) if match[3] == setting @@ -332,6 +337,7 @@ def increment_section_line_numbers(section_index) def flush_buffer_to_file(buffer, fh) return if buffer.empty? + buffer.each { |l| fh.puts(l) } buffer.clear end diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index 51e349dd..8e63c17e 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -17,6 +17,7 @@ def initialize(setting_value, subsetting_separator = ' ', default_quote_char = ' @subsetting_items = [] return unless @setting_value + unquoted, quote_char = unquote_setting_value(setting_value) @quote_char = quote_char unless quote_char.empty? # an item can contain escaped separator @@ -66,6 +67,7 @@ def get_subsetting_value(subsetting, use_exact_match = :false) return nil unless index # the exact match is set and the item is found, the value should be true return true if use_exact_match == :true + item = @subsetting_items[index] item[(subsetting.length + @key_val_separator.length)..-1] end From 88dbe3a91df9c7722f2d768f1033b897c34520e3 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:00:53 +0100 Subject: [PATCH 07/53] (CONT-783) - Correct Layout/HashAlignment --- lib/puppet/functions/inifile/create_ini_settings.rb | 2 +- spec/classes/create_multiple_ini_settings_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/functions/inifile/create_ini_settings.rb b/lib/puppet/functions/inifile/create_ini_settings.rb index 072e3a7d..0d1109f7 100644 --- a/lib/puppet/functions/inifile/create_ini_settings.rb +++ b/lib/puppet/functions/inifile/create_ini_settings.rb @@ -23,7 +23,7 @@ def default_impl(settings, defaults = {}) settings[section].each do |setting, value| res["#{path} [#{section}] #{setting}"] = { - 'ensure' => 'present', + 'ensure' => 'present', 'section' => section, 'setting' => setting, }.merge(if value.is_a?(Hash) diff --git a/spec/classes/create_multiple_ini_settings_spec.rb b/spec/classes/create_multiple_ini_settings_spec.rb index db797440..8db900ad 100644 --- a/spec/classes/create_multiple_ini_settings_spec.rb +++ b/spec/classes/create_multiple_ini_settings_spec.rb @@ -5,10 +5,10 @@ describe 'create_multiple_ini_settings' do context 'on a non-Windows platform', if: !Puppet::Util::Platform.windows? do let(:facts) do - { 'os' => { 'family' => 'RedHat', + { 'os' => { 'family' => 'RedHat', 'release' => { 'major' => '7', 'minor' => '1', - 'full' => '7.1.1503' } } } + 'full' => '7.1.1503' } } } end it { is_expected.to compile } From 20020bfc00d9b91ca04f2257ddfe32838b39c647 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:02:29 +0100 Subject: [PATCH 08/53] (CONT-783) - Correct Layout/HeredocIndentation --- .../puppet/provider/ini_setting/ruby_spec.rb | 1598 ++++++++--------- 1 file changed, 799 insertions(+), 799 deletions(-) diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index e452ed7c..bd62af1a 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -121,50 +121,50 @@ def self.file_path context 'when ensuring that a setting is present' do let(:orig_content) do - <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment - --nonstandard- - shoes = purple + <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS end - expected_content_one = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_one = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -yahoo = yippee -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + yahoo = yippee + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple EOS it 'adds a missing setting to the correct section' do resource = Puppet::Type::Ini_setting.new(common_params.merge(setting: 'yahoo', value: 'yippee')) @@ -174,27 +174,27 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_two = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple - yahoo = yippee + -nonstandard- + shoes = purple + yahoo = yippee EOS it 'adds a missing setting to the correct section with pre/suffix' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'yahoo', value: 'yippee', section_prefix: '-', section_suffix: '-')) @@ -204,27 +204,27 @@ def self.file_path validate_file(expected_content_two, tmpfile) end - expected_content_three = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_three = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple - indented = weirdly + -nonstandard- + shoes = purple + indented = weirdly EOS it 'adds a missing setting to the correct section with indent_char' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'indented', value: 'weirdly', section_prefix: '-', section_suffix: '-', indent_char: "\t")) @@ -234,27 +234,27 @@ def self.file_path validate_file(expected_content_three, tmpfile) end - expected_content_four = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_four = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple - indented = weirdly + -nonstandard- + shoes = purple + indented = weirdly EOS it 'adds a missing setting to the correct section indented by indent_char * indent_width' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'indented', value: 'weirdly', @@ -265,27 +265,27 @@ def self.file_path validate_file(expected_content_four, tmpfile) end - expected_content_five = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_five = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple - indented = weirdly + -nonstandard- + shoes = purple + indented = weirdly EOS it 'treats a string indent_width as an integer' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'indented', value: 'weirdly', @@ -296,27 +296,27 @@ def self.file_path validate_file(expected_content_five, tmpfile) end - expected_content_six = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_six = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple -yahoo = yippee + -nonstandard- + shoes = purple + yahoo = yippee EOS it 'adds a missing setting to the correct section with colon' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'yahoo', value: 'yippee')) @@ -326,26 +326,26 @@ def self.file_path validate_file(expected_content_six, tmpfile) end - expected_content_seven = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_seven = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue2 -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue2 + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple EOS it 'modifies an existing setting with a different value' do resource = Puppet::Type::Ini_setting.new(common_params.merge(setting: 'baz', value: 'bazvalue2')) @@ -355,26 +355,26 @@ def self.file_path validate_file(expected_content_seven, tmpfile) end - expected_content_eight = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_eight = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = false -[section2] + bar = barvalue + main = false + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple EOS it 'modifies an existing setting with a different boolean value' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'main', value: false)) @@ -386,26 +386,26 @@ def self.file_path end # rubocop:enable RSpec/MultipleExpectations : Unable to reduce without altering test - expected_content_nine = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment - --nonstandard- - shoes = orange + expected_content_nine = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = orange EOS it 'modifies an existing setting with pre/suffix with a different value' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'shoes', value: 'orange', section_prefix: '-', section_suffix: '-')) @@ -415,26 +415,26 @@ def self.file_path validate_file(expected_content_nine, tmpfile) end - expected_content_ten = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_ten = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=foo - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=foo + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple EOS it 'modifies an existing setting with a different value - with colon in section' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'subby', value: 'foo')) @@ -444,26 +444,26 @@ def self.file_path validate_file(expected_content_ten, tmpfile) end - expected_content_eleven = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_eleven = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.0.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.0.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple EOS it 'is able to handle settings with non alphanumbering settings' do resource = Puppet::Type::Ini_setting.new(common_params.merge(setting: 'url', value: 'http://192.168.0.1:8080')) @@ -473,26 +473,26 @@ def self.file_path validate_file(expected_content_eleven, tmpfile) end - expected_content_twelve = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_twelve = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = http://192.168.0.1:8080 + -nonstandard- + shoes = http://192.168.0.1:8080 EOS it 'is able to handle settings with pre/suffix with non alphanumbering settings' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'shoes', value: 'http://192.168.0.1:8080', section_prefix: '-', section_suffix: '-')) @@ -515,29 +515,29 @@ def self.file_path expect(provider.exists?).to be true end - expected_content_thirteen = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_thirteen = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple -[section3] -huzzah = shazaam + [section3] + huzzah = shazaam EOS it 'adds a new section if the section does not exist' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section3', setting: 'huzzah', value: 'shazaam')) @@ -547,29 +547,29 @@ def self.file_path validate_file(expected_content_thirteen, tmpfile) end - expected_content_fourteen = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_fourteen = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple --section3- -huzzah = shazaam + -section3- + huzzah = shazaam EOS it 'adds a new section with pre/suffix if the section does not exist' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section3', setting: 'huzzah', value: 'shazaam', section_prefix: '-', section_suffix: '-')) @@ -579,29 +579,29 @@ def self.file_path validate_file(expected_content_fourteen, tmpfile) end - expected_content_fifteen = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_fifteen = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple -[section:subsection] -huzzah = shazaam + [section:subsection] + huzzah = shazaam EOS it 'adds a new section if the section does not exist - with colon' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:subsection', setting: 'huzzah', value: 'shazaam')) @@ -611,29 +611,29 @@ def self.file_path validate_file(expected_content_fifteen, tmpfile) end - expected_content_sixteen = <<-EOS -# This is a comment -[section1] -; This is also a comment -foo=foovalue + expected_content_sixteen = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue -bar = barvalue -main = true -[section2] + bar = barvalue + main = true + [section2] -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment --nonstandard- - shoes = purple + -nonstandard- + shoes = purple --section:subsection- -huzzah = shazaam + -section:subsection- + huzzah = shazaam EOS it 'adds a new section with pre/suffix if the section does not exist - with colon' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:subsection', setting: 'huzzah', value: 'shazaam', section_prefix: '-', section_suffix: '-')) @@ -741,22 +741,22 @@ def self.file_path context 'when dealing with a global section' do let(:orig_content) do - <<-EOS -# This is a comment -foo=blah -[section2] -foo = http://192.168.1.1:8080 - ; yet another comment + <<~EOS + # This is a comment + foo=blah + [section2] + foo = http://192.168.1.1:8080 + ; yet another comment EOS end - expected_content_one = <<-EOS -# This is a comment -foo=blah -bar = yippee -[section2] -foo = http://192.168.1.1:8080 - ; yet another comment + expected_content_one = <<~EOS + # This is a comment + foo=blah + bar = yippee + [section2] + foo = http://192.168.1.1:8080 + ; yet another comment EOS it "adds a missing setting if it doesn't exist" do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: '', setting: 'bar', value: 'yippee')) @@ -766,12 +766,12 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -# This is a comment -foo=yippee -[section2] -foo = http://192.168.1.1:8080 - ; yet another comment + expected_content_two = <<~EOS + # This is a comment + foo=yippee + [section2] + foo = http://192.168.1.1:8080 + ; yet another comment EOS it 'modifies an existing setting with a different value' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: '', setting: 'foo', value: 'yippee')) @@ -790,17 +790,17 @@ def self.file_path context 'when the first line of the file is a section' do let(:orig_content) do - <<-EOS -[section2] -foo = http://192.168.1.1:8080 + <<~EOS + [section2] + foo = http://192.168.1.1:8080 EOS end - expected_content_one = <<-EOS -foo = yippee + expected_content_one = <<~EOS + foo = yippee -[section2] -foo = http://192.168.1.1:8080 + [section2] + foo = http://192.168.1.1:8080 EOS it 'is able to add a global setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: '', setting: 'foo', value: 'yippee')) @@ -810,9 +810,9 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -[section2] -foo = yippee + expected_content_two = <<~EOS + [section2] + foo = yippee EOS it 'modifies an existing setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'foo', value: 'yippee')) @@ -822,10 +822,10 @@ def self.file_path validate_file(expected_content_two, tmpfile) end - expected_content_three = <<-EOS -[section2] -foo = http://192.168.1.1:8080 -bar = baz + expected_content_three = <<~EOS + [section2] + foo = http://192.168.1.1:8080 + bar = baz EOS it 'adds a new setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'bar', value: 'baz')) @@ -838,15 +838,15 @@ def self.file_path context 'when overriding the separator' do let(:orig_content) do - <<-EOS -[section2] -foo=bar + <<~EOS + [section2] + foo=bar EOS end - expected_content_one = <<-EOS -[section2] -foo=yippee + expected_content_one = <<~EOS + [section2] + foo=yippee EOS it 'modifies an existing setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'foo', value: 'yippee', key_val_separator: '=')) @@ -859,15 +859,15 @@ def self.file_path context 'when overriding the separator to something other than =' do let(:orig_content) do - <<-EOS -[section2] -foo: bar + <<~EOS + [section2] + foo: bar EOS end - expected_content_one = <<-EOS -[section2] -foo: yippee + expected_content_one = <<~EOS + [section2] + foo: yippee EOS it 'modifies an existing setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'foo', value: 'yippee', key_val_separator: ': ')) @@ -877,10 +877,10 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -[section2] -foo: bar -bar: baz + expected_content_two = <<~EOS + [section2] + foo: bar + bar: baz EOS it 'adds a new setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'bar', value: 'baz', key_val_separator: ': ')) @@ -893,15 +893,15 @@ def self.file_path context 'when overriding the separator to a space' do let(:orig_content) do - <<-EOS -[section2] -foo bar + <<~EOS + [section2] + foo bar EOS end - expected_content_one = <<-EOS -[section2] -foo yippee + expected_content_one = <<~EOS + [section2] + foo yippee EOS it 'modifies an existing setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'foo', value: 'yippee', key_val_separator: ' ')) @@ -911,10 +911,10 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -[section2] -foo bar -bar baz + expected_content_two = <<~EOS + [section2] + foo bar + bar baz EOS it 'adds a new setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'bar', value: 'baz', key_val_separator: ' ')) @@ -927,56 +927,56 @@ def self.file_path context 'when ensuring that a setting is absent' do let(:orig_content) do - <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS end - expected_content_one = <<-EOS -[section1] -; This is also a comment - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + expected_content_one = <<~EOS + [section1] + ; This is also a comment + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS it 'removes a setting that exists' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'foo', ensure: 'absent')) @@ -986,27 +986,27 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment + expected_content_two = <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment EOS it 'removes a setting with pre/suffix that exists' do @@ -1017,30 +1017,30 @@ def self.file_path validate_file(expected_content_two, tmpfile) end - expected_content_three = <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + expected_content_three = <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS it 'does nothing for a setting that does not exist' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'foo', ensure: 'absent')) @@ -1050,30 +1050,30 @@ def self.file_path validate_file(expected_content_three, tmpfile) end - expected_content_four = <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + expected_content_four = <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS it 'does nothing for a setting with pre/suffix that does not exist' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'nonstandard', setting: 'foo', ensure: 'absent', section_prefix: '-', section_suffix: '-')) @@ -1083,29 +1083,29 @@ def self.file_path validate_file(expected_content_four, tmpfile) end - expected_content_five = <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -[section4] -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + expected_content_five = <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + [section4] + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS it 'does not remove a section when the last uncommented setting is removed if there are comments' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section3', setting: 'uncom', ensure: 'absent')) @@ -1115,28 +1115,28 @@ def self.file_path validate_file(expected_content_five, tmpfile) end - expected_content_six = <<-EOS -[section1] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section2] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section3] -# com = ment -uncom = ment -[section:sub] -subby=bar - #another comment - ; yet another comment - - -nonstandard- - shoes = purple + expected_content_six = <<~EOS + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section2] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section3] + # com = ment + uncom = ment + [section:sub] + subby=bar + #another comment + ; yet another comment + + -nonstandard- + shoes = purple EOS it 'removes the section when removing the last line in the section' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section4', setting: 'uncom', ensure: 'absent')) @@ -1149,46 +1149,46 @@ def self.file_path context 'when dealing with indentation in sections' do let(:orig_content) do - <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment + <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment EOS end - expected_content_one = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - yahoo = yippee - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment + expected_content_one = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + yahoo = yippee + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment EOS it 'adds a missing setting at the correct indentation when the header is aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'yahoo', value: 'yippee')) @@ -1198,24 +1198,24 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue2 - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment + expected_content_two = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue2 + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment EOS it 'updates an existing setting at the correct indentation when the header is aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'bar', value: 'barvalue2')) @@ -1225,25 +1225,25 @@ def self.file_path validate_file(expected_content_two, tmpfile) end - expected_content_three = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 - yahoo = yippee -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment + expected_content_three = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + yahoo = yippee + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment EOS it 'adds a missing setting at the correct indentation when the header is not aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'yahoo', value: 'yippee')) @@ -1253,24 +1253,24 @@ def self.file_path validate_file(expected_content_three, tmpfile) end - expected_content_four = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue2 - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment + expected_content_four = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue2 + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment EOS it 'updates an existing setting at the correct indentation when the header is not aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'baz', value: 'bazvalue2')) @@ -1280,25 +1280,25 @@ def self.file_path validate_file(expected_content_four, tmpfile) end - expected_content_five = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam - ; yet another comment - yahoo = yippee + expected_content_five = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam + ; yet another comment + yahoo = yippee EOS it 'adds a missing setting at the min indentation when the section is not aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'yahoo', value: 'yippee')) @@ -1308,24 +1308,24 @@ def self.file_path validate_file(expected_content_five, tmpfile) end - expected_content_six = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam2 - ; yet another comment + expected_content_six = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam2 + ; yet another comment EOS it 'updates an existing setting at the previous indentation when the section is not aligned' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'fleezy', value: 'flam2')) @@ -1335,24 +1335,24 @@ def self.file_path validate_file(expected_content_six, tmpfile) end - expected_content_seven = <<-EOS -# This is a comment - [section1] - ; This is also a comment - foo=foovalue - - bar = barvalue - main = true - -[section2] - foo= foovalue2 - baz=bazvalue - url = http://192.168.1.1:8080 -[section:sub] - subby=bar - #another comment - fleezy = flam2 - ; yet another comment + expected_content_seven = <<~EOS + # This is a comment + [section1] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + + [section2] + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + fleezy = flam2 + ; yet another comment EOS it 'updates an existing setting at the previous indentation regardless of indent_char and indent_width settings' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section:sub', setting: 'fleezy', value: 'flam2', indent_char: 'ignore this', indent_width: 10)) @@ -1365,32 +1365,32 @@ def self.file_path context 'when dealing settings that have a commented version present' do let(:orig_content) do - <<-EOS - [section1] - # foo=foovalue - bar=barvalue - foo = foovalue2 - -[section2] -# foo = foovalue -;bar=barvalue -blah = blah -#baz= + <<~EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 + + [section2] + # foo = foovalue + ;bar=barvalue + blah = blah + #baz= EOS end - expected_content_eight = <<-EOS - [section1] - # foo=foovalue - bar=barvalue - foo = foovalue2 + expected_content_eight = <<~EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 -[section2] -# foo = foovalue -foo = foo3 -;bar=barvalue -blah = blah -#baz= + [section2] + # foo = foovalue + foo = foo3 + ;bar=barvalue + blah = blah + #baz= EOS it 'adds a new setting below a commented version of that setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'foo', value: 'foo3')) @@ -1400,17 +1400,17 @@ def self.file_path validate_file(expected_content_eight, tmpfile) end - expected_content_nine = <<-EOS - [section1] - # foo=foovalue - bar=barvalue - foo = foo3 + expected_content_nine = <<~EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foo3 -[section2] -# foo = foovalue -;bar=barvalue -blah = blah -#baz= + [section2] + # foo = foovalue + ;bar=barvalue + blah = blah + #baz= EOS it 'updates an existing setting in place, even if there is a commented version of that setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'foo', value: 'foo3')) @@ -1420,18 +1420,18 @@ def self.file_path validate_file(expected_content_nine, tmpfile) end - expected_content_ten = <<-EOS - [section1] - # foo=foovalue - bar=barvalue - foo = foovalue2 + expected_content_ten = <<~EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 -[section2] -# foo = foovalue -;bar=barvalue -bar = bar3 -blah = blah -#baz= + [section2] + # foo = foovalue + ;bar=barvalue + bar = bar3 + blah = blah + #baz= EOS it 'adds a new setting below a commented version of that setting, respecting semicolons as comments' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'bar', value: 'bar3')) @@ -1441,18 +1441,18 @@ def self.file_path validate_file(expected_content_ten, tmpfile) end - expected_content_four = <<-EOS - [section1] - # foo=foovalue - bar=barvalue - foo = foovalue2 + expected_content_four = <<~EOS + [section1] + # foo=foovalue + bar=barvalue + foo = foovalue2 -[section2] -# foo = foovalue -;bar=barvalue -blah = blah -#baz= -baz = bazvalue + [section2] + # foo = foovalue + ;bar=barvalue + blah = blah + #baz= + baz = bazvalue EOS it 'adds a new setting below an empty commented version of that setting' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section2', setting: 'baz', value: 'bazvalue')) @@ -1464,18 +1464,18 @@ def self.file_path context 'when a section only contains comments' do let(:orig_content) do - <<-EOS -[section1] -# foo=foovalue -# bar=bar2 + <<~EOS + [section1] + # foo=foovalue + # bar=bar2 EOS end - expected_content_one = <<-EOS -[section1] -# foo=foovalue -foo = foovalue2 -# bar=bar2 + expected_content_one = <<~EOS + [section1] + # foo=foovalue + foo = foovalue2 + # bar=bar2 EOS it 'is able to add a new setting when a section contains only comments' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'foo', value: 'foovalue2')) @@ -1485,11 +1485,11 @@ def self.file_path validate_file(expected_content_one, tmpfile) end - expected_content_two = <<-EOS -[section1] -# foo=foovalue -# bar=bar2 -bar = barvalue2 + expected_content_two = <<~EOS + [section1] + # foo=foovalue + # bar=bar2 + bar = barvalue2 EOS it 'is able to add a new setting when it matches a commented out line other than the first one' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'bar', value: 'barvalue2')) @@ -1502,44 +1502,44 @@ def self.file_path context 'when sections have spaces and dashes' do let(:orig_content) do - <<-EOS -# This is a comment -[section - one] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section - two] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -[section:sub] -subby=bar - #another comment - ; yet another comment + <<~EOS + # This is a comment + [section - one] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section - two] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + [section:sub] + subby=bar + #another comment + ; yet another comment EOS end - expected_content_one = <<-EOS -# This is a comment -[section - one] -; This is also a comment -foo=foovalue - -bar = barvalue -main = true -[section - two] - -foo= foovalue2 -baz=bazvalue -url = http://192.168.1.1:8080 -yahoo = yippee -[section:sub] -subby=bar - #another comment - ; yet another comment + expected_content_one = <<~EOS + # This is a comment + [section - one] + ; This is also a comment + foo=foovalue + + bar = barvalue + main = true + [section - two] + + foo= foovalue2 + baz=bazvalue + url = http://192.168.1.1:8080 + yahoo = yippee + [section:sub] + subby=bar + #another comment + ; yet another comment EOS it 'adds a missing setting to the correct section' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section - two', setting: 'yahoo', value: 'yippee')) @@ -1553,30 +1553,30 @@ def self.file_path context 'when sections have spaces and quotations' do let(:orig_content) do - <<-EOS -[branch "main"] - remote = origin - merge = refs/heads/main - -[alias] -to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/main -[branch "production"] - remote = origin - merge = refs/heads/production + <<~EOS + [branch "main"] + remote = origin + merge = refs/heads/main + + [alias] + to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/main + [branch "production"] + remote = origin + merge = refs/heads/production EOS end - expected_content_one = <<-EOS -[branch "main"] - remote = origin - merge = refs/heads/main + expected_content_one = <<~EOS + [branch "main"] + remote = origin + merge = refs/heads/main -[alias] -to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/main -foo = bar -[branch "production"] - remote = origin - merge = refs/heads/production + [alias] + to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/main + foo = bar + [branch "production"] + remote = origin + merge = refs/heads/production EOS it 'adds a missing setting to the correct section' do resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'alias', setting: 'foo', value: 'bar')) From d03cd3fc283f8173ca4fe5ac5d6426cf2397bbbb Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:03:33 +0100 Subject: [PATCH 09/53] (CONT-783) - Correct Lint/AmbiguousOperatorPrecedence --- lib/puppet/util/ini_file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 3342745e..a9347d50 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -146,7 +146,7 @@ def save whitespace_buffer = [] if section.new_section? && !section.global? - if index == 1 && !global_empty || index > 1 + if (index == 1 && !global_empty) || index > 1 fh.puts('') end From fee6b75c55f6a55cb8da58e5a197883bca780f13 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:08:49 +0100 Subject: [PATCH 10/53] (CONT-783) - add rubocop_todo --- .rubocop_todo.yml | 424 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 424 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..70c7affd --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,424 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-05 10:47:41 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Layout/ClosingHeredocIndentation: +# Exclude: +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + +# Offense count: 10 +# This cop supports safe autocorrection (--autocorrect). +# Layout/EmptyLineAfterGuardClause: +# Exclude: +# - 'lib/puppet/provider/ini_setting/ruby.rb' +# - 'lib/puppet/type/ini_setting.rb' +# - 'lib/puppet/util/ini_file.rb' +# - 'lib/puppet/util/setting_value.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +# Layout/HashAlignment: +# Exclude: +# - 'lib/puppet/functions/inifile/create_ini_settings.rb' +# - 'spec/classes/create_multiple_ini_settings_spec.rb' + +# Offense count: 59 +# This cop supports safe autocorrection (--autocorrect). +# Layout/HeredocIndentation: +# Exclude: +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Lint/AmbiguousOperatorPrecedence: +# Exclude: +# - 'lib/puppet/util/ini_file.rb' + +# Offense count: 30 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/BooleanSymbol: + Exclude: + - 'lib/puppet/type/ini_setting.rb' + - 'lib/puppet/type/ini_subsetting.rb' + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 4 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 1 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopEnableDirective: + Exclude: + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/unit/puppet/util/ini_file_spec.rb' + +# Offense count: 11 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 48 + +# Offense count: 8 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 128 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 211 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 18 + +# Offense count: 13 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 33 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + MaxOptionalParameters: 5 + Max: 6 + +# Offense count: 2 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 20 + +# Offense count: 1 +Naming/AccessorMethodName: + Exclude: + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: lowercase, uppercase +Naming/HeredocDelimiterCase: + Exclude: + - 'lib/puppet/type/ini_subsetting.rb' + +# 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: 1 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/puppet/util/ini_file.rb' + +# Offense count: 2 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'spec/unit/puppet/type/ini_setting_spec.rb' + +# Offense count: 8 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/spec_helper_local.rb' + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + - 'spec/unit/puppet/util/ini_file_spec.rb' + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ContextMethod: + Exclude: + - 'spec/unit/puppet/util/external_iterator_spec.rb' + +# Offense count: 27 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/acceptance/ini_setting_spec.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/classes/create_multiple_ini_settings_spec.rb' + - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_subetting_spec.rb' + - 'spec/unit/puppet/util/external_iterator_spec.rb' + - 'spec/unit/puppet/util/ini_file_spec.rb' + +# Offense count: 12 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/acceptance/ini_setting_spec.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/classes/create_ini_settings_test_spec.rb' + - 'spec/classes/create_multiple_ini_settings_spec.rb' + - 'spec/classes/inherit_test1_spec.rb' + - 'spec/functions/create_ini_settings_spec.rb' + - 'spec/functions/inifile_create_ini_settings_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/type/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_subetting_spec.rb' + +# Offense count: 40 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterExample: + Exclude: + - 'spec/acceptance/ini_setting_spec.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/classes/create_ini_settings_test_spec.rb' + - 'spec/classes/create_multiple_ini_settings_spec.rb' + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_subetting_spec.rb' + - 'spec/unit/puppet/util/ini_file_spec.rb' + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/EmptyLineAfterExampleGroup: + Exclude: + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterHook: + Exclude: + - 'spec/acceptance/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_subetting_spec.rb' + +# Offense count: 8 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 26 + +# Offense count: 3 +RSpec/ExpectInHook: + Enabled: false + +# Offense count: 12 +RSpec/ImplicitBlockExpectation: + Exclude: + - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/unit/puppet/type/ini_subetting_spec.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit +RSpec/ImplicitSubject: + Exclude: + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/classes/create_ini_settings_test_spec.rb' + - 'spec/classes/create_multiple_ini_settings_spec.rb' + - 'spec/classes/inherit_test1_spec.rb' + +# Offense count: 4 +RSpec/LeakyConstantDeclaration: + Exclude: + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +RSpec/MatchArray: + Exclude: + - 'spec/unit/puppet/util/ini_file_spec.rb' + +# Offense count: 5 +RSpec/MultipleExpectations: + Max: 4 + +# Offense count: 29 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 6 + +# Offense count: 12 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: + Exclude: + - '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_subsetting/ruby_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ReceiveCounts: + Exclude: + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: and_return, block +RSpec/ReturnFromStub: + Exclude: + - 'spec/unit/puppet/util/ini_file_spec.rb' + +# Offense count: 1 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: . +# SupportedStyles: constant, string +RSpec/VerifiedDoubleReference: + EnforcedStyle: string + +# 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' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/EachForSimpleLoop: + Exclude: + - 'spec/unit/puppet/util/external_iterator_spec.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'lib/puppet/provider/ini_setting/ruby.rb' + - 'lib/puppet/provider/ini_subsetting/ruby.rb' + - 'lib/puppet/util/ini_file.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Style/FileWrite: + Exclude: + - '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' + +# Offense count: 10 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/puppet/type/ini_setting.rb' + - 'lib/puppet/type/ini_subsetting.rb' + - 'lib/puppet/util/ini_file.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/NegatedIfElseCondition: + Exclude: + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantStringEscape: + Exclude: + - 'spec/acceptance/ini_setting_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/puppet/util/ini_file.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/SlicingWithRange: + Exclude: + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 7 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/puppet/type/ini_setting.rb' + - 'lib/puppet/type/ini_subsetting.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + - 'spec/unit/puppet/util/setting_value_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. +# AllowedMethods: define_method +Style/SymbolProc: + Exclude: + - 'lib/puppet/util/setting_value.rb' + +# Offense count: 15 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'lib/puppet/functions/inifile/create_ini_settings.rb' + - 'lib/puppet/util/ini_file.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/spec_helper.rb' + - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' + - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' From faba4c5366ba065c456627717fd2b4f42e2007a6 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:34:38 +0100 Subject: [PATCH 11/53] (CONT-783) - pin puppet_agent v4.13.0 --- .fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index d7b3b389..85b50666 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -10,5 +10,5 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' From 883ef2c69d3af16771b92e6aea152622ff55e492 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:50:26 +0100 Subject: [PATCH 12/53] (CONT-783) - Correct Lint/ConstantDefinitionInBlock --- .rubocop_todo.yml | 6 +++--- spec/unit/puppet/util/setting_value_spec.rb | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 70c7affd..45167c53 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,9 +55,9 @@ Lint/BooleanSymbol: # Offense count: 4 # Configuration parameters: AllowedMethods. # AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/unit/puppet/util/setting_value_spec.rb' +# Lint/ConstantDefinitionInBlock: +# Exclude: +# - 'spec/unit/puppet/util/setting_value_spec.rb' # Offense count: 1 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index ce3847ea..07f375e9 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -3,9 +3,13 @@ require 'spec_helper' require 'puppet/util/setting_value' +INIT_VALUE_SPACE = '"-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"' +INIT_VALUE_COMMA = '"-Xmx192m,-XX:+HeapDumpOnOutOfMemoryError,-XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"' +INIT_VALUE_UNQUOTED = '-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof' +QUOTE_CHAR = '"' + describe Puppet::Util::SettingValue do describe 'space subsetting separator' do - INIT_VALUE_SPACE = '"-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"' let(:setting_value) { described_class.new(INIT_VALUE_SPACE, ' ') } @@ -39,7 +43,6 @@ end describe 'comma subsetting separator' do - INIT_VALUE_COMMA = '"-Xmx192m,-XX:+HeapDumpOnOutOfMemoryError,-XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof"' let(:setting_value) { described_class.new(INIT_VALUE_COMMA, ',') } @@ -72,8 +75,6 @@ end describe 'quote_char parameter' do - QUOTE_CHAR = '"' - INIT_VALUE_UNQUOTED = '-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/pe-puppetdb/puppetdb-oom.hprof' it 'gets quoted empty string if original value was empty' do setting_value = described_class.new(nil, ' ', QUOTE_CHAR) From d0821733e6a963b5c3d17c4704c9b5446f0c90bd Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:51:44 +0100 Subject: [PATCH 13/53] (CONT-783) - Layout/EmptyLinesAroundBlockBody --- .rubocop_todo.yml | 61 ++------------------- spec/unit/puppet/util/setting_value_spec.rb | 3 - 2 files changed, 4 insertions(+), 60 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45167c53..fbd01db3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,49 +1,3 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2023-04-05 10:47:41 UTC using RuboCop version 1.48.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Layout/ClosingHeredocIndentation: -# Exclude: -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - -# Offense count: 10 -# This cop supports safe autocorrection (--autocorrect). -# Layout/EmptyLineAfterGuardClause: -# Exclude: -# - 'lib/puppet/provider/ini_setting/ruby.rb' -# - 'lib/puppet/type/ini_setting.rb' -# - 'lib/puppet/util/ini_file.rb' -# - 'lib/puppet/util/setting_value.rb' - -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -# Layout/HashAlignment: -# Exclude: -# - 'lib/puppet/functions/inifile/create_ini_settings.rb' -# - 'spec/classes/create_multiple_ini_settings_spec.rb' - -# Offense count: 59 -# This cop supports safe autocorrection (--autocorrect). -# Layout/HeredocIndentation: -# Exclude: -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Lint/AmbiguousOperatorPrecedence: -# Exclude: -# - 'lib/puppet/util/ini_file.rb' - # Offense count: 30 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/BooleanSymbol: @@ -52,18 +6,11 @@ Lint/BooleanSymbol: - 'lib/puppet/type/ini_subsetting.rb' - 'lib/puppet/util/setting_value.rb' -# Offense count: 4 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -# Lint/ConstantDefinitionInBlock: +# # Offense count: 1 +# # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +# Lint/DuplicateBranch: # Exclude: -# - 'spec/unit/puppet/util/setting_value_spec.rb' - -# Offense count: 1 -# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. -Lint/DuplicateBranch: - Exclude: - - 'lib/puppet/util/setting_value.rb' +# - 'lib/puppet/util/setting_value.rb' # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index 07f375e9..646744e2 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -10,7 +10,6 @@ describe Puppet::Util::SettingValue do describe 'space subsetting separator' do - let(:setting_value) { described_class.new(INIT_VALUE_SPACE, ' ') } it 'gets the original value' do @@ -43,7 +42,6 @@ end describe 'comma subsetting separator' do - let(:setting_value) { described_class.new(INIT_VALUE_COMMA, ',') } it 'gets the original value' do @@ -75,7 +73,6 @@ end describe 'quote_char parameter' do - it 'gets quoted empty string if original value was empty' do setting_value = described_class.new(nil, ' ', QUOTE_CHAR) expect(setting_value.get_value).to eq(QUOTE_CHAR * 2) From 3537996c41844cd43bcfe90a570c7ce33de985cf Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 12:58:54 +0100 Subject: [PATCH 14/53] (CONT-783) - Lint/DuplicateBranch --- .rubocop_todo.yml | 6 ------ lib/puppet/util/setting_value.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fbd01db3..63f711a2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ Lint/BooleanSymbol: - 'lib/puppet/type/ini_subsetting.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 1 -# # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. -# Lint/DuplicateBranch: -# Exclude: -# - 'lib/puppet/util/setting_value.rb' - # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). Lint/RedundantCopEnableDirective: diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index 8e63c17e..87eafd9c 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -112,7 +112,7 @@ def add_subsetting(subsetting, subsetting_value, use_exact_match = :false, inser before_index = insert_value.to_i before_index = @subsetting_items.length if before_index > @subsetting_items.length @subsetting_items.insert(before_index, new_item) - else + else # rubocop:disable Lint/DuplicateBranch @subsetting_items.push(new_item) end From 5ae0d6feb4ad29238dc24986ae6d8254293eaa78 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 13:01:36 +0100 Subject: [PATCH 15/53] (CONT-783) - Lint/RedundantCopEnableDirective --- .rubocop_todo.yml | 10 +++++----- spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 4 ---- spec/unit/puppet/type/ini_setting_spec.rb | 1 - 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 63f711a2..02a5cfa0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -8,11 +8,11 @@ Lint/BooleanSymbol: # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopEnableDirective: - Exclude: - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - - 'spec/unit/puppet/type/ini_setting_spec.rb' - - 'spec/unit/puppet/util/ini_file_spec.rb' +# Lint/RedundantCopEnableDirective: +# Exclude: +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/type/ini_setting_spec.rb' +# - 'spec/unit/puppet/util/ini_file_spec.rb' # Offense count: 11 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index bd62af1a..6d3a2527 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -114,8 +114,6 @@ def self.file_path expect(ensure_array.uniq).to eq([:present]) expect((real_array - expected_array) && (expected_array - real_array)).to eq([]) end - # rubocop:enable RSpec/ExampleLength - # rubocop:enable RSpec/MultipleExpectations end end @@ -384,7 +382,6 @@ def self.file_path expect(Puppet::Transaction::ResourceHarness.new(transaction).evaluate(provider.resource).out_of_sync).to eq(true) validate_file(expected_content_eight, tmpfile) end - # rubocop:enable RSpec/MultipleExpectations : Unable to reduce without altering test expected_content_nine = <<~EOS # This is a comment @@ -1586,5 +1583,4 @@ def self.file_path validate_file(expected_content_one, tmpfile) end end - # rubocop:enable Layout/IndentHeredoc end diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index 00b3adf5..b945ee4d 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -64,7 +64,6 @@ it { is_expected.to raise_exception } end end - # rubocop:enable RSpec/NestedGroups end [true, false].product([true, false, 'true', 'false', 'md5', :md5]).each do |cfg, param| From 0d8fe2fec1c6f05bcd6b5619b95e5a0520f2ee57 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 14:51:01 +0100 Subject: [PATCH 16/53] (CONT-783) - Metrics/ClassLength --- .rubocop_todo.yml | 16 ++++------------ lib/puppet/util/ini_file.rb | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 02a5cfa0..4354dee3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ Lint/BooleanSymbol: - 'lib/puppet/type/ini_subsetting.rb' - 'lib/puppet/util/setting_value.rb' -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Lint/RedundantCopEnableDirective: -# Exclude: -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' -# - 'spec/unit/puppet/type/ini_setting_spec.rb' -# - 'spec/unit/puppet/util/ini_file_spec.rb' - # Offense count: 11 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: @@ -25,10 +17,10 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 128 -# Offense count: 1 -# Configuration parameters: CountComments, CountAsOne. -Metrics/ClassLength: - Max: 211 +# # Offense count: 1 +# # Configuration parameters: CountComments, CountAsOne. +# Metrics/ClassLength: +# Max: 211 # Offense count: 3 # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index a9347d50..a2605dcf 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -7,7 +7,7 @@ module Puppet::Util # # ini_file.rb # - class IniFile + class IniFile # rubocop:disable Metrics/ClassLength def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_suffix = ']', indent_char = ' ', indent_width = nil) From 602da0f20274842061df7115bd8ca03885dc9923 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 14:58:46 +0100 Subject: [PATCH 17/53] (CONT-783) - Correct Metrics/ParameterLists --- .rubocop_todo.yml | 15 +++++---------- lib/puppet/util/ini_file.rb | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4354dee3..b7ea6c88 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -17,11 +17,6 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 128 -# # Offense count: 1 -# # Configuration parameters: CountComments, CountAsOne. -# Metrics/ClassLength: -# Max: 211 - # Offense count: 3 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: @@ -32,11 +27,11 @@ Metrics/CyclomaticComplexity: Metrics/MethodLength: Max: 33 -# Offense count: 2 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - MaxOptionalParameters: 5 - Max: 6 +# # Offense count: 2 +# # Configuration parameters: CountKeywordArgs. +# Metrics/ParameterLists: +# MaxOptionalParameters: 5 +# Max: 6 # Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index a2605dcf..3eb313fc 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -8,7 +8,7 @@ module Puppet::Util # ini_file.rb # class IniFile # rubocop:disable Metrics/ClassLength - def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_suffix = ']', + def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_suffix = ']', # rubocop:disable Metrics/ParameterLists indent_char = ' ', indent_width = nil) k_v_s = (key_val_separator =~ %r{^\s+$}) ? ' ' : key_val_separator.strip From f5e30c97d252e330e4ce31b35d9cb99febd211cd Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:06:56 +0100 Subject: [PATCH 18/53] (CONT-783) - Correct Naming/HeredocDelimiterCase --- .rubocop_todo.yml | 12 +++--------- lib/puppet/type/ini_subsetting.rb | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b7ea6c88..bebaeae6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -27,12 +27,6 @@ Metrics/CyclomaticComplexity: Metrics/MethodLength: Max: 33 -# # Offense count: 2 -# # Configuration parameters: CountKeywordArgs. -# Metrics/ParameterLists: -# MaxOptionalParameters: 5 -# Max: 6 - # Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: @@ -47,9 +41,9 @@ Naming/AccessorMethodName: # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: lowercase, uppercase -Naming/HeredocDelimiterCase: - Exclude: - - 'lib/puppet/type/ini_subsetting.rb' +# Naming/HeredocDelimiterCase: +# Exclude: +# - 'lib/puppet/type/ini_subsetting.rb' # Offense count: 114 # Configuration parameters: ForbiddenDelimiters. diff --git a/lib/puppet/type/ini_subsetting.rb b/lib/puppet/type/ini_subsetting.rb index 403e0474..8ac88854 100644 --- a/lib/puppet/type/ini_subsetting.rb +++ b/lib/puppet/type/ini_subsetting.rb @@ -108,7 +108,7 @@ def is_to_s(value) # rubocop:disable Naming/PredicateName : Changing breaks the end newparam(:insert_type) do - desc <<-eof + desc <<-EOF Where the new subsetting item should be inserted * :start - insert at the beginning of the line. @@ -116,7 +116,7 @@ def is_to_s(value) # rubocop:disable Naming/PredicateName : Changing breaks the * :before - insert before the specified element if possible. * :after - insert after the specified element if possible. * :index - insert at the specified index number. - eof + EOF newvalues(:start, :end, :before, :after, :index) defaultto(:end) From ebb32687804c006892569449ee84250091c2bab5 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:07:15 +0100 Subject: [PATCH 19/53] (CONT-783) - Correct Naming/HeredocDelimiterCase --- .rubocop_todo.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bebaeae6..e203083a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,14 +37,6 @@ Naming/AccessorMethodName: Exclude: - 'lib/puppet/util/setting_value.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: lowercase, uppercase -# Naming/HeredocDelimiterCase: -# Exclude: -# - 'lib/puppet/type/ini_subsetting.rb' - # Offense count: 114 # Configuration parameters: ForbiddenDelimiters. # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) @@ -58,12 +50,12 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' -# Offense count: 1 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to -Naming/MethodParameterName: - Exclude: - - 'lib/puppet/util/ini_file.rb' +# # Offense count: 1 +# # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +# Naming/MethodParameterName: +# Exclude: +# - 'lib/puppet/util/ini_file.rb' # Offense count: 2 # Configuration parameters: MinSize. From 99afec09b76971dcfc6c8d49dfd6682459d89c16 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:09:35 +0100 Subject: [PATCH 20/53] (CONT-783) - Correct Naming/MethodParameterName --- lib/puppet/util/ini_file.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 3eb313fc..dab1d067 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -335,10 +335,10 @@ def increment_section_line_numbers(section_index) end end - def flush_buffer_to_file(buffer, fh) + def flush_buffer_to_file(buffer, file) return if buffer.empty? - buffer.each { |l| fh.puts(l) } + buffer.each { |l| file.puts(l) } buffer.clear end end From 9cafd1d01a9b197a61b17de2c47bbdd9281dd7fb Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:20:16 +0100 Subject: [PATCH 21/53] (CONT-783) - Correct Performance/CollectionLiteralInLoop --- .rubocop_todo.yml | 15 ++++----------- spec/unit/puppet/type/ini_setting_spec.rb | 6 ++++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e203083a..2051d3a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,18 +50,11 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' -# # Offense count: 1 -# # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to -# Naming/MethodParameterName: +# # Offense count: 2 +# # Configuration parameters: MinSize. +# Performance/CollectionLiteralInLoop: # Exclude: -# - 'lib/puppet/util/ini_file.rb' - -# Offense count: 2 -# Configuration parameters: MinSize. -Performance/CollectionLiteralInLoop: - Exclude: - - 'spec/unit/puppet/type/ini_setting_spec.rb' +# - 'spec/unit/puppet/type/ini_setting_spec.rb' # Offense count: 8 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index b945ee4d..99dd51ff 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -73,7 +73,9 @@ end let(:value) { described_class.new(name: 'foo', value: 'whatever', show_diff: param).property(:value) } - if cfg && [true, 'true'].include?(param) + true_array = [true, 'true'] + md5_array = ['md5', :md5] + if cfg && true_array.include?(param) it 'displays diff' do expect(value.change_to_s('not_secret', 'at_all')).to include('not_secret', 'at_all') end @@ -85,7 +87,7 @@ it 'tells new value' do expect(value.should_to_s('not_secret_at_all')).to eq('not_secret_at_all') end - elsif cfg && ['md5', :md5].include?(param) + elsif cfg && md5_array.include?(param) it 'tells correct md5 hashes for multiple values' do expect(value.change_to_s('not_at', 'all_secret')).to include('6edef0c4f5ec664feff6ca6fbc290970', '1660308ab156754fa09af0e8dc2c6629') end From 0d3c292458ff3b59f6e2793bbe7353bf2d668503 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:21:46 +0100 Subject: [PATCH 22/53] (CONT-783) - Correct RSpec/BeEq --- .rubocop_todo.yml | 18 ++++++------------ spec/spec_helper_local.rb | 2 +- .../puppet/provider/ini_setting/ruby_spec.rb | 2 +- spec/unit/puppet/util/ini_file_spec.rb | 6 +++--- spec/unit/puppet/util/setting_value_spec.rb | 6 +++--- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2051d3a1..bfd6b6da 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,20 +50,14 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' -# # Offense count: 2 -# # Configuration parameters: MinSize. -# Performance/CollectionLiteralInLoop: -# Exclude: -# - 'spec/unit/puppet/type/ini_setting_spec.rb' - # Offense count: 8 # This cop supports unsafe autocorrection (--autocorrect-all). -RSpec/BeEq: - Exclude: - - 'spec/spec_helper_local.rb' - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - - 'spec/unit/puppet/util/ini_file_spec.rb' - - 'spec/unit/puppet/util/setting_value_spec.rb' +# RSpec/BeEq: +# Exclude: +# - 'spec/spec_helper_local.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/util/ini_file_spec.rb' +# - 'spec/unit/puppet/util/setting_value_spec.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 0d9188cb..570190ff 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -30,7 +30,7 @@ end shared_examples 'create_ini_settings function' do - it { is_expected.not_to eq(nil) } + it { is_expected.not_to be_nil } it { is_expected.to run.with_params({}) } it { is_expected.to run.with_params({}, {}) } diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 6d3a2527..6fe7e9d6 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -379,7 +379,7 @@ def self.file_path provider = described_class.new(resource) expect(provider.exists?).to be true transaction = instance_double('transaction', persistence: true) - expect(Puppet::Transaction::ResourceHarness.new(transaction).evaluate(provider.resource).out_of_sync).to eq(true) + expect(Puppet::Transaction::ResourceHarness.new(transaction).evaluate(provider.resource).out_of_sync).to be(true) validate_file(expected_content_eight, tmpfile) end diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index abf4a25a..9a036dc4 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -128,9 +128,9 @@ end before :each do - expect(ini_sub.get_value('section1', 'far')).to eq(nil) - expect(ini_sub.get_value('section1', 'bar')).to eq(nil) - expect(ini_sub.get_value('section1', "xyzzy['thing1']['thing2']")).to eq(nil) + expect(ini_sub.get_value('section1', 'far')).to be_nil + expect(ini_sub.get_value('section1', 'bar')).to be_nil + expect(ini_sub.get_value('section1', "xyzzy['thing1']['thing2']")).to be_nil end # rubocop:enable RSpec/ExpectInHook diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index 646744e2..aa705166 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -37,7 +37,7 @@ it 'removes existing value' do setting_value.remove_subsetting('-Xmx') - expect(setting_value.get_subsetting_value('-Xmx')).to eq(nil) + expect(setting_value.get_subsetting_value('-Xmx')).to be_nil end end @@ -68,7 +68,7 @@ it 'removes existing value' do setting_value.remove_subsetting('-Xmx') - expect(setting_value.get_subsetting_value('-Xmx')).to eq(nil) + expect(setting_value.get_subsetting_value('-Xmx')).to be_nil end end @@ -108,7 +108,7 @@ setting_value = described_class.new(INIT_VALUE_UNQUOTED, ' ', QUOTE_CHAR) setting_value.remove_subsetting('-Xmx') - expect(setting_value.get_subsetting_value('-Xmx')).to eq(nil) + expect(setting_value.get_subsetting_value('-Xmx')).to be_nil end end it 'quotes the setting when removing an existing value #quotes' do From b0021c9ccbbabab5bdc0bd8584f7949495501151 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:22:52 +0100 Subject: [PATCH 23/53] (CONT-783) - Correct RSpec/ContextMethod --- .rubocop_todo.yml | 16 ++++------------ spec/unit/puppet/util/external_iterator_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bfd6b6da..93fe09ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,20 +50,12 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' -# Offense count: 8 -# This cop supports unsafe autocorrection (--autocorrect-all). -# RSpec/BeEq: -# Exclude: -# - 'spec/spec_helper_local.rb' -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' -# - 'spec/unit/puppet/util/ini_file_spec.rb' -# - 'spec/unit/puppet/util/setting_value_spec.rb' # Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ContextMethod: - Exclude: - - 'spec/unit/puppet/util/external_iterator_spec.rb' +# # This cop supports safe autocorrection (--autocorrect). +# RSpec/ContextMethod: +# Exclude: +# - 'spec/unit/puppet/util/external_iterator_spec.rb' # Offense count: 27 # Configuration parameters: Prefixes, AllowedPatterns. diff --git a/spec/unit/puppet/util/external_iterator_spec.rb b/spec/unit/puppet/util/external_iterator_spec.rb index 4773d833..db3487f6 100644 --- a/spec/unit/puppet/util/external_iterator_spec.rb +++ b/spec/unit/puppet/util/external_iterator_spec.rb @@ -12,7 +12,7 @@ expected_values = [['a', 0], ['b', 1], ['c', 2]] end - context '#next' do + describe '#next' do it 'iterates over the items' do expected_values.each do |expected_pair| expect(subject_class.next).to eq(expected_pair) @@ -20,7 +20,7 @@ end end - context '#peek' do + describe '#peek' do it 'returns the 0th item repeatedly' do (0..2).each do |_i| expect(subject_class.peek).to eq(expected_values[0]) From 8ea2f04fd8e46782a54c79b0c34d75e5436e8f7b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:25:47 +0100 Subject: [PATCH 24/53] (CONT-783) - Correct RSpec/EmptyLineAfterExample --- .rubocop_todo.yml | 28 ++++++++----------- spec/acceptance/ini_setting_spec.rb | 5 ++++ spec/acceptance/ini_subsetting_spec.rb | 1 + spec/classes/create_ini_settings_test_spec.rb | 3 ++ .../create_multiple_ini_settings_spec.rb | 1 + .../puppet/provider/ini_setting/ruby_spec.rb | 1 + spec/unit/puppet/type/ini_setting_spec.rb | 10 +++++++ spec/unit/puppet/type/ini_subetting_spec.rb | 8 ++++++ spec/unit/puppet/util/ini_file_spec.rb | 8 ++++++ spec/unit/puppet/util/setting_value_spec.rb | 3 ++ 10 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 93fe09ab..e1be77e2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -51,12 +51,6 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/util/ini_file_spec.rb' -# Offense count: 2 -# # This cop supports safe autocorrection (--autocorrect). -# RSpec/ContextMethod: -# Exclude: -# - 'spec/unit/puppet/util/external_iterator_spec.rb' - # Offense count: 27 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without @@ -95,17 +89,17 @@ RSpec/DescribeClass: # Offense count: 40 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterExample: - Exclude: - - 'spec/acceptance/ini_setting_spec.rb' - - 'spec/acceptance/ini_subsetting_spec.rb' - - 'spec/classes/create_ini_settings_test_spec.rb' - - 'spec/classes/create_multiple_ini_settings_spec.rb' - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - - 'spec/unit/puppet/type/ini_setting_spec.rb' - - 'spec/unit/puppet/type/ini_subetting_spec.rb' - - 'spec/unit/puppet/util/ini_file_spec.rb' - - 'spec/unit/puppet/util/setting_value_spec.rb' +# RSpec/EmptyLineAfterExample: +# Exclude: +# - 'spec/acceptance/ini_setting_spec.rb' +# - 'spec/acceptance/ini_subsetting_spec.rb' +# - 'spec/classes/create_ini_settings_test_spec.rb' +# - 'spec/classes/create_multiple_ini_settings_spec.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/type/ini_setting_spec.rb' +# - 'spec/unit/puppet/type/ini_subetting_spec.rb' +# - 'spec/unit/puppet/util/ini_file_spec.rb' +# - 'spec/unit/puppet/util/setting_value_spec.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index c6608878..339096d9 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -197,6 +197,7 @@ it 'applies manifest and expects changed value to be logged in proper form' do expect(res.stdout).to match(i[:matcher]) end + it 'applies manifest and expects changed value to be logged in proper form #optional test' do expect(res.stdout).not_to match(i[:value]) unless i[:show_diff] == true end @@ -258,6 +259,7 @@ describe file("#{basedir}/ini_setting.ini") do it { is_expected.to be_file } + describe '#content' do subject { super().content } @@ -289,6 +291,7 @@ describe file("#{basedir}/ini_setting.ini") do it { is_expected.to be_file } + describe '#content' do subject { super().content } @@ -323,6 +326,7 @@ describe file("#{basedir}/ini_setting.ini") do it { is_expected.to be_file } + describe '#content' do subject { super().content } @@ -356,6 +360,7 @@ describe file("#{basedir}/ini_setting.ini") do it { is_expected.to be_file } + describe '#content' do subject { super().content } diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index aec0b7a1..8cec49b3 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -216,6 +216,7 @@ it 'applies manifest and expects changed value to be logged in proper form' do expect(res.stdout).to match(i[:matcher]) end + it 'applies manifest and expects changed value to be logged in proper form #optional test' do expect(res.stdout).not_to match(i[:value]) unless i[:show_diff] == true end diff --git a/spec/classes/create_ini_settings_test_spec.rb b/spec/classes/create_ini_settings_test_spec.rb index 5f5555bf..fa257c0d 100644 --- a/spec/classes/create_ini_settings_test_spec.rb +++ b/spec/classes/create_ini_settings_test_spec.rb @@ -4,6 +4,7 @@ # end-to-end test of the create_init_settings function describe 'create_ini_settings_test' do it { is_expected.to have_ini_setting_resource_count(3) } + it { is_expected.to contain_ini_setting('/tmp/foo.ini [section1] setting1').with( ensure: 'present', section: 'section1', @@ -11,6 +12,7 @@ path: '/tmp/foo.ini' ) } + it { is_expected.to contain_ini_setting('/tmp/foo.ini [section2] setting2').with( ensure: 'present', section: 'section2', @@ -18,6 +20,7 @@ path: '/tmp/foo.ini' ) } + it { is_expected.to contain_ini_setting('/tmp/foo.ini [section2] setting3').with( ensure: 'absent', section: 'section2', diff --git a/spec/classes/create_multiple_ini_settings_spec.rb b/spec/classes/create_multiple_ini_settings_spec.rb index 8db900ad..090210a6 100644 --- a/spec/classes/create_multiple_ini_settings_spec.rb +++ b/spec/classes/create_multiple_ini_settings_spec.rb @@ -23,6 +23,7 @@ path: '/tmp/foo.ini', ) } + it { is_expected.to contain_ini_setting('/tmp/foo.ini [section1] setting2').with( ensure: 'absent', diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 6fe7e9d6..26864c27 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -52,6 +52,7 @@ def self.file_path expect(child_one).to receive(:file_path).and_return(emptyfile) expect(child_one.instances).to eq([]) end + child_two = Class.new(provider_class) do def self.file_path '/some/file/path' diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index 99dd51ff..d225b56d 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -91,9 +91,11 @@ it 'tells correct md5 hashes for multiple values' do expect(value.change_to_s('not_at', 'all_secret')).to include('6edef0c4f5ec664feff6ca6fbc290970', '1660308ab156754fa09af0e8dc2c6629') end + it 'does not tell singular value one' do expect(value.change_to_s('not_at #', 'all_secret')).not_to include('not_at') end + it 'does not tell singular value two' do expect(value.change_to_s('not_at', 'all_secret')).not_to include('all_secret') end @@ -101,6 +103,7 @@ it 'tells md5 of current value' do expect(value.is_to_s('not_at_all_secret')).to eq('{md5}858b46aee11b780b8f5c8853668efc05') end + it 'does not tell the current value' do expect(value.is_to_s('not_at_all_secret')).not_to include('not_secret_at_all') end @@ -108,6 +111,7 @@ it 'tells md5 of new value' do expect(value.should_to_s('not_at_all_secret')).to eq('{md5}858b46aee11b780b8f5c8853668efc05') end + it 'does not tell the new value' do expect(value.should_to_s('not_at_all_secret')).not_to include('not_secret_at_all') end @@ -115,9 +119,11 @@ it 'tells redaction warning in place of actual values' do expect(value.change_to_s('at_all', 'not_secret')).to include('[redacted sensitive information]') end + it 'does not tell actual value one' do expect(value.change_to_s('at_all', 'not_secret')).not_to include('not_secret') end + it 'does not tell actual value two' do expect(value.change_to_s('at_all', 'not_secret')).not_to include('at_all') end @@ -125,6 +131,7 @@ it 'tells redaction warning in place of current value' do expect(value.is_to_s('not_secret_at_all')).to eq('[redacted sensitive information]') end + it 'does not tell current value' do expect(value.is_to_s('not_secret_at_all')).not_to include('not_secret_at_all') end @@ -132,6 +139,7 @@ it 'tells redaction warning in place of new value' do expect(value.should_to_s('not_secret_at_all')).to eq('[redacted sensitive information]') end + it 'does not tell new value' do expect(value.should_to_s('not_secret_at_all')).not_to include('not_secret_at_all') end @@ -162,9 +170,11 @@ it 'creates relationship' do expect(auto_req.size).to be 1 end + it 'links to ini_setting resource' do expect(auto_req[0].target).to eq(ini_setting_resource) end + it 'autorequires parent directory' do expect(auto_req[0].source).to eq(file_resource) end diff --git a/spec/unit/puppet/type/ini_subetting_spec.rb b/spec/unit/puppet/type/ini_subetting_spec.rb index d32de89e..3a6cd40a 100644 --- a/spec/unit/puppet/type/ini_subetting_spec.rb +++ b/spec/unit/puppet/type/ini_subetting_spec.rb @@ -83,9 +83,11 @@ it 'tells correct md5 hashes for multiple values' do expect(value.change_to_s('not_secret', 'at_all')).to include('e9e8db547f8960ef32dbc34029735564', '46cd73a9509ba78c39f05faf078a8cbe') end + it 'does not tell singular value one' do expect(value.change_to_s('not_secret', 'at_all')).not_to include('not_secret') end + it 'does not tell singular value two' do expect(value.change_to_s('not_secret', 'at_all')).not_to include('at_all') end @@ -93,6 +95,7 @@ it 'tells md5 of current value' do expect(value.is_to_s('not_secret_at_all')).to eq('{md5}218fde79f501b8ab8d212f1059bb857f') end + it 'does not tell the current value' do expect(value.is_to_s('not_secret_at_all')).not_to include('not_secret_at_all') end @@ -100,6 +103,7 @@ it 'tells md5 of new value' do expect(value.should_to_s('not_secret_at_all')).not_to include('not_secret_at_all') end + it 'does not tell the new value' do expect(value.should_to_s('not_secret_at_all')).to eq('{md5}218fde79f501b8ab8d212f1059bb857f') end @@ -107,9 +111,11 @@ it 'tells redaction warning in place of actual values' do expect(value.change_to_s('not_at', 'all_secret')).to include('[redacted sensitive information]') end + it 'does not tell actual value one' do expect(value.change_to_s('not_at', 'all_secret')).not_to include('not_at') end + it 'does not tell actual value two' do expect(value.change_to_s('not_at', 'all_secret')).not_to include('all_secret') end @@ -117,6 +123,7 @@ it 'tells redaction warning in place of current value' do expect(value.is_to_s('not_at_all_secret')).to eq('[redacted sensitive information]') end + it 'does not tell current value' do expect(value.is_to_s('not_at_all_secret')).not_to include('not_at_all_secret') end @@ -124,6 +131,7 @@ it 'tells redaction warning in place of new value' do expect(value.should_to_s('not_at_all_secret')).to eq('[redacted sensitive information]') end + it 'does not tell new value' do expect(value.should_to_s('not_at_all_secret')).not_to include('not_at_all_secret') end diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 9a036dc4..5c5aa069 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -53,6 +53,7 @@ 'baz' => '', 'foo' => 'foovalue') end + it 'exposes settings for sections #section2' do expect(ini_sub.get_settings('section2')).to eq('baz' => 'bazvalue', 'foo' => 'foovalue2', @@ -111,6 +112,7 @@ it 'exposes settings for sections #bar' do expect(ini_sub.get_value('', 'foo')).to eq('bar') end + it 'exposes settings for sections #foovalue' do expect(ini_sub.get_value('section1', 'foo')).to eq('foovalue') end @@ -260,6 +262,7 @@ it 'exposes settings for sections #print' do expect(ini_sub.get_value('khotkeys', '{5465e8c7-d608-4493-a48f-b99d99fdb508}')).to eq('Print,none,PrintScreen') end + it 'exposes settings for sections #search' do expect(ini_sub.get_value('khotkeys', '{d03619b6-9b3c-48cc-9d9c-a2aadb485550}')).to eq('Search,none,Search') end @@ -279,9 +282,11 @@ it 'exposes settings for sections #A' do expect(ini_sub.get_value('Drive names', 'A:')).to eq '5.25" Floppy' end + it 'exposes settings for sections #B' do expect(ini_sub.get_value('Drive names', 'B:')).to eq '3.5" Floppy' end + it 'exposes settings for sections #C' do expect(ini_sub.get_value('Drive names', 'C:')).to eq 'Winchester' end @@ -304,12 +309,15 @@ it 'exposes settings for sections #log' do expect(ini_sub.get_value('global', 'log file')).to eq '/var/log/samba/log.%m' end + it 'exposes settings for sections #kerberos' do expect(ini_sub.get_value('global', 'kerberos method')).to eq 'system keytab' end + it 'exposes settings for sections #passdb' do expect(ini_sub.get_value('global', 'passdb backend')).to eq 'tdbsam' end + it 'exposes settings for sections #security' do expect(ini_sub.get_value('global', 'security')).to eq 'ads' end diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index aa705166..df55fa91 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -56,6 +56,7 @@ setting_value.add_subsetting('-Xms', '256m') expect(setting_value.get_subsetting_value('-Xms')).to eq('256m') end + it 'adds a new value #original' do setting_value.add_subsetting('-Xms', '256m') expect(setting_value.get_value).to eq(INIT_VALUE_COMMA[0, INIT_VALUE_COMMA.length - 1] + ',-Xms256m"') @@ -84,6 +85,7 @@ expect(setting_value.get_subsetting_value('-Xms')).to eq('256m') end + it 'quotes the setting when adding a value #original' do setting_value = described_class.new(INIT_VALUE_UNQUOTED, ' ', QUOTE_CHAR) setting_value.add_subsetting('-Xms', '256m') @@ -97,6 +99,7 @@ expect(setting_value.get_subsetting_value('-Xmx')).to eq('512m') end + it 'quotes the setting when changing an existing value #quotes' do setting_value = described_class.new(INIT_VALUE_UNQUOTED, ' ', QUOTE_CHAR) setting_value.add_subsetting('-Xmx', '512m') From ec494d7716f499a3442bf9c75787042b514b075b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:26:21 +0100 Subject: [PATCH 25/53] (CONT-783) - Correct RSpec/EmptyLineAfterExampleGroup --- .rubocop_todo.yml | 22 ++++----------------- spec/unit/puppet/util/setting_value_spec.rb | 1 + 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e1be77e2..2c57c9ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -86,27 +86,13 @@ RSpec/DescribeClass: - 'spec/unit/puppet/type/ini_setting_spec.rb' - 'spec/unit/puppet/type/ini_subetting_spec.rb' -# Offense count: 40 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -# RSpec/EmptyLineAfterExample: + +# # Offense count: 1 +# # This cop supports safe autocorrection (--autocorrect). +# RSpec/EmptyLineAfterExampleGroup: # Exclude: -# - 'spec/acceptance/ini_setting_spec.rb' -# - 'spec/acceptance/ini_subsetting_spec.rb' -# - 'spec/classes/create_ini_settings_test_spec.rb' -# - 'spec/classes/create_multiple_ini_settings_spec.rb' -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' -# - 'spec/unit/puppet/type/ini_setting_spec.rb' -# - 'spec/unit/puppet/type/ini_subetting_spec.rb' -# - 'spec/unit/puppet/util/ini_file_spec.rb' # - 'spec/unit/puppet/util/setting_value_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterExampleGroup: - Exclude: - - 'spec/unit/puppet/util/setting_value_spec.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowConsecutiveOneLiners. diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index df55fa91..fad0f7a3 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -114,6 +114,7 @@ expect(setting_value.get_subsetting_value('-Xmx')).to be_nil end end + it 'quotes the setting when removing an existing value #quotes' do setting_value = described_class.new(INIT_VALUE_UNQUOTED, ' ', QUOTE_CHAR) setting_value.remove_subsetting('-Xmx') From 05d2f01ca51bc71cb14b2680f8178ba3ab34f4c6 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:27:17 +0100 Subject: [PATCH 26/53] (CONT-783) - Correct RSpec/EmptyLineAfterHook --- .rubocop_todo.yml | 19 ++++++------------- spec/acceptance/ini_setting_spec.rb | 1 + spec/unit/puppet/type/ini_setting_spec.rb | 2 ++ spec/unit/puppet/type/ini_subetting_spec.rb | 1 + 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2c57c9ab..5443ad74 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -86,21 +86,14 @@ RSpec/DescribeClass: - 'spec/unit/puppet/type/ini_setting_spec.rb' - 'spec/unit/puppet/type/ini_subetting_spec.rb' - -# # Offense count: 1 +# Offense count: 4 # # This cop supports safe autocorrection (--autocorrect). -# RSpec/EmptyLineAfterExampleGroup: +# # Configuration parameters: AllowConsecutiveOneLiners. +# RSpec/EmptyLineAfterHook: # Exclude: -# - 'spec/unit/puppet/util/setting_value_spec.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterHook: - Exclude: - - 'spec/acceptance/ini_setting_spec.rb' - - 'spec/unit/puppet/type/ini_setting_spec.rb' - - 'spec/unit/puppet/type/ini_subetting_spec.rb' +# - 'spec/acceptance/ini_setting_spec.rb' +# - 'spec/unit/puppet/type/ini_setting_spec.rb' +# - 'spec/unit/puppet/type/ini_subetting_spec.rb' # Offense count: 8 # Configuration parameters: CountAsOne. diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index 339096d9..09f1a1fe 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -234,6 +234,7 @@ after :each do run_shell("rm #{basedir}/ini_setting.ini", expect_failures: true) end + context 'when event is triggered' do context 'update setting value' do let(:update_value_manifest) do diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index d225b56d..fa49bdf1 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -14,6 +14,7 @@ Puppet.features.stub(:microsoft_windows?) { false } Puppet::Util::Platform.stub(:windows?) { false } end + context 'with an absolute path' do let(:path) { '/absolute/path' } @@ -71,6 +72,7 @@ before(:each) do Puppet[:show_diff] = cfg end + let(:value) { described_class.new(name: 'foo', value: 'whatever', show_diff: param).property(:value) } true_array = [true, 'true'] diff --git a/spec/unit/puppet/type/ini_subetting_spec.rb b/spec/unit/puppet/type/ini_subetting_spec.rb index 3a6cd40a..f1216cfb 100644 --- a/spec/unit/puppet/type/ini_subetting_spec.rb +++ b/spec/unit/puppet/type/ini_subetting_spec.rb @@ -65,6 +65,7 @@ before(:each) do Puppet[:show_diff] = cfg end + let(:value) { described_class.new(name: 'foo', value: 'whatever', show_diff: param).property(:value) } if cfg && param == true From 7e8b98f890d6fb0dffcee0d535235cfb41225598 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 15:28:30 +0100 Subject: [PATCH 27/53] (CONT-783) - Correct RSpec/ExpectInHook --- .rubocop_todo.yml | 15 +++------------ spec/unit/puppet/util/ini_file_spec.rb | 1 + 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5443ad74..a417cc18 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -86,23 +86,14 @@ RSpec/DescribeClass: - 'spec/unit/puppet/type/ini_setting_spec.rb' - 'spec/unit/puppet/type/ini_subetting_spec.rb' -# Offense count: 4 -# # This cop supports safe autocorrection (--autocorrect). -# # Configuration parameters: AllowConsecutiveOneLiners. -# RSpec/EmptyLineAfterHook: -# Exclude: -# - 'spec/acceptance/ini_setting_spec.rb' -# - 'spec/unit/puppet/type/ini_setting_spec.rb' -# - 'spec/unit/puppet/type/ini_subetting_spec.rb' - # Offense count: 8 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 26 -# Offense count: 3 -RSpec/ExpectInHook: - Enabled: false +# # Offense count: 3 +# RSpec/ExpectInHook: +# Enabled: false # Offense count: 12 RSpec/ImplicitBlockExpectation: diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 5c5aa069..158bc3d5 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -129,6 +129,7 @@ template.split("\n") end + # rubocop:disable RSpec/ExpectInHook before :each do expect(ini_sub.get_value('section1', 'far')).to be_nil expect(ini_sub.get_value('section1', 'bar')).to be_nil From 023bbc8b2d0f68de39e0138391685fede3785cba Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 5 Apr 2023 17:08:45 +0100 Subject: [PATCH 28/53] (CONT-783) - Correct RSpec/MatchArray --- .rubocop_todo.yml | 11 +++-------- spec/unit/puppet/util/ini_file_spec.rb | 12 +++--------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a417cc18..26a6e781 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,16 +112,11 @@ RSpec/ImplicitSubject: - 'spec/classes/create_multiple_ini_settings_spec.rb' - 'spec/classes/inherit_test1_spec.rb' -# Offense count: 4 -RSpec/LeakyConstantDeclaration: - Exclude: - - 'spec/unit/puppet/util/setting_value_spec.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). -RSpec/MatchArray: - Exclude: - - 'spec/unit/puppet/util/ini_file_spec.rb' +# RSpec/MatchArray: +# Exclude: +# - 'spec/unit/puppet/util/ini_file_spec.rb' # Offense count: 5 RSpec/MultipleExpectations: diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 158bc3d5..4801d583 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -195,10 +195,7 @@ end it 'parses the sections' do - expect(ini_sub.section_names).to match_array ['', - 'branch "main"', - 'alias', - 'branch "production"'] + expect(ini_sub.section_names).to contain_exactly('', 'branch "main"', 'alias', 'branch "production"') end end @@ -228,7 +225,7 @@ end it 'parses the correct section_names' do - expect(ini_sub.section_names).to match_array ['', 'global', 'printers', 'print$', 'Shares'] + expect(ini_sub.section_names).to contain_exactly('', 'global', 'printers', 'print$', 'Shares') end end @@ -242,10 +239,7 @@ end it 'parses the correct section_names' do - expect(ini_sub.section_names).to match_array [ - '', - 'monitor:///var/log/*.log', - ] + expect(ini_sub.section_names).to contain_exactly('', 'monitor:///var/log/*.log') end end From c3e9f692fc79d42da6b88fa137855effc2d184b5 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 08:53:50 +0100 Subject: [PATCH 29/53] (CONT-783) - Correct RSpec/ContextWording --- .rubocop_todo.yml | 52 ++++++++++--------- spec/acceptance/ini_setting_spec.rb | 20 +++---- spec/acceptance/ini_subsetting_spec.rb | 2 +- .../create_multiple_ini_settings_spec.rb | 4 +- spec/unit/puppet/type/ini_setting_spec.rb | 20 +++---- spec/unit/puppet/type/ini_subetting_spec.rb | 6 +-- spec/unit/puppet/util/ini_file_spec.rb | 12 ++--- 7 files changed, 59 insertions(+), 57 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 26a6e781..34c53c2d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,3 +1,11 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-06 07:44:08 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + # Offense count: 30 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/BooleanSymbol: @@ -50,19 +58,17 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' - -# Offense count: 27 -# Configuration parameters: Prefixes, AllowedPatterns. -# Prefixes: when, with, without -RSpec/ContextWording: - Exclude: - - 'spec/acceptance/ini_setting_spec.rb' - - 'spec/acceptance/ini_subsetting_spec.rb' - - 'spec/classes/create_multiple_ini_settings_spec.rb' - - 'spec/unit/puppet/type/ini_setting_spec.rb' - - 'spec/unit/puppet/type/ini_subetting_spec.rb' - - 'spec/unit/puppet/util/external_iterator_spec.rb' - - 'spec/unit/puppet/util/ini_file_spec.rb' +# # Offense count: 25 +# # Configuration parameters: Prefixes, AllowedPatterns. +# # Prefixes: when, with, without +# RSpec/ContextWording: +# Exclude: +# - 'spec/acceptance/ini_setting_spec.rb' +# - 'spec/acceptance/ini_subsetting_spec.rb' +# - 'spec/classes/create_multiple_ini_settings_spec.rb' +# - 'spec/unit/puppet/type/ini_setting_spec.rb' +# - 'spec/unit/puppet/type/ini_subetting_spec.rb' +# - 'spec/unit/puppet/util/ini_file_spec.rb' # Offense count: 12 # Configuration parameters: IgnoredMetadata. @@ -91,14 +97,9 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 26 -# # Offense count: 3 -# RSpec/ExpectInHook: -# Enabled: false - -# Offense count: 12 +# Offense count: 5 RSpec/ImplicitBlockExpectation: Exclude: - - 'spec/unit/puppet/type/ini_setting_spec.rb' - 'spec/unit/puppet/type/ini_subetting_spec.rb' # Offense count: 7 @@ -112,16 +113,17 @@ RSpec/ImplicitSubject: - 'spec/classes/create_multiple_ini_settings_spec.rb' - 'spec/classes/inherit_test1_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# RSpec/MatchArray: -# Exclude: -# - 'spec/unit/puppet/util/ini_file_spec.rb' - # Offense count: 5 RSpec/MultipleExpectations: Max: 4 +# Offense count: 7 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/unit/puppet/type/ini_setting_spec.rb' + # Offense count: 29 # Configuration parameters: AllowedGroups. RSpec/NestedGroups: diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index 09f1a1fe..9bf7c290 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -43,7 +43,7 @@ end end - context 'ensure parameter => present for global and section' do + context 'when ensure parameter => present for global and section' do pp = <<-EOS ini_setting { 'ensure => present for section': ensure => present, @@ -64,7 +64,7 @@ it_behaves_like 'has_content', "#{basedir}/ini_setting.ini", pp, %r{four = five\R\R\[one\]\Rtwo = three} end - context 'ensure parameter => absent for key/value' do + context 'when ensure parameter => absent for key/value' do before :all do ipp = <<-MANIFEST file { '#{basedir}/ini_setting.ini': @@ -103,7 +103,7 @@ end end - context 'ensure parameter => absent for global' do + context 'when ensure parameter => absent for global' do before :all do ipp = <<-MANIFEST file { '#{basedir}/ini_setting.ini': @@ -147,7 +147,7 @@ end describe 'path parameter' do - context 'path => foo' do + context 'when path => foo' do pp = <<-EOS ini_setting { 'path => foo': ensure => present, @@ -162,7 +162,7 @@ end end - context 'ensure parameter => present and only section' do + context 'when ensure parameter => present and only section' do pp = <<-EOS ini_setting { 'ensure => present for section': ensure => present, @@ -192,7 +192,7 @@ } EOS - context "show_diff => #{i[:show_diff]}" do + context "when show_diff => #{i[:show_diff]}" do res = apply_manifest(pp, expect_changes: true) it 'applies manifest and expects changed value to be logged in proper form' do expect(res.stdout).to match(i[:matcher]) @@ -236,7 +236,7 @@ end context 'when event is triggered' do - context 'update setting value' do + context 'when update setting value' do let(:update_value_manifest) do <<-EOS notify { foo: @@ -269,7 +269,7 @@ end end - context 'remove setting value' do + context 'when remove setting value' do let(:remove_setting_manifest) do <<-EOS notify { foo: @@ -303,7 +303,7 @@ end context 'when not receiving an event' do - context 'does not update setting' do + context 'when does not update setting' do let(:does_not_update_value_manifest) do <<-EOS file { "#{basedir}/ini_setting.ini": @@ -337,7 +337,7 @@ end end - context 'does not remove setting' do + context 'when does not remove setting' do let(:does_not_remove_setting_manifest) do <<-EOS file { "#{basedir}/ini_setting.ini": diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 8cec49b3..8e241322 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -211,7 +211,7 @@ } EOS - context "show_diff => #{i[:show_diff]}" do + context "when show_diff => #{i[:show_diff]}" do res = apply_manifest(pp, expect_changes: true) it 'applies manifest and expects changed value to be logged in proper form' do expect(res.stdout).to match(i[:matcher]) diff --git a/spec/classes/create_multiple_ini_settings_spec.rb b/spec/classes/create_multiple_ini_settings_spec.rb index 090210a6..fad38dd1 100644 --- a/spec/classes/create_multiple_ini_settings_spec.rb +++ b/spec/classes/create_multiple_ini_settings_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'create_multiple_ini_settings' do - context 'on a non-Windows platform', if: !Puppet::Util::Platform.windows? do + context 'when on a non-Windows platform', if: !Puppet::Util::Platform.windows? do let(:facts) do { 'os' => { 'family' => 'RedHat', 'release' => { 'major' => '7', @@ -34,7 +34,7 @@ } end - context 'on a Windows platform', if: Puppet::Util::Platform.windows? do + context 'when on a Windows platform', if: Puppet::Util::Platform.windows? do let(:facts) do { 'os' => { 'family' => 'windows' } } end diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index fa49bdf1..c3efccb1 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -8,7 +8,7 @@ describe 'path validation' do subject { -> { described_class.new(name: 'foo', path: path) } } - context 'on posix platforms' do + context 'when on posix platforms' do before(:each) do Puppet.features.stub(:posix?) { true } Puppet.features.stub(:microsoft_windows?) { false } @@ -18,17 +18,17 @@ context 'with an absolute path' do let(:path) { '/absolute/path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with a relative path' do let(:path) { 'relative/path' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end end - context 'on windows platforms' do + context 'when on windows platforms' do before(:each) do Puppet.features.stub(:posix?) { false } Puppet.features.stub(:microsoft_windows?) { true } @@ -38,31 +38,31 @@ context 'with an absolute path with front slashes' do let(:path) { 'c:/absolute/path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with an absolute path with backslashes' do let(:path) { 'c:\absolute\path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with an absolute path with mixed slashes' do let(:path) { 'c:/absolute\path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with a relative path with front slashes' do let(:path) { 'relative/path' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end context 'with a relative path with back slashes' do let(:path) { 'relative\path' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end end end @@ -151,7 +151,7 @@ describe 'when parent of :path is in the catalog' do ['posix', 'windows'].each do |platform| - context "on #{platform} platforms" do + context "when on #{platform} platforms" do before(:each) do Puppet.features.stub(:posix?) { platform == 'posix' } Puppet.features.stub(:microsoft_windows?) { platform == 'windows' } diff --git a/spec/unit/puppet/type/ini_subetting_spec.rb b/spec/unit/puppet/type/ini_subetting_spec.rb index f1216cfb..bffe2a59 100644 --- a/spec/unit/puppet/type/ini_subetting_spec.rb +++ b/spec/unit/puppet/type/ini_subetting_spec.rb @@ -8,7 +8,7 @@ describe 'quote_char validation' do subject { -> { described_class.new(name: 'foo', path: path, quote_char: quote_char) } } - context 'on posix platforms' do + context 'when on posix platforms' do let(:path) { '/absolute/path' } let(:quote_char) { '\”' } @@ -19,7 +19,7 @@ describe 'path validation' do subject { -> { described_class.new(name: 'foo', path: path) } } - context 'on posix platforms' do + context 'when on posix platforms' do before(:each) do Puppet.features.stub(:posix?) { true } Puppet.features.stub(:microsoft_windows?) { false } @@ -39,7 +39,7 @@ end end - context 'on windows platforms' do + context 'when on windows platforms' do before(:each) do Puppet.features.stub(:posix?) { false } Puppet.features.stub(:microsoft_windows?) { true } diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 4801d583..70fdf18a 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -178,7 +178,7 @@ end end - context 'the file has quotation marks in its section names' do + context 'when the file has quotation marks in its section names' do let(:sample_content) do template = <<-EOS [branch "main"] @@ -199,7 +199,7 @@ end end - context 'Samba INI file with dollars in section names' do + context 'when Samba INI file with dollars in section names' do let(:sample_content) do template = <<-EOS [global] @@ -229,7 +229,7 @@ end end - context 'section names with forward slashes in them' do + context 'when section names with forward slashes in them' do let(:sample_content) do template = <<-EOS [monitor:///var/log/*.log] @@ -243,7 +243,7 @@ end end - context 'KDE Configuration with braces in setting names' do + context 'when KDE Configuration with braces in setting names' do let(:sample_content) do template = <<-EOS [khotkeys] @@ -263,7 +263,7 @@ end end - context 'Configuration with colons in setting names' do + context 'when Configuration with colons in setting names' do let(:sample_content) do template = <<-EOS [Drive names] @@ -287,7 +287,7 @@ end end - context 'Configuration with spaces in setting names' do + context 'when Configuration with spaces in setting names' do let(:sample_content) do template = <<-EOS [global] From 8fc15287c379b5cd3094efe660099ead3ae822f4 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 08:55:23 +0100 Subject: [PATCH 30/53] (CONT-783) - Correct RSpec/ImplicitBlockExpectation --- .rubocop_todo.yml | 20 ++++---------------- spec/unit/puppet/type/ini_subetting_spec.rb | 10 +++++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 34c53c2d..921a1c16 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,18 +58,6 @@ Naming/HeredocDelimiterNaming: - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' - 'spec/unit/puppet/util/ini_file_spec.rb' -# # Offense count: 25 -# # Configuration parameters: Prefixes, AllowedPatterns. -# # Prefixes: when, with, without -# RSpec/ContextWording: -# Exclude: -# - 'spec/acceptance/ini_setting_spec.rb' -# - 'spec/acceptance/ini_subsetting_spec.rb' -# - 'spec/classes/create_multiple_ini_settings_spec.rb' -# - 'spec/unit/puppet/type/ini_setting_spec.rb' -# - 'spec/unit/puppet/type/ini_subetting_spec.rb' -# - 'spec/unit/puppet/util/ini_file_spec.rb' - # Offense count: 12 # Configuration parameters: IgnoredMetadata. RSpec/DescribeClass: @@ -97,10 +85,10 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 26 -# Offense count: 5 -RSpec/ImplicitBlockExpectation: - Exclude: - - 'spec/unit/puppet/type/ini_subetting_spec.rb' +# # Offense count: 5 +# RSpec/ImplicitBlockExpectation: +# Exclude: +# - 'spec/unit/puppet/type/ini_subetting_spec.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/unit/puppet/type/ini_subetting_spec.rb b/spec/unit/puppet/type/ini_subetting_spec.rb index bffe2a59..c957e0d4 100644 --- a/spec/unit/puppet/type/ini_subetting_spec.rb +++ b/spec/unit/puppet/type/ini_subetting_spec.rb @@ -12,7 +12,7 @@ let(:path) { '/absolute/path' } let(:quote_char) { '\”' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end end @@ -29,13 +29,13 @@ context 'with an absolute path' do let(:path) { '/absolute/path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with a relative path' do let(:path) { 'relative/path' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end end @@ -49,13 +49,13 @@ context 'with an absolute path with front slashes' do let(:path) { 'c:/absolute/path' } - it { is_expected.not_to raise_exception } + it { expect(subject).not_to raise_exception } end context 'with a relative path with back slashes' do let(:path) { 'relative\path' } - it { is_expected.to raise_exception } + it { expect(subject).to raise_exception } end end end From 82b5f1f670392837870ed03b74acd17a7f158858 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:28:09 +0100 Subject: [PATCH 31/53] (CONT-783) - Fix Spec Tests --- .rubocop_todo.yml | 21 ++++--------------- spec/acceptance/ini_subsetting_spec.rb | 2 +- spec/classes/create_ini_settings_test_spec.rb | 6 +++--- .../create_multiple_ini_settings_spec.rb | 4 ++-- spec/classes/inherit_test1_spec.rb | 2 +- spec/unit/puppet/type/ini_setting_spec.rb | 16 +++++++------- spec/unit/puppet/type/ini_subetting_spec.rb | 14 ++++++------- 7 files changed, 26 insertions(+), 39 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 921a1c16..a45cfab0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -85,22 +85,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 26 -# # Offense count: 5 -# RSpec/ImplicitBlockExpectation: -# Exclude: -# - 'spec/unit/puppet/type/ini_subetting_spec.rb' - -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: - Exclude: - - 'spec/acceptance/ini_subsetting_spec.rb' - - 'spec/classes/create_ini_settings_test_spec.rb' - - 'spec/classes/create_multiple_ini_settings_spec.rb' - - 'spec/classes/inherit_test1_spec.rb' - # Offense count: 5 RSpec/MultipleExpectations: Max: 4 @@ -110,7 +94,10 @@ RSpec/MultipleExpectations: # SupportedStyles: always, named_only RSpec/NamedSubject: Exclude: - - 'spec/unit/puppet/type/ini_setting_spec.rb' + - 'spec/acceptance/ini_subsetting_spec.rb' + - 'spec/classes/create_ini_settings_test_spec.rb' + - 'spec/classes/create_multiple_ini_settings_spec.rb' + - 'spec/classes/inherit_test1_spec.rb' # Offense count: 29 # Configuration parameters: AllowedGroups. diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 8e241322..26fb3af0 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -25,7 +25,7 @@ subject { super().content } it { - is_expected.to match content + expect(subject).to match content } end end diff --git a/spec/classes/create_ini_settings_test_spec.rb b/spec/classes/create_ini_settings_test_spec.rb index fa257c0d..0208f5d9 100644 --- a/spec/classes/create_ini_settings_test_spec.rb +++ b/spec/classes/create_ini_settings_test_spec.rb @@ -6,7 +6,7 @@ it { is_expected.to have_ini_setting_resource_count(3) } it { - is_expected.to contain_ini_setting('/tmp/foo.ini [section1] setting1').with( + expect(subject).to contain_ini_setting('/tmp/foo.ini [section1] setting1').with( ensure: 'present', section: 'section1', setting: 'setting1', value: 'val1', path: '/tmp/foo.ini' @@ -14,7 +14,7 @@ } it { - is_expected.to contain_ini_setting('/tmp/foo.ini [section2] setting2').with( + expect(subject).to contain_ini_setting('/tmp/foo.ini [section2] setting2').with( ensure: 'present', section: 'section2', setting: 'setting2', value: 'val2', path: '/tmp/foo.ini' @@ -22,7 +22,7 @@ } it { - is_expected.to contain_ini_setting('/tmp/foo.ini [section2] setting3').with( + expect(subject).to contain_ini_setting('/tmp/foo.ini [section2] setting3').with( ensure: 'absent', section: 'section2', setting: 'setting3', path: '/tmp/foo.ini' ) diff --git a/spec/classes/create_multiple_ini_settings_spec.rb b/spec/classes/create_multiple_ini_settings_spec.rb index fad38dd1..c5c83828 100644 --- a/spec/classes/create_multiple_ini_settings_spec.rb +++ b/spec/classes/create_multiple_ini_settings_spec.rb @@ -15,7 +15,7 @@ it { is_expected.to have_ini_setting_resource_count(2) } it { - is_expected.to contain_ini_setting('/tmp/foo.ini [section1] setting1').with( + expect(subject).to contain_ini_setting('/tmp/foo.ini [section1] setting1').with( ensure: 'present', section: 'section1', setting: 'setting1', @@ -25,7 +25,7 @@ } it { - is_expected.to contain_ini_setting('/tmp/foo.ini [section1] setting2').with( + expect(subject).to contain_ini_setting('/tmp/foo.ini [section1] setting2').with( ensure: 'absent', section: 'section1', setting: 'setting2', diff --git a/spec/classes/inherit_test1_spec.rb b/spec/classes/inherit_test1_spec.rb index 500810b2..5ed8ce4a 100644 --- a/spec/classes/inherit_test1_spec.rb +++ b/spec/classes/inherit_test1_spec.rb @@ -5,6 +5,6 @@ # parser OK. describe 'inherit_test1' do it { - is_expected.to contain_inherit_ini_setting('valid_type').with('value' => 'true') + expect(subject).to contain_inherit_ini_setting('valid_type').with('value' => 'true') } end diff --git a/spec/unit/puppet/type/ini_setting_spec.rb b/spec/unit/puppet/type/ini_setting_spec.rb index c3efccb1..89923565 100644 --- a/spec/unit/puppet/type/ini_setting_spec.rb +++ b/spec/unit/puppet/type/ini_setting_spec.rb @@ -6,7 +6,7 @@ describe ini_setting do describe 'path validation' do - subject { -> { described_class.new(name: 'foo', path: path) } } + subject(:ini_setting_path) { described_class.new(name: 'foo', path: path) } context 'when on posix platforms' do before(:each) do @@ -18,13 +18,13 @@ context 'with an absolute path' do let(:path) { '/absolute/path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_setting_path }.not_to raise_exception } end context 'with a relative path' do let(:path) { 'relative/path' } - it { expect(subject).to raise_exception } + it { expect { ini_setting_path }.to raise_exception(Puppet::ResourceError) } end end @@ -38,31 +38,31 @@ context 'with an absolute path with front slashes' do let(:path) { 'c:/absolute/path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_setting_path }.not_to raise_exception } end context 'with an absolute path with backslashes' do let(:path) { 'c:\absolute\path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_setting_path }.not_to raise_exception } end context 'with an absolute path with mixed slashes' do let(:path) { 'c:/absolute\path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_setting_path }.not_to raise_exception } end context 'with a relative path with front slashes' do let(:path) { 'relative/path' } - it { expect(subject).to raise_exception } + it { expect { ini_setting_path }.to raise_exception(Puppet::ResourceError) } end context 'with a relative path with back slashes' do let(:path) { 'relative\path' } - it { expect(subject).to raise_exception } + it { expect { ini_setting_path }.to raise_exception(Puppet::ResourceError) } end end end diff --git a/spec/unit/puppet/type/ini_subetting_spec.rb b/spec/unit/puppet/type/ini_subetting_spec.rb index c957e0d4..9638ceae 100644 --- a/spec/unit/puppet/type/ini_subetting_spec.rb +++ b/spec/unit/puppet/type/ini_subetting_spec.rb @@ -6,18 +6,18 @@ describe ini_subsetting do describe 'quote_char validation' do - subject { -> { described_class.new(name: 'foo', path: path, quote_char: quote_char) } } + subject(:ini_subsetting_test) { described_class.new(name: 'foo', path: path, quote_char: quote_char) } context 'when on posix platforms' do let(:path) { '/absolute/path' } let(:quote_char) { '\”' } - it { expect(subject).to raise_exception } + it { expect { ini_subsetting_test }.to raise_exception(Puppet::ResourceError) } end end describe 'path validation' do - subject { -> { described_class.new(name: 'foo', path: path) } } + subject(:ini_subsetting_test) { described_class.new(name: 'foo', path: path) } context 'when on posix platforms' do before(:each) do @@ -29,13 +29,13 @@ context 'with an absolute path' do let(:path) { '/absolute/path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_subsetting_test }.not_to raise_exception } end context 'with a relative path' do let(:path) { 'relative/path' } - it { expect(subject).to raise_exception } + it { expect { ini_subsetting_test }.to raise_exception(Puppet::ResourceError) } end end @@ -49,13 +49,13 @@ context 'with an absolute path with front slashes' do let(:path) { 'c:/absolute/path' } - it { expect(subject).not_to raise_exception } + it { expect { ini_subsetting_test }.not_to raise_exception } end context 'with a relative path with back slashes' do let(:path) { 'relative\path' } - it { expect(subject).to raise_exception } + it { expect { ini_subsetting_test }.to raise_exception(Puppet::ResourceError) } end end end From 2cab4b095b819f1430dce1e1e4fd52582d23df15 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:29:56 +0100 Subject: [PATCH 32/53] (CONT-783) - Correct Naming/AccessorMethodName --- .rubocop_todo.yml | 6 +++--- lib/puppet/util/setting_value.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a45cfab0..39c05699 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -41,9 +41,9 @@ Metrics/PerceivedComplexity: Max: 20 # Offense count: 1 -Naming/AccessorMethodName: - Exclude: - - 'lib/puppet/util/setting_value.rb' +# Naming/AccessorMethodName: +# Exclude: +# - 'lib/puppet/util/setting_value.rb' # Offense count: 114 # Configuration parameters: ForbiddenDelimiters. diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index 87eafd9c..2c263fe9 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -50,7 +50,7 @@ def unquote_setting_value(setting_value) # Get the resulting setting value by joining all the # subsettings, separator and quote characters. # @return [String] - def get_value + def get_value # rubocop:disable Naming/AccessorMethodName value = @subsetting_items.join @subsetting_separator @quote_char + value + @quote_char end From 3911fc0d7c0fb2e1a33f801fb7403b0117c33867 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:37:50 +0100 Subject: [PATCH 33/53] (CONT-783) - Correct RSpec/NoExpectationExample --- .rubocop_todo.yml | 17 ++++++----------- spec/acceptance/ini_setting_spec.rb | 6 +++--- spec/acceptance/ini_subsetting_spec.rb | 8 ++++---- .../provider/ini_setting/inheritance_spec.rb | 2 +- .../puppet/provider/ini_subsetting/ruby_spec.rb | 10 +++++----- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 39c05699..34b7ba7a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -40,11 +40,6 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 20 -# Offense count: 1 -# Naming/AccessorMethodName: -# Exclude: -# - 'lib/puppet/util/setting_value.rb' - # Offense count: 114 # Configuration parameters: ForbiddenDelimiters. # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) @@ -107,12 +102,12 @@ RSpec/NestedGroups: # Offense count: 12 # Configuration parameters: AllowedPatterns. # AllowedPatterns: ^expect_, ^assert_ -RSpec/NoExpectationExample: - Exclude: - - '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_subsetting/ruby_spec.rb' +# RSpec/NoExpectationExample: +# Exclude: +# - '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_subsetting/ruby_spec.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index 9bf7c290..f7368645 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file(path) do @@ -87,7 +87,7 @@ EOS it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file("#{basedir}/ini_setting.ini") do @@ -130,7 +130,7 @@ EOS it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file("#{basedir}/ini_setting.ini") do diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 26fb3af0..2fc92369 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file(path) do @@ -83,7 +83,7 @@ EOS it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file("#{basedir}/ini_subsetting.ini") do @@ -121,7 +121,7 @@ it 'applies the manifest twice' do run_shell("echo -e [one]\\\\nkey = alphabet betatrons > #{basedir}/ini_subsetting.ini", expect_failures: true) - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file("#{basedir}/ini_subsetting.ini") do @@ -176,7 +176,7 @@ EOS it 'applies the manifest twice' do - idempotent_apply(pp) + expect(idempotent_apply(pp)).to be_successful end describe file("#{basedir}/ini_subsetting.ini") do diff --git a/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb b/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb index 0f22485e..f1898b0a 100644 --- a/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb @@ -57,7 +57,7 @@ def validate_file(expected_content, tmpfile) resource = Puppet::Type::Inherit_ini_setting.new(setting: 'set_this', value: 'to_that') provider = described_class.new(resource) provider.create - validate_file("set_this=to_that\n", tmpfile) + expect(validate_file("set_this=to_that\n", tmpfile)).to be_truthy end end end diff --git a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb index 8c732ca6..5c547c43 100644 --- a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb @@ -234,7 +234,7 @@ def validate_file(expected_content, tmpfile) resource = Puppet::Type::Ini_subsetting.new(common_params.merge(subsetting: 'fo', subsetting_separator: ',')) provider = described_class.new(resource) provider.value = '' - validate_file(expected_content_one, tmpfile) + expect(validate_file(expected_content_one, tmpfile)).to be_truthy end expected_content_two = <<-EOS @@ -247,7 +247,7 @@ def validate_file(expected_content, tmpfile) provider = described_class.new(resource) provider.value = '' provider.destroy - validate_file(expected_content_two, tmpfile) + expect(validate_file(expected_content_two, tmpfile)).to be_truthy end end @@ -280,7 +280,7 @@ def validate_file(expected_content, tmpfile) resource = Puppet::Type::Ini_subsetting.new(common_params.merge(subsetting: 'c', value: '3')) provider = described_class.new(resource) provider.value = '3' - validate_file(expected_content_one, tmpfile) + expect(validate_file(expected_content_one, tmpfile)).to be_truthy end expected_content_two = <<-EOS @@ -353,11 +353,11 @@ def validate_file(expected_content, tmpfile) resource = Puppet::Type::Ini_subsetting.new(common_params.merge(setting: 'reports', subsetting: 'http', subsetting_separator: ',')) provider = described_class.new(resource) provider.destroy - validate_file(expected_content_one, tmpfile) + expect(validate_file(expected_content_one, tmpfile)).to be_truthy resource = Puppet::Type::Ini_subsetting.new(common_params.merge(setting: 'something', subsetting: 'else', subsetting_separator: ',')) provider = described_class.new(resource) provider.destroy - validate_file(expected_content_two, tmpfile) + expect(validate_file(expected_content_two, tmpfile)).to be_truthy end end end From 92539409a18e2a320000f2eb6efc803ff9af6311 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:39:30 +0100 Subject: [PATCH 34/53] (CONT-783) - Correct RSpec/ReceiveCounts --- .rubocop_todo.yml | 18 ++++-------------- .../puppet/provider/ini_setting/ruby_spec.rb | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 34b7ba7a..df1cb454 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,21 +99,11 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 6 -# Offense count: 12 -# Configuration parameters: AllowedPatterns. -# AllowedPatterns: ^expect_, ^assert_ -# RSpec/NoExpectationExample: +# # Offense count: 1 +# # This cop supports safe autocorrection (--autocorrect). +# RSpec/ReceiveCounts: # Exclude: -# - '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_subsetting/ruby_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ReceiveCounts: - Exclude: - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 26864c27..868ec32f 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -93,7 +93,7 @@ def self.file_path '/some/file/path' end end - expect(child_three).to receive(:file_path).exactly(2).times.and_return(tmpfile) + expect(child_three).to receive(:file_path).twice.and_return(tmpfile) expect(child_three.instances.size).to eq(7) expected_array = [ { name: 'section1/foo', value: 'foovalue' }, From dfa2604dfd1f8594632d7e43f0eb88dd51a4d56f Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:40:38 +0100 Subject: [PATCH 35/53] (CONT-783) - Correct RSpec/ReturnFromStub --- .rubocop_todo.yml | 15 +++++---------- spec/unit/puppet/util/ini_file_spec.rb | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index df1cb454..7e3f36cc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,19 +99,14 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 6 + # # Offense count: 1 # # This cop supports safe autocorrection (--autocorrect). -# RSpec/ReceiveCounts: +# # Configuration parameters: EnforcedStyle. +# # SupportedStyles: and_return, block +# RSpec/ReturnFromStub: # Exclude: -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: and_return, block -RSpec/ReturnFromStub: - Exclude: - - 'spec/unit/puppet/util/ini_file_spec.rb' +# - 'spec/unit/puppet/util/ini_file_spec.rb' # Offense count: 1 RSpec/StubbedMock: diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index 70fdf18a..4e51b090 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -8,7 +8,7 @@ subject(:ini_sub) { described_class.new('/my/ini/file/path') } before :each do - allow(File).to receive(:file?).with('/my/ini/file/path') { true } + allow(File).to receive(:file?).with('/my/ini/file/path').and_return(true) allow(described_class).to receive(:readlines).once.with('/my/ini/file/path') do sample_content end From acc2c5b96a585f10f5c7d17893bff004279f232b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:42:47 +0100 Subject: [PATCH 36/53] (CONT-783) - Correct RSpec/ReceiveCounts --- .rubocop_todo.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7e3f36cc..c6e6ef04 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,19 +99,10 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 6 - # # Offense count: 1 -# # This cop supports safe autocorrection (--autocorrect). -# # Configuration parameters: EnforcedStyle. -# # SupportedStyles: and_return, block -# RSpec/ReturnFromStub: +# RSpec/StubbedMock: # Exclude: -# - 'spec/unit/puppet/util/ini_file_spec.rb' - -# Offense count: 1 -RSpec/StubbedMock: - Exclude: - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). From a9fa05ac89bcd0ad475f81d6fcc0a0cf7df231d0 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 11:48:40 +0100 Subject: [PATCH 37/53] (CONT-783) - Correct RSpec/StubbedMock --- spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 868ec32f..41d20702 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -49,7 +49,7 @@ def self.file_path end end it 'returns [] when file is empty' do - expect(child_one).to receive(:file_path).and_return(emptyfile) + allow(child_one).to receive(:file_path).and_return(emptyfile) expect(child_one.instances).to eq([]) end From dcebca31922adc61cb05366a6b5b8a2ebc076fd7 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:15:28 +0100 Subject: [PATCH 38/53] (CONT-783) - Fix acceptance tests --- .rubocop_todo.yml | 15 +++++---------- spec/acceptance/ini_setting_spec.rb | 6 +++--- spec/acceptance/ini_subsetting_spec.rb | 8 ++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c6e6ef04..62648c9d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -100,16 +100,11 @@ RSpec/NestedGroups: Max: 6 # # Offense count: 1 -# RSpec/StubbedMock: -# Exclude: -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: . -# SupportedStyles: constant, string -RSpec/VerifiedDoubleReference: - EnforcedStyle: string +# # This cop supports unsafe autocorrection (--autocorrect-all). +# # Configuration parameters: . +# # SupportedStyles: constant, string +# RSpec/VerifiedDoubleReference: +# EnforcedStyle: string # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index f7368645..8e3206ff 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file(path) do @@ -87,7 +87,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file("#{basedir}/ini_setting.ini") do @@ -130,7 +130,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file("#{basedir}/ini_setting.ini") do diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 2fc92369..c135e8d8 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file(path) do @@ -83,7 +83,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do @@ -121,7 +121,7 @@ it 'applies the manifest twice' do run_shell("echo -e [one]\\\\nkey = alphabet betatrons > #{basedir}/ini_subsetting.ini", expect_failures: true) - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do @@ -176,7 +176,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).to be_successful + expect(idempotent_apply(pp)).not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do From 2adcfe0641ed6a9229240176a0573892e59da363 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:18:24 +0100 Subject: [PATCH 39/53] (CONT-783) - Correct RSpec/VerifiedDoubleReference --- spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 41d20702..82a95665 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -379,7 +379,7 @@ def self.file_path resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'main', value: false)) provider = described_class.new(resource) expect(provider.exists?).to be true - transaction = instance_double('transaction', persistence: true) + transaction = instance_double('transaction', persistence: true) # rubocop:disable RSpec/VerifiedDoubleReference expect(Puppet::Transaction::ResourceHarness.new(transaction).evaluate(provider.resource).out_of_sync).to be(true) validate_file(expected_content_eight, tmpfile) end From 09212161450d870db65a12837f66a62b23041d41 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:30:46 +0100 Subject: [PATCH 40/53] (CONT-783) - Correct Style/EachForSimpleLoop --- .rubocop_todo.yml | 17 +++++------------ spec/unit/puppet/util/external_iterator_spec.rb | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 62648c9d..2c58661a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,13 +99,6 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 6 -# # Offense count: 1 -# # This cop supports unsafe autocorrection (--autocorrect-all). -# # Configuration parameters: . -# # SupportedStyles: constant, string -# RSpec/VerifiedDoubleReference: -# EnforcedStyle: string - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. @@ -117,11 +110,11 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/EachForSimpleLoop: - Exclude: - - 'spec/unit/puppet/util/external_iterator_spec.rb' +# # Offense count: 1 +# # This cop supports safe autocorrection (--autocorrect). +# Style/EachForSimpleLoop: +# Exclude: +# - 'spec/unit/puppet/util/external_iterator_spec.rb' # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/unit/puppet/util/external_iterator_spec.rb b/spec/unit/puppet/util/external_iterator_spec.rb index db3487f6..99a45a2a 100644 --- a/spec/unit/puppet/util/external_iterator_spec.rb +++ b/spec/unit/puppet/util/external_iterator_spec.rb @@ -22,7 +22,7 @@ describe '#peek' do it 'returns the 0th item repeatedly' do - (0..2).each do |_i| + 3.times do |_i| expect(subject_class.peek).to eq(expected_values[0]) end end From 903cb7aba4a58365da9de24edb15d6fc2f6b1e5a Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:31:42 +0100 Subject: [PATCH 41/53] (CONT-783) - Correct Acceptance --- spec/acceptance/ini_setting_spec.rb | 6 +++--- spec/acceptance/ini_subsetting_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index 8e3206ff..0fb0ac80 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file(path) do @@ -87,7 +87,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file("#{basedir}/ini_setting.ini") do @@ -130,7 +130,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file("#{basedir}/ini_setting.ini") do diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index c135e8d8..925f77fb 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -15,7 +15,7 @@ end it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file(path) do @@ -83,7 +83,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do @@ -121,7 +121,7 @@ it 'applies the manifest twice' do run_shell("echo -e [one]\\\\nkey = alphabet betatrons > #{basedir}/ini_subsetting.ini", expect_failures: true) - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do @@ -176,7 +176,7 @@ EOS it 'applies the manifest twice' do - expect(idempotent_apply(pp)).not_to raise_error + expect { idempotent_apply(pp) }.not_to raise_error end describe file("#{basedir}/ini_subsetting.ini") do From 7b671f9794a87513096908731f690de441a99f90 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:39:06 +0100 Subject: [PATCH 42/53] (CONT-783) - Correct Style/ExpandPathArguments --- .rubocop_todo.yml | 16 +++++----------- lib/puppet/provider/ini_setting/ruby.rb | 2 +- lib/puppet/provider/ini_subsetting/ruby.rb | 4 ++-- lib/puppet/util/ini_file.rb | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2c58661a..18220f0f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,19 +110,13 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 1 +# # Offense count: 5 # # This cop supports safe autocorrection (--autocorrect). -# Style/EachForSimpleLoop: +# Style/ExpandPathArguments: # Exclude: -# - 'spec/unit/puppet/util/external_iterator_spec.rb' - -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/ExpandPathArguments: - Exclude: - - 'lib/puppet/provider/ini_setting/ruby.rb' - - 'lib/puppet/provider/ini_subsetting/ruby.rb' - - 'lib/puppet/util/ini_file.rb' +# - 'lib/puppet/provider/ini_setting/ruby.rb' +# - 'lib/puppet/provider/ini_subsetting/ruby.rb' +# - 'lib/puppet/util/ini_file.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). diff --git a/lib/puppet/provider/ini_setting/ruby.rb b/lib/puppet/provider/ini_setting/ruby.rb index 5ccb6793..c3a1f663 100644 --- a/lib/puppet/provider/ini_setting/ruby.rb +++ b/lib/puppet/provider/ini_setting/ruby.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path('../../../util/ini_file', __FILE__) +require File.expand_path('../../util/ini_file', __dir__) Puppet::Type.type(:ini_setting).provide(:ruby) do def self.instances diff --git a/lib/puppet/provider/ini_subsetting/ruby.rb b/lib/puppet/provider/ini_subsetting/ruby.rb index 0f6b7721..34a03d90 100644 --- a/lib/puppet/provider/ini_subsetting/ruby.rb +++ b/lib/puppet/provider/ini_subsetting/ruby.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require File.expand_path('../../../util/ini_file', __FILE__) -require File.expand_path('../../../util/setting_value', __FILE__) +require File.expand_path('../../util/ini_file', __dir__) +require File.expand_path('../../util/setting_value', __dir__) Puppet::Type.type(:ini_subsetting).provide(:ruby) do desc ' diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index dab1d067..cc24a2a9 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require File.expand_path('../external_iterator', __FILE__) -require File.expand_path('../ini_file/section', __FILE__) +require File.expand_path('external_iterator', __dir__) +require File.expand_path('ini_file/section', __dir__) module Puppet::Util # From f078a08e922b44dfa6e993cf01727a4923f54b25 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:41:29 +0100 Subject: [PATCH 43/53] (CONT-783) - Correct Style/FileWrite --- .rubocop_todo.yml | 18 +++++------------- .../provider/ini_setting/inheritance_spec.rb | 4 +--- .../puppet/provider/ini_setting/ruby_spec.rb | 8 ++------ .../provider/ini_subsetting/ruby_spec.rb | 4 +--- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 18220f0f..89a51f88 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,21 +110,13 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 5 +# # Offense count: 4 # # This cop supports safe autocorrection (--autocorrect). -# Style/ExpandPathArguments: +# Style/FileWrite: # Exclude: -# - 'lib/puppet/provider/ini_setting/ruby.rb' -# - 'lib/puppet/provider/ini_subsetting/ruby.rb' -# - 'lib/puppet/util/ini_file.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/FileWrite: - Exclude: - - '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/provider/ini_setting/inheritance_spec.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' # Offense count: 10 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb b/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb index f1898b0a..42e1952f 100644 --- a/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/inheritance_spec.rb @@ -16,9 +16,7 @@ def validate_file(expected_content, tmpfile) end before :each do - File.open(tmpfile, 'w') do |fh| - fh.write(orig_content) - end + File.write(tmpfile, orig_content) end context 'when calling instances' do diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 82a95665..70778fef 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -23,12 +23,8 @@ def validate_file(expected_content, tmpfile) end before :each do - File.open(tmpfile, 'w') do |fh| - fh.write(orig_content) - end - File.open(emptyfile, 'w') do |fh| - fh.write('') - end + File.write(tmpfile, orig_content) + File.write(emptyfile, '') end context 'when calling instances' do diff --git a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb index 5c547c43..45c2de35 100644 --- a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb @@ -14,9 +14,7 @@ def validate_file(expected_content, tmpfile) end before :each do - File.open(tmpfile, 'w') do |fh| - fh.write(orig_content) - end + File.write(tmpfile, orig_content) end context 'when ensuring that a subsetting is present' do From 4f4783b4013a4a40d72301a87b9afb7c3b7611e3 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:43:18 +0100 Subject: [PATCH 44/53] (CONT-783) - Correct Style/IfUnlessModifier --- .rubocop_todo.yml | 18 +++++------------- lib/puppet/type/ini_setting.rb | 12 +++--------- lib/puppet/type/ini_subsetting.rb | 8 ++------ lib/puppet/util/ini_file.rb | 20 +++++--------------- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 89a51f88..17912b8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,21 +110,13 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 4 +# # Offense count: 10 # # This cop supports safe autocorrection (--autocorrect). -# Style/FileWrite: +# Style/IfUnlessModifier: # Exclude: -# - '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' - -# Offense count: 10 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/puppet/type/ini_setting.rb' - - 'lib/puppet/type/ini_subsetting.rb' - - 'lib/puppet/util/ini_file.rb' +# - 'lib/puppet/type/ini_setting.rb' +# - 'lib/puppet/type/ini_subsetting.rb' +# - 'lib/puppet/util/ini_file.rb' # Offense count: 1 Style/MixinUsage: diff --git a/lib/puppet/type/ini_setting.rb b/lib/puppet/type/ini_setting.rb index 16635322..15d0a2ea 100644 --- a/lib/puppet/type/ini_setting.rb +++ b/lib/puppet/type/ini_setting.rb @@ -47,9 +47,7 @@ def munge_boolean_md5(value) newparam(:setting) do desc 'The name of the setting to be defined.' munge do |value| - if value.match?(%r{(^\s|\s$)}) - Puppet.warn('Settings should not have spaces in the value, we are going to strip the whitespace') - end + Puppet.warn('Settings should not have spaces in the value, we are going to strip the whitespace') if value.match?(%r{(^\s|\s$)}) value.strip end end @@ -62,9 +60,7 @@ def munge_boolean_md5(value) newparam(:path) do desc 'The ini file Puppet will ensure contains the specified setting.' validate do |value| - unless Puppet::Util.absolute_path?(value) - raise(Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }) - end + raise(Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }) unless Puppet::Util.absolute_path?(value) end end @@ -145,9 +141,7 @@ def insync?(current) end def refresh - if self[:ensure] == :absent && self[:refreshonly] - return provider.destroy - end + return provider.destroy if self[:ensure] == :absent && self[:refreshonly] # update the value in the provider, which will save the value to the ini file provider.value = self[:value] if self[:refreshonly] diff --git a/lib/puppet/type/ini_subsetting.rb b/lib/puppet/type/ini_subsetting.rb index 8ac88854..caf721c5 100644 --- a/lib/puppet/type/ini_subsetting.rb +++ b/lib/puppet/type/ini_subsetting.rb @@ -52,9 +52,7 @@ def munge_boolean_md5(value) newparam(:path) do desc 'The ini file Puppet will ensure contains the specified setting.' validate do |value| - unless Puppet::Util.absolute_path?(value) - raise(Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }) - end + raise(Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }) unless Puppet::Util.absolute_path?(value) end end newparam(:show_diff) do @@ -77,9 +75,7 @@ def munge_boolean_md5(value) defaultto('') validate do |value| - unless value.match?(%r{^["']?$}) - raise Puppet::Error, _(%q(:quote_char valid values are '', '"' and "'")) - end + raise Puppet::Error, _(%q(:quote_char valid values are '', '"' and "'")) unless value.match?(%r{^["']?$}) end end diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index cc24a2a9..7d70a812 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -72,9 +72,7 @@ def set_value(*args) separator: separator, value: value, } - unless @sections_hash.key?(section_name) - add_section(Section.new(section_name, nil, nil, nil, nil)) - end + add_section(Section.new(section_name, nil, nil, nil, nil)) unless @sections_hash.key?(section_name) section = @sections_hash[section_name] @@ -146,9 +144,7 @@ def save whitespace_buffer = [] if section.new_section? && !section.global? - if (index == 1 && !global_empty) || index > 1 - fh.puts('') - end + fh.puts('') if (index == 1 && !global_empty) || index > 1 fh.puts("#{@section_prefix}#{section.name}#{@section_suffix}") end @@ -250,9 +246,7 @@ def update_line(section, setting, value) (section.start_line..section.end_line).each do |line_num| next unless (match = @setting_regex.match(lines[line_num])) - if match[2] == setting - lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}" - end + lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}" if match[2] == setting end end @@ -260,9 +254,7 @@ def remove_line(section, setting) (section.start_line..section.end_line).each do |line_num| next unless (match = @setting_regex.match(lines[line_num])) - if match[2] == setting - lines.delete_at(line_num) - end + lines.delete_at(line_num) if match[2] == setting end end @@ -299,9 +291,7 @@ def find_commented_setting(section, setting) (section.start_line..section.end_line).each do |line_num| next unless (match = @commented_setting_regex.match(lines[line_num])) - if match[3] == setting - return { match: match, line_num: line_num } - end + return { match: match, line_num: line_num } if match[3] == setting end nil end From e44bfdb7ae37409851beab5fd0a78c93304871ab Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:44:31 +0100 Subject: [PATCH 45/53] (CONT-783) - Correct Style/MixinUsage --- .rubocop_todo.yml | 19 +++---------------- spec/spec_helper.rb | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 17912b8d..7a889684 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,24 +110,11 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 10 +# # Offense count: 1 # # This cop supports safe autocorrection (--autocorrect). -# Style/IfUnlessModifier: +# Style/NegatedIfElseCondition: # Exclude: -# - 'lib/puppet/type/ini_setting.rb' -# - 'lib/puppet/type/ini_subsetting.rb' -# - 'lib/puppet/util/ini_file.rb' - -# Offense count: 1 -Style/MixinUsage: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/NegatedIfElseCondition: - Exclude: - - 'lib/puppet/util/setting_value.rb' +# - 'lib/puppet/util/setting_value.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db7342..0463715e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,7 @@ require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -include RspecPuppetFacts +include RspecPuppetFacts # rubocop:disable Style/MixinUsage default_facts = { puppetversion: Puppet.version, From ecc278940f814f94a46bf43c5afcf4014093ecef Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:45:36 +0100 Subject: [PATCH 46/53] (CONT-783) - Correct Style/NegatedIfElseCondition --- lib/puppet/util/setting_value.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index 2c263fe9..f8eaf152 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -38,10 +38,10 @@ def unquote_setting_value(setting_value) quote_char = "'" end - unquoted = if quote_char != '' - setting_value[1, setting_value.length - 2] - else + unquoted = if quote_char == '' setting_value + else + setting_value[1, setting_value.length - 2] end [unquoted, quote_char] From 87ea6e96427dcf07c32796260479d7656f8b7e8b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:47:56 +0100 Subject: [PATCH 47/53] (CONT-783) - Correct Style/RedundantStringEscape --- .rubocop_todo.yml | 10 ++-------- spec/acceptance/ini_setting_spec.rb | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7a889684..07f15775 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,15 +112,9 @@ Style/ClassAndModuleChildren: # # Offense count: 1 # # This cop supports safe autocorrection (--autocorrect). -# Style/NegatedIfElseCondition: +# Style/RedundantStringEscape: # Exclude: -# - 'lib/puppet/util/setting_value.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantStringEscape: - Exclude: - - 'spec/acceptance/ini_setting_spec.rb' +# - 'spec/acceptance/ini_setting_spec.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/acceptance/ini_setting_spec.rb b/spec/acceptance/ini_setting_spec.rb index 0fb0ac80..3e70ccbf 100644 --- a/spec/acceptance/ini_setting_spec.rb +++ b/spec/acceptance/ini_setting_spec.rb @@ -223,7 +223,7 @@ before :each do ipp = <<-MANIFEST file { '#{basedir}/ini_setting.ini': - content => "[section1]\n valueinsection1 = 123\", + content => "[section1]\n valueinsection1 = 123", force => true, } MANIFEST From e7ce65dae7ab105788c3976b34baba3b595e3e71 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:50:19 +0100 Subject: [PATCH 48/53] (CONT-783) - Correct Style/RescueStandardError --- .rubocop_todo.yml | 16 +++++----------- spec/spec_helper.rb | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 07f15775..66cd07f5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,19 +110,13 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 1 +# Offense count: 1 # # This cop supports safe autocorrection (--autocorrect). -# Style/RedundantStringEscape: +# # Configuration parameters: EnforcedStyle. +# # SupportedStyles: implicit, explicit +# Style/RescueStandardError: # Exclude: -# - 'spec/acceptance/ini_setting_spec.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'spec/spec_helper.rb' +# - 'spec/spec_helper.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0463715e..e6f671ad 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end From 43b3dc160fe08194366301d7e660f27f361ad0cc Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:51:06 +0100 Subject: [PATCH 49/53] (CONT-783) - Correct Style/SafeNavigation --- .rubocop_todo.yml | 16 ---------------- lib/puppet/util/ini_file.rb | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 66cd07f5..19f92228 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,22 +110,6 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# Offense count: 1 -# # This cop supports safe autocorrection (--autocorrect). -# # Configuration parameters: EnforcedStyle. -# # SupportedStyles: implicit, explicit -# Style/RescueStandardError: -# Exclude: -# - 'spec/spec_helper.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'lib/puppet/util/ini_file.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 7d70a812..e0be27d1 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -16,7 +16,7 @@ def initialize(path, key_val_separator = ' = ', section_prefix = '[', section_su @section_prefix = section_prefix @section_suffix = section_suffix @indent_char = indent_char - @indent_width = indent_width ? indent_width.to_i : nil + @indent_width = indent_width&.to_i @section_regex = section_regex @setting_regex = %r{^(\s*)([^#;\s]|[^#;\s].*?[^\s#{k_v_s}])(\s*#{k_v_s}[ \t]*)(.*)\s*$} From 1173e4517b0af7f262135ca1ca7d91932567964d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:55:32 +0100 Subject: [PATCH 50/53] (CONT-783) - Correct Style/SlicingWithRange --- .rubocop_todo.yml | 10 +++++----- lib/puppet/util/setting_value.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 19f92228..be71d97e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,11 +110,11 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/SlicingWithRange: - Exclude: - - 'lib/puppet/util/setting_value.rb' +# # Offense count: 1 +# # This cop supports unsafe autocorrection (--autocorrect-all). +# Style/SlicingWithRange: +# Exclude: +# - 'lib/puppet/util/setting_value.rb' # Offense count: 7 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index f8eaf152..d170d4e3 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -69,7 +69,7 @@ def get_subsetting_value(subsetting, use_exact_match = :false) return true if use_exact_match == :true item = @subsetting_items[index] - item[(subsetting.length + @key_val_separator.length)..-1] + item[(subsetting.length + @key_val_separator.length)..] end # Add a new subsetting item to the list of existing items From 0a42aee5ed2009556c3abdb17c6f52b36f7e5f9d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:57:29 +0100 Subject: [PATCH 51/53] (CONT-783) - Correct Style/StringConcatenation --- .rubocop_todo.yml | 23 +++++++------------ lib/puppet/type/ini_setting.rb | 2 +- lib/puppet/type/ini_subsetting.rb | 2 +- spec/acceptance/ini_subsetting_spec.rb | 2 +- .../puppet/provider/ini_setting/ruby_spec.rb | 2 +- spec/unit/puppet/util/setting_value_spec.rb | 6 ++--- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index be71d97e..21f8f5b1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -109,23 +109,16 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file.rb' - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' - -# # Offense count: 1 +# # Offense count: 7 # # This cop supports unsafe autocorrection (--autocorrect-all). -# Style/SlicingWithRange: +# # Configuration parameters: Mode. +# Style/StringConcatenation: # Exclude: -# - 'lib/puppet/util/setting_value.rb' - -# Offense count: 7 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Mode. -Style/StringConcatenation: - Exclude: - - 'lib/puppet/type/ini_setting.rb' - - 'lib/puppet/type/ini_subsetting.rb' - - 'spec/acceptance/ini_subsetting_spec.rb' - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - - 'spec/unit/puppet/util/setting_value_spec.rb' +# - 'lib/puppet/type/ini_setting.rb' +# - 'lib/puppet/type/ini_subsetting.rb' +# - 'spec/acceptance/ini_subsetting_spec.rb' +# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' +# - 'spec/unit/puppet/util/setting_value_spec.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/lib/puppet/type/ini_setting.rb b/lib/puppet/type/ini_setting.rb index 15d0a2ea..53cd5c22 100644 --- a/lib/puppet/type/ini_setting.rb +++ b/lib/puppet/type/ini_setting.rb @@ -97,7 +97,7 @@ def should_to_s(newvalue) if @resource[:show_diff] == :true && Puppet[:show_diff] newvalue elsif @resource[:show_diff] == :md5 && Puppet[:show_diff] - '{md5}' + Digest::MD5.hexdigest(newvalue.to_s) + "{md5}#{Digest::MD5.hexdigest(newvalue.to_s)}" else '[redacted sensitive information]' end diff --git a/lib/puppet/type/ini_subsetting.rb b/lib/puppet/type/ini_subsetting.rb index caf721c5..38589411 100644 --- a/lib/puppet/type/ini_subsetting.rb +++ b/lib/puppet/type/ini_subsetting.rb @@ -92,7 +92,7 @@ def should_to_s(newvalue) if @resource[:show_diff] == :true && Puppet[:show_diff] newvalue elsif @resource[:show_diff] == :md5 && Puppet[:show_diff] - '{md5}' + Digest::MD5.hexdigest(newvalue.to_s) + "{md5}#{Digest::MD5.hexdigest(newvalue.to_s)}" else '[redacted sensitive information]' end diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 925f77fb..43fd178a 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -145,7 +145,7 @@ ['-Xmx', '512m'] => %r{args="-Xmx512m"}, ['-Xms', '256m'] => %r{args="-Xmx256m -Xms256m"}, }.each do |parameter, content| - context %(with '#{parameter.first}' #{(parameter.length > 1) ? '=> \'' + parameter[1] + '\'' : 'absent'} makes '#{content}') do + context %(with '#{parameter.first}' #{(parameter.length > 1) ? "=> '#{parameter[1]}'" : 'absent'} makes '#{content}') do path = File.join(basedir, 'ini_subsetting.ini') before :all do ipp = <<-MANIFEST diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 70778fef..af8be591 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -642,7 +642,7 @@ def self.file_path provider = described_class.new(resource) expect(provider.exists?).to be false provider.create - validate_file(orig_content + "\n[section]\n", tmpfile) + validate_file("#{orig_content}\n[section]\n", tmpfile) end it 'is able to handle variables of any type' do diff --git a/spec/unit/puppet/util/setting_value_spec.rb b/spec/unit/puppet/util/setting_value_spec.rb index fad0f7a3..e531f37c 100644 --- a/spec/unit/puppet/util/setting_value_spec.rb +++ b/spec/unit/puppet/util/setting_value_spec.rb @@ -27,7 +27,7 @@ it 'adds a new value #original' do setting_value.add_subsetting('-Xms', '256m') - expect(setting_value.get_value).to eq(INIT_VALUE_SPACE[0, INIT_VALUE_SPACE.length - 1] + ' -Xms256m"') + expect(setting_value.get_value).to eq("#{INIT_VALUE_SPACE[0, INIT_VALUE_SPACE.length - 1]} -Xms256m\"") end it 'changes existing value' do @@ -59,7 +59,7 @@ it 'adds a new value #original' do setting_value.add_subsetting('-Xms', '256m') - expect(setting_value.get_value).to eq(INIT_VALUE_COMMA[0, INIT_VALUE_COMMA.length - 1] + ',-Xms256m"') + expect(setting_value.get_value).to eq("#{INIT_VALUE_COMMA[0, INIT_VALUE_COMMA.length - 1]},-Xms256m\"") end it 'changes existing value' do @@ -90,7 +90,7 @@ setting_value = described_class.new(INIT_VALUE_UNQUOTED, ' ', QUOTE_CHAR) setting_value.add_subsetting('-Xms', '256m') - expect(setting_value.get_value).to eq(QUOTE_CHAR + INIT_VALUE_UNQUOTED + ' -Xms256m' + QUOTE_CHAR) + expect(setting_value.get_value).to eq("#{QUOTE_CHAR}#{INIT_VALUE_UNQUOTED} -Xms256m#{QUOTE_CHAR}") end it 'quotes the setting when changing an existing value #value' do From a714ccd08c7b633bc7cacca92a1d316164620240 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 13:59:02 +0100 Subject: [PATCH 52/53] (CONT-783) - Correct Style/SymbolProc --- .rubocop_todo.yml | 22 ++++++---------------- lib/puppet/util/setting_value.rb | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 21f8f5b1..c08a9365 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -109,24 +109,14 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file.rb' - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' -# # Offense count: 7 + +# # Offense count: 1 # # This cop supports unsafe autocorrection (--autocorrect-all). -# # Configuration parameters: Mode. -# Style/StringConcatenation: +# # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. +# # AllowedMethods: define_method +# Style/SymbolProc: # Exclude: -# - 'lib/puppet/type/ini_setting.rb' -# - 'lib/puppet/type/ini_subsetting.rb' -# - 'spec/acceptance/ini_subsetting_spec.rb' -# - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' -# - 'spec/unit/puppet/util/setting_value_spec.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. -# AllowedMethods: define_method -Style/SymbolProc: - Exclude: - - 'lib/puppet/util/setting_value.rb' +# - 'lib/puppet/util/setting_value.rb' # Offense count: 15 # This cop supports safe autocorrection (--autocorrect). diff --git a/lib/puppet/util/setting_value.rb b/lib/puppet/util/setting_value.rb index d170d4e3..fb1c4741 100644 --- a/lib/puppet/util/setting_value.rb +++ b/lib/puppet/util/setting_value.rb @@ -22,7 +22,7 @@ def initialize(setting_value, subsetting_separator = ' ', default_quote_char = ' @quote_char = quote_char unless quote_char.empty? # an item can contain escaped separator @subsetting_items = unquoted.scan(Regexp.new("(?:(?:[^\\#{@subsetting_separator}]|\\.)+)")) - @subsetting_items.map! { |item| item.strip } + @subsetting_items.map!(&:strip) end # If the setting value is quoted, the quotes are From 9c7c29f07ae6031c344154156b7ae5eb32db5418 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Apr 2023 14:00:23 +0100 Subject: [PATCH 53/53] (CONT-783) - Correct Style/TrailingCommaInHashLiteral --- .rubocop_todo.yml | 29 ------------------- .../functions/inifile/create_ini_settings.rb | 2 +- lib/puppet/util/ini_file.rb | 2 +- spec/acceptance/ini_subsetting_spec.rb | 12 ++++---- spec/spec_helper.rb | 2 +- .../puppet/provider/ini_setting/ruby_spec.rb | 2 +- .../provider/ini_subsetting/ruby_spec.rb | 10 +++---- 7 files changed, 15 insertions(+), 44 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c08a9365..478e5f8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,3 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2023-04-06 07:44:08 UTC using RuboCop version 1.48.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - # Offense count: 30 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/BooleanSymbol: @@ -109,24 +101,3 @@ Style/ClassAndModuleChildren: - 'lib/puppet/util/ini_file.rb' - 'lib/puppet/util/ini_file/section.rb' - 'lib/puppet/util/setting_value.rb' - -# # Offense count: 1 -# # This cop supports unsafe autocorrection (--autocorrect-all). -# # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. -# # AllowedMethods: define_method -# Style/SymbolProc: -# Exclude: -# - 'lib/puppet/util/setting_value.rb' - -# Offense count: 15 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/puppet/functions/inifile/create_ini_settings.rb' - - 'lib/puppet/util/ini_file.rb' - - 'spec/acceptance/ini_subsetting_spec.rb' - - 'spec/spec_helper.rb' - - 'spec/unit/puppet/provider/ini_setting/ruby_spec.rb' - - 'spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb' diff --git a/lib/puppet/functions/inifile/create_ini_settings.rb b/lib/puppet/functions/inifile/create_ini_settings.rb index 0d1109f7..3ddd2621 100644 --- a/lib/puppet/functions/inifile/create_ini_settings.rb +++ b/lib/puppet/functions/inifile/create_ini_settings.rb @@ -25,7 +25,7 @@ def default_impl(settings, defaults = {}) res["#{path} [#{section}] #{setting}"] = { 'ensure' => 'present', 'section' => section, - 'setting' => setting, + 'setting' => setting }.merge(if value.is_a?(Hash) value else diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index e0be27d1..1636479f 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -70,7 +70,7 @@ def set_value(*args) complete_setting = { setting: setting, separator: separator, - value: value, + value: value } add_section(Section.new(section_name, nil, nil, nil, nil)) unless @sections_hash.key?(section_name) diff --git a/spec/acceptance/ini_subsetting_spec.rb b/spec/acceptance/ini_subsetting_spec.rb index 43fd178a..e1548f57 100644 --- a/spec/acceptance/ini_subsetting_spec.rb +++ b/spec/acceptance/ini_subsetting_spec.rb @@ -143,7 +143,7 @@ ['-Xmx'] => %r{args=""}, ['-Xmx', '256m'] => %r{args=-Xmx256m}, ['-Xmx', '512m'] => %r{args="-Xmx512m"}, - ['-Xms', '256m'] => %r{args="-Xmx256m -Xms256m"}, + ['-Xms', '256m'] => %r{args="-Xmx256m -Xms256m"} }.each do |parameter, content| context %(with '#{parameter.first}' #{(parameter.length > 1) ? "=> '#{parameter[1]}'" : 'absent'} makes '#{content}') do path = File.join(basedir, 'ini_subsetting.ini') @@ -228,26 +228,26 @@ [ { insert_type: :start, - content: %r{d a b c}, + content: %r{d a b c} }, { insert_type: :end, - content: %r{a b c d}, + content: %r{a b c d} }, { insert_type: :before, insert_value: 'c', - content: %r{a b d c}, + content: %r{a b d c} }, { insert_type: :after, insert_value: 'a', - content: %r{a d b c}, + content: %r{a d b c} }, { insert_type: :index, insert_value: 2, - content: %r{a b d c}, + content: %r{a b d c} }, ].each do |params| context "with '#{params[:insert_type]}' makes '#{params[:content]}'" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e6f671ad..1a8b68bd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index af8be591..3015079f 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -14,7 +14,7 @@ { title: 'ini_setting_ensure_present_test', path: tmpfile, - section: 'section2', + section: 'section2' } end diff --git a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb index 45c2de35..8596397e 100644 --- a/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb @@ -24,7 +24,7 @@ def validate_file(expected_content, tmpfile) path: tmpfile, section: '', key_val_separator: '=', - setting: 'JAVA_ARGS', + setting: 'JAVA_ARGS' } end @@ -151,7 +151,7 @@ def validate_file(expected_content, tmpfile) title: 'ini_setting_ensure_present_test', path: tmpfile, section: 'main', - setting: 'reports', + setting: 'reports' } end @@ -211,7 +211,7 @@ def validate_file(expected_content, tmpfile) path: tmpfile, section: 'main', setting: 'reports', - use_exact_match: true, + use_exact_match: true } end @@ -257,7 +257,7 @@ def validate_file(expected_content, tmpfile) section: 'main', setting: 'reports', subsetting_separator: ',', - subsetting_key_val_separator: ':', + subsetting_key_val_separator: ':' } end @@ -328,7 +328,7 @@ def validate_file(expected_content, tmpfile) title: 'ini_setting_delete_if_empty_test', path: tmpfile, section: 'main', - delete_if_empty: true, + delete_if_empty: true } end