Skip to content

Commit

Permalink
unsave rubocop autofixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markuszilch committed Aug 23, 2023
1 parent d52c50b commit 1999003
Show file tree
Hide file tree
Showing 32 changed files with 201 additions and 105 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source ENV['GEM_SOURCE'] || 'https://rubygems.org'

gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet-ghostbuster/puppetdb.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppetdb'
require 'puppet'
require 'puppet/util/puppetdb'
Expand All @@ -8,7 +10,7 @@ class PuppetDB

def self.client
@@client ||= ::PuppetDB::Client.new({

Check failure on line 12 in lib/puppet-ghostbuster/puppetdb.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/ClassVars: Replace class var @@client with a class instance var. (https://rubystyle.guide#no-class-vars)
server: "#{ENV['PUPPETDB_URL'] || Puppet::Util::Puppetdb.config.server_urls[0]}",
server: (ENV['PUPPETDB_URL'] || Puppet::Util::Puppetdb.config.server_urls[0]).to_s,

Check failure on line 13 in lib/puppet-ghostbuster/puppetdb.rb

View workflow job for this annotation

GitHub Actions / rubocop

Layout/LineLength: Line is too long. [127/120] (https://rubystyle.guide#max-line-length)
pem: {
'key' => ENV['PUPPETDB_KEY_FILE'] || Puppet[:hostprivkey],
'cert' => ENV['PUPPETDB_CERT_FILE'] || Puppet[:hostcert],
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet-ghostbuster/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PuppetGhostbuster
VERSION = '0.9.0'
end
24 changes: 14 additions & 10 deletions lib/puppet-lint/plugins/check_ghostbuster_classes.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

require 'puppet-ghostbuster/puppetdb'

class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
module PuppetLint
class Checks

Check failure on line 6 in lib/puppet-lint/plugins/check_ghostbuster_classes.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/Documentation: Missing top-level documentation comment for `class PuppetLint::Checks`.
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand Down
24 changes: 14 additions & 10 deletions lib/puppet-lint/plugins/check_ghostbuster_defines.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

require 'puppet-ghostbuster/puppetdb'

class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
module PuppetLint
class Checks

Check failure on line 6 in lib/puppet-lint/plugins/check_ghostbuster_defines.rb

View workflow job for this annotation

GitHub Actions / rubocop

Style/Documentation: Missing top-level documentation comment for `class PuppetLint::Checks`.
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand Down
30 changes: 17 additions & 13 deletions lib/puppet-lint/plugins/check_ghostbuster_facts.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
# frozen_string_literal: true

module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand All @@ -31,13 +35,13 @@ def check
found = false

manifests.each do |manifest|
found = true if File.readlines(manifest).grep(/\$\{?::#{fact_name}\}?/).size > 0
found = true if File.readlines(manifest).grep(/@#{fact_name}/).size > 0
found = true if File.readlines(manifest).grep(/\$\{?::#{fact_name}\}?/).size.positive?
found = true if File.readlines(manifest).grep(/@#{fact_name}/).size.positive?
break if found
end

templates.each do |template|
found = true if File.readlines(template).grep(/@#{fact_name}/).size > 0
found = true if File.readlines(template).grep(/@#{fact_name}/).size.positive?
break if found
end

Expand Down
32 changes: 18 additions & 14 deletions lib/puppet-lint/plugins/check_ghostbuster_files.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

require 'puppet-ghostbuster/puppetdb'

class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand All @@ -27,7 +31,7 @@ def check

module_name, file_name = m.captures
query = "resources[title] { parameters.source = 'puppet:///modules/#{module_name}/#{file_name}' and nodes { deactivated is null } }"
return if puppetdb.client.request('', query).data.size > 0
return if puppetdb.client.request('', query).data.size.positive?

dir_name = File.dirname(file_name)
while dir_name != '.'
Expand All @@ -36,15 +40,15 @@ def check
or parameters.source = 'puppet:///modules/#{module_name}/#{dir_name}/')
and parameters.recurse = true
and nodes { deactivated is null } }"
return if puppetdb.client.request('', query).data.size > 0
return if puppetdb.client.request('', query).data.size.positive?

dir_name = File.dirname(dir_name)
end

manifests.each do |manifest|
return if File.readlines(manifest).grep(%r{["']#{module_name}/#{file_name}["']}).size > 0
return if File.readlines(manifest).grep(%r{["']#{module_name}/#{file_name}["']}).size.positive?

if (match = manifest.match(%r{.*/([^/]+)/manifests/.+$})) && (match.captures[0] == module_name) && (File.readlines(manifest).grep(%r{["']\$\{module_name\}/#{file_name}["']}).size > 0)
if (match = manifest.match(%r{.*/([^/]+)/manifests/.+$})) && (match.captures[0] == module_name) && File.readlines(manifest).grep(%r{["']\$\{module_name\}/#{file_name}["']}).size.positive?
return
end
end
Expand Down
30 changes: 17 additions & 13 deletions lib/puppet-lint/plugins/check_ghostbuster_functions.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
# frozen_string_literal: true

module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand All @@ -28,12 +32,12 @@ def check
function_name = m.captures[0]

manifests.each do |manifest|
return if File.readlines(manifest).grep(/#{function_name}\(/).size > 0
return if File.readlines(manifest).grep(/#{function_name}\(/).size.positive?
end

templates.each do |template|
return if File.readlines(template).grep(/scope.function_#{function_name}\(/).size > 0
return if File.readlines(template).grep(/Puppet::Parser::Functions.function\(:#{function_name}/).size > 0
return if File.readlines(template).grep(/scope.function_#{function_name}\(/).size.positive?
return if File.readlines(template).grep(/Puppet::Parser::Functions.function\(:#{function_name}/).size.positive?
end

notify :warning, {
Expand Down
28 changes: 16 additions & 12 deletions lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
# frozen_string_literal: true

module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand All @@ -34,7 +38,7 @@ def check
regexprs.each do |k, v|
m = _path.match(Regexp.new("#{k}.yaml"))
next if m.nil?
return if m.captures.size == 0
return if m.captures.empty?

if m.captures.size > 1
i = 0
Expand Down Expand Up @@ -62,7 +66,7 @@ def check

query = [:and, query, [:'=', 'deactivated', nil]]

return if puppetdb.client.request('nodes', query).data.size > 0
return if puppetdb.client.request('nodes', query).data.size.positive?
end

notify :warning, {
Expand Down
32 changes: 18 additions & 14 deletions lib/puppet-lint/plugins/check_ghostbuster_templates.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
# frozen_string_literal: true

module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand All @@ -28,17 +32,17 @@ def check
module_name, template_name = m.captures

manifests.each do |manifest|
return if File.readlines(manifest).grep(%r{["']#{module_name}/#{template_name}["']}).size > 0
return if File.readlines(manifest).grep(%r{["']#{module_name}/#{template_name}["']}).size.positive?

next unless match = manifest.match(%r{.*/([^/]+)/manifests/.+$})
next unless (match = manifest.match(%r{.*/([^/]+)/manifests/.+$}))

if match.captures[0] == module_name && (File.readlines(manifest).grep(%r{["']\$\{module_name\}/#{template_name}["']}).size > 0)
if match.captures[0] == module_name && File.readlines(manifest).grep(%r{["']\$\{module_name\}/#{template_name}["']}).size.positive?
return
end
end

templates.each do |template|
if File.readlines(template).grep(%r{scope.function_template\(\['#{module_name}/#{template_name}'\]\)}).size > 0
if File.readlines(template).grep(%r{scope.function_template\(\['#{module_name}/#{template_name}'\]\)}).size.positive?
return
end
end
Expand Down
24 changes: 14 additions & 10 deletions lib/puppet-lint/plugins/check_ghostbuster_types.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

require 'puppet-ghostbuster/puppetdb'

class PuppetLint::Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
module PuppetLint
class Checks
def load_data(path, content)
lexer = PuppetLint::Lexer.new
PuppetLint::Data.path = path
begin
PuppetLint::Data.manifest_lines = content.split("\n", -1)
PuppetLint::Data.tokens = lexer.tokenise(content)
PuppetLint::Data.parse_control_comments
rescue StandardError
PuppetLint::Data.tokens = []
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions puppet-ghostbuster.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'puppet-ghostbuster/version'

Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/modules/foo/lib/facter/bar.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fact used in manifest
Facter.add('bar') do
setcode do
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/modules/foo/lib/facter/baz.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fact used in template
Facter.add('baz') do
setcode do
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/modules/foo/lib/facter/foo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fact used in a string
Facter.add('foo') do
setcode do
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/modules/foo/lib/facter/multi.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Unused facts
Facter.add('multi1') do
setcode do
Expand Down
Loading

0 comments on commit 1999003

Please sign in to comment.