Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubocop: fix whitespace and newline warnings #141

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/puppet-syntax/hiera.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module PuppetSyntax
class Hiera

def check_hiera_key(key)
if key.is_a? Symbol
if key.to_s.start_with?(':')
Expand Down Expand Up @@ -33,7 +32,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
Expand All @@ -56,13 +55,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
Expand All @@ -81,7 +80,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
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-syntax/manifests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-syntax/tasks/puppet-syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions puppet-syntax.gemspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
1 change: 0 additions & 1 deletion spec/puppet-syntax/hiera_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@
res = subject.check(files)
expect(res).to be_empty
end

end
end
1 change: 0 additions & 1 deletion spec/puppet-syntax/manifests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

expect(output).to eq([])
expect(has_errors).to eq(false)

end

it 'should read more than one valid file' do
Expand Down