From 1868e60d6221efc6fe1143cc8cd0b3085fd58727 Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Mon, 7 Apr 2025 16:09:00 +0100 Subject: [PATCH 1/4] (CAT-2281) Remove puppet 7 infrastructure Puppet 7 is EOL. Therefore, we can remove the test infrastructure for it. This commit aims to clear up any testing/config infrastructure related to Puppet 7 and, by extension, Ruby 2.7. --- .rubocop.yml | 2 +- puppet-lint-check_unsafe_interpolations.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7fd2383..a1e515f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ require: - rubocop-rspec AllCops: DisplayCopNames: true - TargetRubyVersion: '2.7' + TargetRubyVersion: '3.1' SuggestExtensions: false Include: - "**/*.rb" diff --git a/puppet-lint-check_unsafe_interpolations.gemspec b/puppet-lint-check_unsafe_interpolations.gemspec index 708b180..28c7947 100644 --- a/puppet-lint-check_unsafe_interpolations.gemspec +++ b/puppet-lint-check_unsafe_interpolations.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| EOF spec.homepage = 'https://github.com/puppetlabs/puppet-lint-check_unsafe_interpolations' spec.license = 'Apache-2.0' - spec.required_ruby_version = Gem::Requirement.new(">= 2.5".freeze) + spec.required_ruby_version = Gem::Requirement.new(">= 3.1".freeze) spec.add_dependency 'puppet-lint', '~> 4.0' end From 620f54d7b9977642186dd86a78ecbcd79e30f5f5 Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Wed, 9 Apr 2025 16:16:14 +0100 Subject: [PATCH 2/4] rubocop update --- .rubocop.yml | 3 ++ .rubocop_todo.yml | 33 +++++++++++++++++++ Gemfile | 2 +- .../plugins/check_unsafe_interpolations.rb | 8 ++--- ...t-lint-check_unsafe_interpolations.gemspec | 5 +-- 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index a1e515f..e9560e4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,11 @@ --- +inherit_from: .rubocop_todo.yml + require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true TargetRubyVersion: '3.1' SuggestExtensions: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..cc727a9 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,33 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2025-04-09 15:15:52 UTC using RuboCop version 1.70.0. +# 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: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/OrAssignmentToConstant: + Exclude: + - 'lib/puppet-lint/plugins/version.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/ArrayIntersect: + Exclude: + - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/ConcatArrayLiterals: + Exclude: + - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' diff --git a/Gemfile b/Gemfile index 1e1843d..e65a9a1 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ group :coverage, optional: ENV['COVERAGE']!='yes' do end group :rubocop do - gem 'rubocop', '~> 1.6.1', require: false + gem 'rubocop', '~> 1.70.0', require: false gem 'rubocop-performance', '~> 1.9.1', require: false gem 'rubocop-rspec', '~> 2.0.1', require: false end diff --git a/lib/puppet-lint/plugins/check_unsafe_interpolations.rb b/lib/puppet-lint/plugins/check_unsafe_interpolations.rb index f71ad2c..8356737 100644 --- a/lib/puppet-lint/plugins/check_unsafe_interpolations.rb +++ b/lib/puppet-lint/plugins/check_unsafe_interpolations.rb @@ -1,7 +1,7 @@ PuppetLint.new_check(:check_unsafe_interpolations) do - COMMANDS = Array['command', 'onlyif', 'unless'] - INTERPOLATED_STRINGS = Array[:DQPRE, :DQMID] - USELESS_CHARS = Array[:WHITESPACE, :COMMA] + COMMANDS = ['command', 'onlyif', 'unless'] + INTERPOLATED_STRINGS = [:DQPRE, :DQMID] + USELESS_CHARS = [:WHITESPACE, :COMMA] def check # Gather any exec commands' resources into an array exec_resources = resource_indexes.map { |resource| @@ -33,7 +33,7 @@ def check_unsafe_title(title) def check_unsafe_interpolations(command_resources) command_resources[:tokens].each do |token| # Skip iteration if token isn't a command of type :NAME - next unless COMMANDS.include?(token.value) && (token.type == :NAME || token.type == :UNLESS) + next unless COMMANDS.include?(token.value) && [:NAME, :UNLESS].include?(token.type) # Don't check the command if it is parameterised next if parameterised?(token) diff --git a/puppet-lint-check_unsafe_interpolations.gemspec b/puppet-lint-check_unsafe_interpolations.gemspec index 28c7947..860eaa9 100644 --- a/puppet-lint-check_unsafe_interpolations.gemspec +++ b/puppet-lint-check_unsafe_interpolations.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppet-lint/plugins/version' Gem::Specification.new do |spec| - spec.name = "puppet-lint-check_unsafe_interpolations" + spec.name = 'puppet-lint-check_unsafe_interpolations' spec.version = CheckUnsafeInterpolations::VERSION spec.authors = ['Puppet, Inc.'] spec.files = Dir[ @@ -20,7 +20,8 @@ Gem::Specification.new do |spec| EOF spec.homepage = 'https://github.com/puppetlabs/puppet-lint-check_unsafe_interpolations' spec.license = 'Apache-2.0' - spec.required_ruby_version = Gem::Requirement.new(">= 3.1".freeze) + spec.required_ruby_version = Gem::Requirement.new('>= 3.1') spec.add_dependency 'puppet-lint', '~> 4.0' + spec.metadata['rubygems_mfa_required'] = 'true' end From d123611cc03e8dadcc7fe6dfebb610d29aff704d Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Wed, 9 Apr 2025 16:20:56 +0100 Subject: [PATCH 3/4] Downgrading rubocop to non-erroring version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e65a9a1..1a5f059 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ group :coverage, optional: ENV['COVERAGE']!='yes' do end group :rubocop do - gem 'rubocop', '~> 1.70.0', require: false + gem 'rubocop', '~> 1.60.0', require: false gem 'rubocop-performance', '~> 1.9.1', require: false gem 'rubocop-rspec', '~> 2.0.1', require: false end From 04607df7f8d9b71fe954d6b1bacf0b2cd5d96ef7 Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Thu, 10 Apr 2025 14:50:57 +0100 Subject: [PATCH 4/4] Unsafe autocorrections --- .rubocop.yml | 2 -- .rubocop_todo.yml | 33 ------------------- .../plugins/check_unsafe_interpolations.rb | 10 +++--- lib/puppet-lint/plugins/version.rb | 2 +- 4 files changed, 6 insertions(+), 41 deletions(-) delete mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index e9560e4..7396f12 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,4 @@ --- -inherit_from: .rubocop_todo.yml - require: - rubocop-performance - rubocop-rspec diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index cc727a9..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2025-04-09 15:15:52 UTC using RuboCop version 1.70.0. -# 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: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/OrAssignmentToConstant: - Exclude: - - 'lib/puppet-lint/plugins/version.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/ArrayIntersect: - Exclude: - - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/ConcatArrayLiterals: - Exclude: - - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' - -# Offense count: 3 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'lib/puppet-lint/plugins/check_unsafe_interpolations.rb' diff --git a/lib/puppet-lint/plugins/check_unsafe_interpolations.rb b/lib/puppet-lint/plugins/check_unsafe_interpolations.rb index 8356737..72bbfc1 100644 --- a/lib/puppet-lint/plugins/check_unsafe_interpolations.rb +++ b/lib/puppet-lint/plugins/check_unsafe_interpolations.rb @@ -1,12 +1,12 @@ PuppetLint.new_check(:check_unsafe_interpolations) do - COMMANDS = ['command', 'onlyif', 'unless'] - INTERPOLATED_STRINGS = [:DQPRE, :DQMID] - USELESS_CHARS = [:WHITESPACE, :COMMA] + COMMANDS = ['command', 'onlyif', 'unless'].freeze + INTERPOLATED_STRINGS = [:DQPRE, :DQMID].freeze + USELESS_CHARS = [:WHITESPACE, :COMMA].freeze def check # Gather any exec commands' resources into an array exec_resources = resource_indexes.map { |resource| resource_parameters = resource[:param_tokens].map(&:value) - resource if resource[:type].value == 'exec' && !(COMMANDS & resource_parameters).empty? + resource if resource[:type].value == 'exec' && !COMMANDS.intersect?(resource_parameters).nil? }.compact # Iterate over title tokens and raise a warning if any are variables @@ -106,7 +106,7 @@ def get_exec_titles result << tokens[title_start_idx..title_end_idx] # Title is in single quotes else - tokens_array.concat([tokens[token_idx].next_code_token.next_code_token]) + tokens_array.push(tokens[token_idx].next_code_token.next_code_token) result << tokens_array end diff --git a/lib/puppet-lint/plugins/version.rb b/lib/puppet-lint/plugins/version.rb index 877fccb..09a5dfb 100644 --- a/lib/puppet-lint/plugins/version.rb +++ b/lib/puppet-lint/plugins/version.rb @@ -1,4 +1,4 @@ # version of this gem class CheckUnsafeInterpolations - VERSION ||= '0.0.5'.freeze + VERSION = '0.0.5'.freeze end