Skip to content

Commit 1b30b4d

Browse files
committed
(MAINT) Rubocop: Fix Layout/EmptyLineAfterGuardClause
1 parent a76d361 commit 1b30b4d

22 files changed

+73
-0
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ namespace :litmus do
9595
`gem build puppet-strings.gemspec --quiet`
9696
result = $CHILD_STATUS
9797
raise "Unable to build the puppet-strings gem. Returned exit code #{result.exitstatus}" unless result.exitstatus.zero?
98+
9899
puts 'Built'
99100
# Find the gem build artifact
100101
gem_tar = Dir.glob('puppet-strings-*.gem').max_by { |f| File.mtime(f) }
101102
raise "Unable to find package in 'puppet-strings-*.gem'" if gem_tar.nil?
103+
102104
gem_tar = File.expand_path(gem_tar)
103105

104106
target_string = if args[:target_node_name].nil?

lib/puppet-strings/tasks/gh_pages.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
task :checkout do
88
if Dir.exist?('doc')
99
fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
10+
1011
Dir.chdir('doc') do
1112
system 'git checkout gh-pages'
1213
system 'git pull --rebase origin gh-pages'

lib/puppet-strings/yard.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def stats_for_puppet_tasks
104104

105105
def stats_for_puppet_plans
106106
return unless PuppetStrings.puppet_5?
107+
107108
output 'Puppet Plans', *type_statistics_all(:puppet_plan)
108109
end
109110

lib/puppet-strings/yard/code_objects/function.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def function_type
6363
# @return [String] Returns the Puppet signature of the function.
6464
def signature
6565
return '' if self.has_tag? :overload
66+
6667
tags = self.tags(:param)
6768
args = @parameters.map do |parameter|
6869
name, default = parameter

lib/puppet-strings/yard/code_objects/group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects
1212
def self.instance(key)
1313
instance = P(:root, key)
1414
return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
15+
1516
instance = self.new(:root, key)
1617
instance.visibility = :hidden
1718
P(:root).children << instance

lib/puppet-strings/yard/code_objects/provider.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def type
4444
# @return [void]
4545
def add_confine(key, value)
4646
return unless key && value
47+
4748
@confines ||= {}
4849
@confines[key] = value
4950
end
@@ -53,6 +54,7 @@ def add_confine(key, value)
5354
# @return [void]
5455
def add_feature(feature)
5556
return unless feature
57+
5658
@features ||= []
5759
@features << feature
5860
end
@@ -62,6 +64,7 @@ def add_feature(feature)
6264
# @return [void]
6365
def add_default(constraints)
6466
return unless constraints
67+
6568
@defaults ||= []
6669
@defaults << constraints
6770
end
@@ -72,6 +75,7 @@ def add_default(constraints)
7275
# @return [void]
7376
def add_command(key, value)
7477
return unless key && value
78+
7579
@commands ||= {}
7680
@commands[key] = value
7781
end

lib/puppet-strings/yard/code_objects/type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def parameters
169169
def providers
170170
providers = YARD::Registry.all("puppet_providers_#{name}".intern)
171171
return providers if providers.empty?
172+
172173
providers.first.children
173174
end
174175

lib/puppet-strings/yard/handlers/puppet/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def set_parameter_types(object)
1919
tags = object.tags(:param)
2020
tags.each do |tag|
2121
next if statement.parameters.find { |p| tag.name == p.name }
22+
2223
log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}." unless tag.name == 'name' || tag.name == 'title'
2324
end
2425

lib/puppet-strings/yard/handlers/ruby/base.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
1414
# @return [String] Returns a string representation of the node or nil if a string representation was not possible.
1515
def node_as_string(node)
1616
return nil unless node
17+
1718
case node.type
1819
when :symbol, :symbol_literal
1920
node.source[1..-1]
@@ -44,8 +45,10 @@ def node_as_string(node)
4445
def get_name(statementobject, statementtype)
4546
parameters = statementobject.parameters(false)
4647
raise YARD::Parser::UndocumentableError, "Expected at least one parameter to #{statementtype} at #{statementobject.file}:#{statementobject.line}." if parameters.empty?
48+
4749
name = node_as_string(parameters.first)
4850
raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name
51+
4952
name
5053
end
5154
end

lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
1212

1313
process do
1414
return unless statement.count > 1
15+
1516
ruby_module_name = statement[0].source
1617
return unless ruby_module_name == 'Puppet::DataTypes' || ruby_module_name == 'DataTypes' # rubocop:disable Style/MultipleComparison This reads better
18+
1719
object = get_datatype_yard_object(get_name(statement, 'Puppet::DataTypes.create_type'))
1820
# Extract the interface definition
1921
type_interface = extract_data_type_interface
@@ -67,8 +69,10 @@ def extract_data_type_interface
6769
next false unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
6870
node.method_name &&
6971
node.method_name.source == 'interface'
72+
7073
parameters = node.parameters(false)
7174
next false unless parameters.count >= 1
75+
7276
interface_string = node_as_string(parameters[0])
7377
next false unless interface_string
7478

@@ -99,8 +103,10 @@ def extract_data_type_interface
99103
# @return [YARD::Parser::Ruby::AstNode, nil]
100104
def find_ruby_ast_node(ast_node, recurse = false, &block)
101105
raise ArgumentError, 'find_ruby_ast_node requires a block' unless block_given?
106+
102107
is_found = yield ast_node
103108
return ast_node if is_found
109+
104110
if ast_node.respond_to?(:children)
105111
ast_node.children.each do |child_node|
106112
child_found = find_ruby_ast_node(child_node, recurse, &block)
@@ -277,8 +283,10 @@ def validate_param_tags!(object, actual_params_hash)
277283
# Find param tags with a type that is different from the actual definition
278284
object.tags(:param).reject { |tag| tag.types.nil? }.each do |tag|
279285
next if actual_params_hash[tag.name].nil?
286+
280287
actual_data_type = actual_params_hash[tag.name][:types]
281288
next if actual_data_type.nil?
289+
282290
log.warn "The @param tag for '#{tag.name}' has a different type definition than the actual attribute near #{object.file}:#{object.line}." if tag.types != actual_data_type
283291
end
284292

@@ -292,6 +300,7 @@ def validate_param_tags!(object, actual_params_hash)
292300
# Set the type in the param tag
293301
object.tags(:param).each do |tag|
294302
next if actual_params_hash[tag.name].nil?
303+
295304
tag.types = actual_params_hash[tag.name][:types]
296305
end
297306
end
@@ -313,10 +322,13 @@ def validate_methods!(object, actual_functions_hash)
313322
# Functions with the wrong return type
314323
object.meths.each do |meth|
315324
next unless actual_func_names.include?(meth.name.to_s)
325+
316326
return_tag = meth.docstring.tag(:return)
317327
next if return_tag.nil?
328+
318329
actual_return_types = [actual_functions_hash[meth.name.to_s][:return_type]]
319330
next if return_tag.types == actual_return_types
331+
320332
log.warn "The @return tag for '#{meth.name}' has a different type definition than the actual function near #{object.file}:#{object.line}. Expected #{actual_return_types}"
321333
return_tag.types = actual_return_types
322334
end
@@ -331,13 +343,15 @@ def validate_methods!(object, actual_functions_hash)
331343
# Add the return type for the methods if missing
332344
object.meths.each do |meth|
333345
next unless meth.docstring.tag(:return).nil?
346+
334347
meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type]))
335348
end
336349

337350
# Sync the method properties and add the return type for the methods if missing
338351
object.meths.each do |meth|
339352
validate_function_method!(object, meth, actual_functions_hash[meth.name.to_s])
340353
next unless meth.docstring.tag(:return).nil?
354+
341355
meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type]))
342356
end
343357

lib/puppet-strings/yard/handlers/ruby/function_handler.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
3131
# newline, YARD ignores the namespace and uses `newfunction` as the source of the
3232
# first statement.
3333
return unless statement.count > 1
34+
3435
module_name = statement[0].source
3536
return unless module_name == 'Puppet::Functions' || module_name == 'Puppet::Parser::Functions' || module_name == 'newfunction'
3637

@@ -330,6 +331,7 @@ def validate_overload(overload, file, line)
330331
# Validate that tags have matching parameters
331332
overload.tags(:param).each do |tag|
332333
next if overload.parameters.find { |p| tag.name == p[0] }
334+
333335
log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{file}:#{line}."
334336
end
335337
end
@@ -340,9 +342,11 @@ def get_3x_docstring(name)
340342
parameters[1].each do |kvp|
341343
next unless kvp.count == 2
342344
next unless node_as_string(kvp[0]) == 'doc'
345+
343346
docstring = node_as_string(kvp[1])
344347

345348
log.error "Failed to parse docstring for 3.x Puppet function '#{name}' near #{statement.file}:#{statement.line}." and return nil unless docstring
349+
346350
return PuppetStrings::Yard::Util.scrub_string(docstring)
347351
end
348352
end

lib/puppet-strings/yard/handlers/ruby/provider_handler.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
2222
# Extract the type name
2323
type_call_parameters = type_call.parameters(false)
2424
return unless type_call_parameters.count >= 1
25+
2526
type_name = node_as_string(type_call_parameters.first)
2627
raise YARD::Parser::UndocumentableError, "Could not determine the resource type name for the provider defined at #{statement.file}:#{statement.line}." unless type_name
2728

@@ -49,8 +50,10 @@ def register_provider_docstring(object)
4950
if child.type == :assign
5051
ivar = child.jump(:ivar)
5152
next unless ivar != child && ivar.source == '@doc'
53+
5254
docstring = node_as_string(child[1])
5355
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
56+
5457
register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
5558
return nil
5659
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
@@ -62,6 +65,7 @@ def register_provider_docstring(object)
6265

6366
docstring = node_as_string(child.parameters[0])
6467
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
68+
6569
register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
6670
return nil
6771
end
@@ -73,6 +77,7 @@ def populate_provider_data(object)
7377
# Traverse the block looking for confines/defaults/commands
7478
block = statement.block
7579
return unless block && block.count >= 2
80+
7681
block[1].children.each do |node|
7782
next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name
7883

@@ -82,8 +87,10 @@ def populate_provider_data(object)
8287
if method_name == 'confine'
8388
# Add a confine to the object
8489
next unless parameters.count >= 1
90+
8591
parameters[0].each do |kvp|
8692
next unless kvp.count == 2
93+
8794
object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
8895
end
8996
elsif method_name == 'has_feature' || method_name == 'has_features'
@@ -94,9 +101,11 @@ def populate_provider_data(object)
94101
elsif method_name == 'defaultfor'
95102
# Add a default to the object
96103
next unless parameters.count >= 1
104+
97105
# Some defaultfor statements contain multiple constraints.
98106
parameters.each do |kvps|
99107
next unless kvps.count >= 1
108+
100109
defaultfor = []
101110
kvps.each do |kvp|
102111
defaultfor << [node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source]
@@ -106,8 +115,10 @@ def populate_provider_data(object)
106115
elsif method_name == 'commands'
107116
# Add the commands to the object
108117
next unless parameters.count >= 1
118+
109119
parameters[0].each do |kvp|
110120
next unless kvp.count == 2
121+
111122
object.add_command(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
112123
end
113124
end

lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
1616
process do
1717
# Only accept calls to Puppet::ResourceApi
1818
return unless statement.count > 1
19+
1920
module_name = statement[0].source
2021
return unless ['Puppet::ResourceApi'].include? module_name
2122

lib/puppet-strings/yard/handlers/ruby/type_base.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def find_docstring(node, kind)
2424
if child.type == :assign
2525
ivar = child.jump(:ivar)
2626
next unless ivar != child && ivar.source == '@doc'
27+
2728
docstring = node_as_string(child[1])
2829
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
30+
2931
return PuppetStrings::Yard::Util.scrub_string(docstring)
3032
elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
3133
# Look for a call to a dispatch method with a block
@@ -35,6 +37,7 @@ def find_docstring(node, kind)
3537

3638
docstring = node_as_string(child.parameters[0])
3739
log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
40+
3841
return PuppetStrings::Yard::Util.scrub_string(docstring)
3942
end
4043
end
@@ -71,16 +74,19 @@ def set_values(node, object)
7174

7275
if method_name == 'newvalue'
7376
next unless parameters.count >= 1
77+
7478
object.add(node_as_string(parameters[0]) || parameters[0].source)
7579
elsif method_name == 'newvalues'
7680
parameters.each do |p|
7781
object.add(node_as_string(p) || p.source)
7882
end
7983
elsif method_name == 'aliasvalue'
8084
next unless parameters.count >= 2
85+
8186
object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
8287
elsif method_name == 'defaultto'
8388
next unless parameters.count >= 1
89+
8490
object.default = node_as_string(parameters[0]) || parameters[0].source
8591
elsif method_name == 'isnamevar'
8692
object.isnamevar = true
@@ -105,6 +111,7 @@ def set_values(node, object)
105111
parameters[1].each do |kvp|
106112
next unless kvp.count == 2
107113
next unless node_as_string(kvp[0]) == 'parent'
114+
108115
if kvp[1].source == 'Puppet::Parameter::Boolean'
109116
object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
110117
object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
@@ -119,16 +126,19 @@ def set_values(node, object)
119126

120127
def set_default_namevar(object)
121128
return unless object.properties || object.parameters
129+
122130
default = nil
123131
if object.properties
124132
object.properties.each do |property|
125133
return nil if property.isnamevar
134+
126135
default = property if property.name == 'name'
127136
end
128137
end
129138
if object.parameters
130139
object.parameters.each do |parameter|
131140
return nil if parameter.isnamevar
141+
132142
default ||= parameter if parameter.name == 'name'
133143
end
134144
end

lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
3333
# propertyname: "content"
3434

3535
return unless (statement.count > 1) && (statement[0].children.count > 2)
36+
3637
module_name = statement[0].children[0].source
3738
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
3839
return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'

0 commit comments

Comments
 (0)