Skip to content

Commit

Permalink
Merge pull request #81 from bastelfreak/cleanup
Browse files Browse the repository at this point in the history
rubocop: various small cleanups part 1
  • Loading branch information
genebean authored Jun 10, 2022
2 parents 972658b + 55077cf commit 8264d9a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 46 deletions.
40 changes: 1 addition & 39 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-06-10 12:36:35 UTC using RuboCop version 1.22.3.
# on 2022-06-10 12:48:42 UTC using RuboCop version 1.22.3.
# 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
Expand Down Expand Up @@ -264,48 +264,10 @@ Style/RegexpLiteral:
- 'lib/puppet/face/catalog/pull.rb'
- 'spec/unit/puppet/catalog_diff/comparer_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Methods.
# Methods: {"reduce"=>["acc", "elem"]}, {"inject"=>["acc", "elem"]}
Style/SingleLineBlockParams:
Exclude:
- 'lib/puppet/face/catalog/diff.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/puppet/catalog-diff/formater.rb'
- 'spec/unit/puppet/catalog_diff/comparer_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'spec/unit/puppet/catalog_diff/comparer_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Exclude:
- 'lib/puppet/catalog-diff/searchfacts.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: brackets
2 changes: 1 addition & 1 deletion lib/puppet/catalog-diff/comparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def filter_parameters!(params, blacklist)
# sort require/before/notify/subscribe before comparison
def sort_dependencies!(params)
params.each do |x|
next unless [:require, :before, :notify, :subscribe].include?(x[0])
next unless %i[require before notify subscribe].include?(x[0])

if x[1].class == Array
x[1].sort!
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/catalog-diff/searchfacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def find_nodes(options = {})
# Pull all nodes from PuppetDB
old_env = options[:old_server].split('/')[1]
Puppet.debug('Using PuppetDB to find active nodes')
filter_env = (options[:filter_old_env]) ? old_env : nil
filter_env = options[:filter_old_env] ? old_env : nil
active_nodes = find_nodes_puppetdb(filter_env, options[:puppetdb])
if active_nodes.empty?
raise 'No active nodes were returned from your fact search'
Expand All @@ -23,7 +23,7 @@ def find_nodes(options = {})
end

def build_query(env, version)
base_query = ['and', ['=', ['node', 'active'], true]]
base_query = ['and', ['=', %w[node active], true]]
query_field_catalog_environment = Puppet::Util::Package.versioncmp(version, '3') >= 0 ? 'catalog_environment' : 'catalog-environment'
base_query.concat([['=', query_field_catalog_environment, env]]) if env
real_facts = @facts.reject { |_k, v| v.nil? }
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/face/catalog/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
Hash[node => summary[:node_differences]]
end
total_nodes = nodes.size
nodes[:total_percentage] = (nodes.map { |_node, summary| summary.is_a?(Hash) && summary[:node_percentage] || nil }.compact.reduce { |sum, x| sum.to_f + x } / total_nodes)
nodes[:total_percentage] = (nodes.map { |_node, summary| summary.is_a?(Hash) && summary[:node_percentage] || nil }.compact.reduce { |acc, elem| acc.to_f + elem } / total_nodes)
nodes[:with_changes] = with_changes.size
nodes[:most_changed] = most_changed.reverse.take((options.key?(:changed_depth) && options[:changed_depth].to_i || 10))
nodes[:most_differences] = most_differences.reverse.take((options.key?(:changed_depth) && options[:changed_depth].to_i || 10))
Expand All @@ -232,7 +232,7 @@

format = Puppet::CatalogDiff::Formater.new
nodes.map do |node, summary|
next if [:total_percentage, :total_nodes, :most_changed, :with_changes, :most_differences, :pull_output, :date, :all_changed_nodes].include?(node)
next if %i[total_percentage total_nodes most_changed with_changes most_differences pull_output date all_changed_nodes].include?(node)

format.node_summary_header(node, summary, :node_percentage) + summary.map do |header, value|
next if value.nil?
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/catalog_diff/comparer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

describe 'extract_titles' do
it 'returns resource ids' do
extract_titles(resources1).should eq(['foo', 'bar'])
extract_titles(resources1).should eq(%w[foo bar])
end
end

Expand Down Expand Up @@ -93,7 +93,7 @@

ruby_default_replacement_string_for_invalid_characters = '�'
expect(diffs[:string_diffs]['file.foo'][3]).to \
eq("-\t content => \"" + ruby_default_replacement_string_for_invalid_characters + "\"")
eq("-\t content => \"" + ruby_default_replacement_string_for_invalid_characters + '"')
end

it 'returns a diff without path parameter' do
Expand Down

0 comments on commit 8264d9a

Please sign in to comment.