From 7897c70a52085099a9bf29c23f20a80a72c578fe Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Wed, 14 Sep 2016 13:14:53 -0700 Subject: [PATCH] (maint) RuboCop fixes. This commit fixes a few RuboCop related failures. --- lib/puppet-strings/json.rb | 11 +++++------ lib/puppet-strings/yard.rb | 13 +++++++------ lib/puppet-strings/yard/code_objects/type.rb | 6 +++--- .../yard/handlers/ruby/provider_handler.rb | 7 ++++--- lib/puppet/face/strings.rb | 2 +- spec/spec_helper_acceptance.rb | 1 - 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/puppet-strings/json.rb b/lib/puppet-strings/json.rb index 32b8d52..d6d2e42 100644 --- a/lib/puppet-strings/json.rb +++ b/lib/puppet-strings/json.rb @@ -2,17 +2,16 @@ require 'json' # The module for JSON related functionality. module PuppetStrings::Json - # Renders the current YARD registry as JSON to the given file (or STDOUT if nil). # @param [String] file The path to the output file to render the registry to. If nil, output will be to STDOUT. # @return [void] def self.render(file = nil) document = { - puppet_classes: YARD::Registry.all(:puppet_class).sort_by! { |c| c.name }.map! { |c| c.to_hash }, - defined_types: YARD::Registry.all(:puppet_defined_type).sort_by! { |dt| dt.name }.map! { |dt| dt.to_hash }, - resource_types: YARD::Registry.all(:puppet_type).sort_by! { |t| t.name }.map! { |t| t.to_hash }, - providers: YARD::Registry.all(:puppet_provider).sort_by! { |p| p.name }.map! { |p| p.to_hash }, - puppet_functions: YARD::Registry.all(:puppet_function).sort_by! { |f| f.name }.map! { |f| f.to_hash }, + puppet_classes: YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash), + defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash), + resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash), + providers: YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash), + puppet_functions: YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash), # TODO: Need Ruby documentation? } diff --git a/lib/puppet-strings/yard.rb b/lib/puppet-strings/yard.rb index 7e61cde..726b062 100644 --- a/lib/puppet-strings/yard.rb +++ b/lib/puppet-strings/yard.rb @@ -43,7 +43,7 @@ class YARD::CLI::Yardoc :puppet_defined_type, :puppet_type, :puppet_provider, - :puppet_function, + :puppet_function ) end end @@ -76,11 +76,12 @@ class YARD::CLI::Stats # Monkey patch output to accommodate our larger header widths @total += data if data.is_a?(Integer) && undoc @undocumented += undoc if undoc.is_a?(Integer) - if undoc - data = ('%5s (% 5d undocumented)' % [data, undoc]) - else - data = '%5s' % data - end + data = + if undoc + ('%5s (% 5d undocumented)' % [data, undoc]) + else + '%5s' % data + end log.puts('%-21s %s' % [name + ':', data]) end diff --git a/lib/puppet-strings/yard/code_objects/type.rb b/lib/puppet-strings/yard/code_objects/type.rb index 8e3185e..384ccf8 100644 --- a/lib/puppet-strings/yard/code_objects/type.rb +++ b/lib/puppet-strings/yard/code_objects/type.rb @@ -138,9 +138,9 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects: hash[:file] = file hash[:line] = line hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring) - hash[:properties] = properties.map { |p| p.to_hash } if properties && !properties.empty? - hash[:parameters] = parameters.map { |p| p.to_hash } if parameters && !parameters.empty? - hash[:features] = features.map { |f| f.to_hash } if features && !features.empty? + hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty? + hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty? + hash[:features] = features.map(&:to_hash) if features && !features.empty? hash end end diff --git a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb index 89929c9..5d4565e 100644 --- a/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb @@ -57,9 +57,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard return nil elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode) # Look for a call to a dispatch method with a block - next unless child.method_name && - (child.method_name.source == 'desc' || child.method_name.source == 'doc=') && - child.parameters(false).count == 1 + next unless + child.method_name && + (child.method_name.source == 'desc' || child.method_name.source == 'doc=') && + child.parameters(false).count == 1 docstring = node_as_string(child.parameters[0]) log.error "Failed to parse docstring for Puppet provider '#{object.name}' (resource type '#{object.type_name}') near #{child.file}:#{child.line}." and return nil unless docstring diff --git a/lib/puppet/face/strings.rb b/lib/puppet/face/strings.rb index ba441ed..06d4ce6 100644 --- a/lib/puppet/face/strings.rb +++ b/lib/puppet/face/strings.rb @@ -80,7 +80,7 @@ Puppet::Face.define(:strings, '0.0.1') do def check_required_features raise RuntimeError, "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard? raise RuntimeError, "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen? - raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match(/^1\.8/) + raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION =~ /^1\.8/ end # Builds the options to PuppetStrings.generate. diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index a948d98..e64afc4 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -6,7 +6,6 @@ unless ENV['RS_PROVISION'] == 'no' end RSpec.configure do |c| - # Readable test descriptions c.formatter = :documentation