From 20730025cd6bd57182b2854ffad2ea4342f2f926 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Mon, 20 Mar 2023 10:39:27 +0100 Subject: [PATCH 1/2] rubocop: fix space violations --- lib/puppet-syntax/hiera.rb | 8 ++++---- lib/puppet-syntax/tasks/puppet-syntax.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/puppet-syntax/hiera.rb b/lib/puppet-syntax/hiera.rb index 6c9fb8b..c283904 100644 --- a/lib/puppet-syntax/hiera.rb +++ b/lib/puppet-syntax/hiera.rb @@ -33,7 +33,7 @@ def check_eyaml_data(name, val) break if error end elsif val.is_a? Hash - val.each do |k,v| + val.each do |k, v| error = check_eyaml_data("#{name}['#{k}']", v) break if error end @@ -56,13 +56,13 @@ def check_eyaml_blob(val) method = 'PKCS7' end - return "has unknown eyaml method #{method}" unless ['PKCS7','GPG','GKMS','KMS'].include? method + return "has unknown eyaml method #{method}" unless ['PKCS7', 'GPG', 'GKMS', 'KMS'].include? method return "has unpadded or truncated base64 data" unless base64.length % 4 == 0 # Base64#decode64 will silently ignore characters outside the alphabet, # so we check resulting length of binary data instead pad_length = base64.gsub(/[^=]/, '').length - if Base64.decode64(base64).length != base64.length * 3/4 - pad_length + if Base64.decode64(base64).length != base64.length * 3 / 4 - pad_length return "has corrupt base64 data" end end @@ -81,7 +81,7 @@ def check(filelist) next end if yamldata - yamldata.each do |k,v| + yamldata.each do |k, v| if PuppetSyntax.check_hiera_keys key_msg = check_hiera_key(k) errors << "WARNING: #{hiera_file}: Key :#{k}: #{key_msg}" if key_msg diff --git a/lib/puppet-syntax/tasks/puppet-syntax.rb b/lib/puppet-syntax/tasks/puppet-syntax.rb index cdd16ee..2f5f45f 100644 --- a/lib/puppet-syntax/tasks/puppet-syntax.rb +++ b/lib/puppet-syntax/tasks/puppet-syntax.rb @@ -41,7 +41,7 @@ def initialize(*args) c = PuppetSyntax::Manifests.new output, has_errors = c.check(filelist_manifests) $stdout.puts "#{output.join("\n")}\n" unless output.empty? - exit 1 if has_errors || ( output.any? && PuppetSyntax.fail_on_deprecation_notices ) + exit 1 if has_errors || (output.any? && PuppetSyntax.fail_on_deprecation_notices) end desc 'Syntax check Puppet templates' From a628a7f462f86e2f228a8c1a208e7e3aa3d7cf93 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Mon, 20 Mar 2023 10:40:29 +0100 Subject: [PATCH 2/2] rubocop: fix newline warnings --- lib/puppet-syntax/hiera.rb | 1 - lib/puppet-syntax/manifests.rb | 2 ++ puppet-syntax.gemspec | 1 + spec/puppet-syntax/hiera_spec.rb | 1 - spec/puppet-syntax/manifests_spec.rb | 1 - 5 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet-syntax/hiera.rb b/lib/puppet-syntax/hiera.rb index c283904..d9559f6 100644 --- a/lib/puppet-syntax/hiera.rb +++ b/lib/puppet-syntax/hiera.rb @@ -3,7 +3,6 @@ module PuppetSyntax class Hiera - def check_hiera_key(key) if key.is_a? Symbol if key.to_s.start_with?(':') diff --git a/lib/puppet-syntax/manifests.rb b/lib/puppet-syntax/manifests.rb index 2dcf3e6..162d9a7 100644 --- a/lib/puppet-syntax/manifests.rb +++ b/lib/puppet-syntax/manifests.rb @@ -2,6 +2,7 @@ module PuppetSyntax class Manifests def check(filelist) raise "Expected an array of files" unless filelist.is_a?(Array) + require 'puppet' require 'puppet/version' require 'puppet/face' @@ -60,6 +61,7 @@ def check(filelist) end private + def validate_manifest(file) Puppet[:tasks] = true if Puppet::Util::Package.versioncmp(Puppet.version, '5.4.0') >= 0 and file.match(/.*plans\/.*\.pp$/) Puppet::Face[:parser, :current].validate(file) diff --git a/puppet-syntax.gemspec b/puppet-syntax.gemspec index 760f2e6..08118af 100644 --- a/puppet-syntax.gemspec +++ b/puppet-syntax.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'puppet-syntax/version' diff --git a/spec/puppet-syntax/hiera_spec.rb b/spec/puppet-syntax/hiera_spec.rb index a4cd299..bbecdfb 100644 --- a/spec/puppet-syntax/hiera_spec.rb +++ b/spec/puppet-syntax/hiera_spec.rb @@ -66,6 +66,5 @@ res = subject.check(files) expect(res).to be_empty end - end end diff --git a/spec/puppet-syntax/manifests_spec.rb b/spec/puppet-syntax/manifests_spec.rb index 0982866..693d12c 100644 --- a/spec/puppet-syntax/manifests_spec.rb +++ b/spec/puppet-syntax/manifests_spec.rb @@ -58,7 +58,6 @@ expect(output).to eq([]) expect(has_errors).to eq(false) - end it 'should read more than one valid file' do