diff --git a/.rubocop.yml b/.rubocop.yml index 7fd2383..7396f12 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,8 +3,9 @@ require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.7' + TargetRubyVersion: '3.1' SuggestExtensions: false Include: - "**/*.rb" diff --git a/Gemfile b/Gemfile index 1e1843d..1a5f059 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.60.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..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 = Array['command', 'onlyif', 'unless'] - INTERPOLATED_STRINGS = Array[:DQPRE, :DQMID] - USELESS_CHARS = Array[: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 @@ -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) @@ -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 diff --git a/puppet-lint-check_unsafe_interpolations.gemspec b/puppet-lint-check_unsafe_interpolations.gemspec index 708b180..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(">= 2.5".freeze) + spec.required_ruby_version = Gem::Requirement.new('>= 3.1') spec.add_dependency 'puppet-lint', '~> 4.0' + spec.metadata['rubygems_mfa_required'] = 'true' end