Skip to content

Commit 5af8db8

Browse files
committed
(MAINT) Rubocop - (lib) fixes for yard
1 parent 5bec15b commit 5af8db8

35 files changed

+235
-200
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.instance
1313
# Gets the display name of the group.
1414
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1515
# @return [String] Returns the display name of the group.
16-
def name(prefix = false)
16+
def name(_prefix = false)
1717
'Puppet Classes'
1818
end
1919
end
@@ -53,7 +53,7 @@ def to_hash
5353
hash[:line] = line
5454
hash[:inherits] = statement.parent_class if statement.parent_class
5555
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
56-
defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
56+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
5757
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
5858
hash[:source] = source unless source.nil? || source.empty?
5959
hash

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.instance
1414
# Gets the display name of the group.
1515
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1616
# @return [String] Returns the display name of the group.
17-
def name(prefix = false)
17+
def name(_prefix = false)
1818
'Puppet Data Types'
1919
end
2020
end
@@ -73,7 +73,7 @@ def add_function(name, return_type, parameter_types)
7373
meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}"))
7474
end
7575

76-
self.meths << meth_obj
76+
meths << meth_obj
7777
end
7878

7979
def functions
@@ -87,14 +87,14 @@ def to_hash
8787
hash[:name] = name
8888
hash[:file] = file
8989
hash[:line] = line
90-
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
90+
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, [:param, :option, :enum, :return, :example])
9191
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
9292
hash[:source] = source unless source.nil? || source.empty?
9393
hash[:functions] = functions.map do |func|
9494
{
9595
name: func.name,
9696
signature: func.signature,
97-
docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example])
97+
docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, [:param, :option, :enum, :return, :example])
9898
}
9999
end
100100
hash

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.instance
1414
# Gets the display name of the group.
1515
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1616
# @return [String] Returns the display name of the group.
17-
def name(prefix = false)
17+
def name(_prefix = false)
1818
'Puppet Data Type Aliases'
1919
end
2020
end

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.instance
1313
# Gets the display name of the group.
1414
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1515
# @return [String] Returns the display name of the group.
16-
def name(prefix = false)
16+
def name(_prefix = false)
1717
'Defined Types'
1818
end
1919
end
@@ -52,7 +52,7 @@ def to_hash
5252
hash[:file] = file
5353
hash[:line] = line
5454
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
55-
defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
55+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
5656
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
5757
hash[:source] = source unless source.nil? || source.empty?
5858
hash

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class PuppetStrings::Yard::CodeObjects::Functions < PuppetStrings::Yard::CodeObj
88
# @param [Symbol] type The function type to get the group for.
99
# @return Returns the singleton instance of the group.
1010
def self.instance(type)
11-
super("puppet_functions_#{type}".intern)
11+
super("puppet_functions_#{type}".to_sym)
1212
end
1313

1414
# Gets the display name of the group.
1515
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1616
# @return [String] Returns the display name of the group.
17-
def name(prefix = false)
17+
def name(_prefix = false)
1818
'Puppet Functions'
1919
end
2020
end
@@ -62,18 +62,18 @@ def function_type
6262
# Gets the Puppet signature of the function (single overload only).
6363
# @return [String] Returns the Puppet signature of the function.
6464
def signature
65-
return '' if self.has_tag? :overload
65+
return '' if has_tag? :overload
6666

6767
tags = self.tags(:param)
68-
args = @parameters.map do |parameter|
68+
args = @parameters.map { |parameter|
6969
name, default = parameter
7070
tag = tags.find { |t| t.name == name } if tags
7171
type = tag&.types ? "#{tag.type} " : 'Any '
72-
prefix = "#{name[0]}" if name.start_with?('*', '&')
72+
prefix = (name[0]).to_s if name.start_with?('*', '&')
7373
name = name[1..-1] if prefix
7474
default = " = #{default}" if default
7575
"#{type}#{prefix}$#{name}#{default}"
76-
end.join(', ')
76+
}.join(', ')
7777
@name.to_s + '(' + args + ')'
7878
end
7979

@@ -88,17 +88,17 @@ def to_hash
8888
hash[:type] = @function_type.to_s
8989
hash[:signatures] = []
9090

91-
if self.has_tag? :overload
91+
if has_tag? :overload
9292
# loop over overloads and append onto the signatures array
93-
self.tags(:overload).each do |o|
94-
hash[:signatures] << { :signature => o.signature, :docstring => PuppetStrings::Yard::Util.docstring_to_hash(o.docstring, %i[param option enum return example]) }
93+
tags(:overload).each do |o|
94+
hash[:signatures] << { signature: o.signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(o.docstring, [:param, :option, :enum, :return, :example]) }
9595
end
9696
else
97-
hash[:signatures] << { :signature => self.signature, :docstring => PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example]) }
97+
hash[:signatures] << { signature: signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(docstring, [:param, :option, :enum, :return, :example]) }
9898
end
9999

100100
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
101-
defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
101+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
102102
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
103103
hash[:source] = source unless source.nil? || source.empty?
104104
hash

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.instance(key)
1313
instance = P(:root, key)
1414
return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
1515

16-
instance = self.new(:root, key)
16+
instance = new(:root, key)
1717
instance.visibility = :hidden
1818
P(:root).children << instance
1919
instance

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'puppet-strings/yard/code_objects/group'
44

5+
# Implements the group for Puppet plans.
56
class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group
67
# Gets the singleton instance of the group.
78
# @return Returns the singleton instance of the group.
@@ -12,11 +13,12 @@ def self.instance
1213
# Gets the display name of the group.
1314
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1415
# @return [String] Returns the display name of the group.
15-
def name(prefix = false)
16+
def name(_prefix = false)
1617
'Puppet Plans'
1718
end
1819
end
1920

21+
# Implements the Puppet plan code object.
2022
class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects::Base
2123
attr_reader :statement
2224
attr_reader :parameters
@@ -50,7 +52,7 @@ def to_hash
5052
hash[:file] = file
5153
hash[:line] = line
5254
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
53-
defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
55+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
5456
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
5557
hash[:source] = source unless source.nil? || source.empty?
5658
hash

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class PuppetStrings::Yard::CodeObjects::Providers < PuppetStrings::Yard::CodeObj
88
# @param [String] type The resource type name for the provider.
99
# @return Returns the singleton instance of the group.
1010
def self.instance(type)
11-
super("puppet_providers_#{type}".intern)
11+
super("puppet_providers_#{type}".to_sym)
1212
end
1313

1414
# Gets the display name of the group.
1515
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1616
# @return [String] Returns the display name of the group.
17-
def name(prefix = false)
17+
def name(_prefix = false)
1818
'Providers'
1919
end
2020
end

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ def self.instance
1111
end
1212

1313
# Gets the display name of the group.
14-
# @param [Boolean] prefix whether to show a prefix.
14+
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1515
# @return [String] Returns the display name of the group.
16-
def name(prefix = false)
16+
def name(_prefix = false)
1717
'Puppet Tasks'
1818
end
1919
end
@@ -45,11 +45,11 @@ def source
4545

4646
def parameters
4747
parameters = []
48-
statement.parameters.each do |name,props|
48+
statement.parameters.each do |name, props|
4949
parameters.push({ name: name.to_s,
5050
tag_name: 'param',
51-
text: props['description'] || "",
52-
types: [props['type']] || "" })
51+
text: props['description'] || '',
52+
types: [props['type']] || '' })
5353
end
5454
parameters
5555
end
@@ -66,7 +66,6 @@ def to_hash
6666
},
6767
source: statement.source,
6868
supports_noop: statement.json['supports_noop'] || false,
69-
input_method: statement.json['input_method']
70-
}
69+
input_method: statement.json['input_method'] }
7170
end
7271
end

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.instance
1414
# Gets the display name of the group.
1515
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
1616
# @return [String] Returns the display name of the group.
17-
def name(prefix = false)
17+
def name(_prefix = false)
1818
'Resource Types'
1919
end
2020
end
@@ -87,7 +87,7 @@ class Feature
8787
# @param [String] docstring The docstring of the feature.
8888
def initialize(name, docstring)
8989
@name = name
90-
@docstring = PuppetStrings::Yard::Util.scrub_string(docstring).gsub("\n", ' ')
90+
@docstring = PuppetStrings::Yard::Util.scrub_string(docstring).tr("\n", ' ')
9191
end
9292

9393
# Converts the feature to a hash representation.
@@ -148,7 +148,7 @@ def add_check(check)
148148
end
149149

150150
def parameters
151-
@parameters ||= [] # guard against not filled parameters
151+
@parameters ||= [] # guard against not filled parameters
152152
# just return params if there are no providers
153153
return @parameters if providers.empty?
154154

@@ -157,8 +157,8 @@ def parameters
157157

158158
provider_param = Parameter.new(
159159
'provider',
160-
"The specific backend to use for this `#{self.name.to_s}` resource. You will seldom need " + \
161-
"to specify this --- Puppet will usually discover the appropriate provider for your platform."
160+
"The specific backend to use for this `#{name}` resource. You will seldom need " \
161+
'to specify this --- Puppet will usually discover the appropriate provider for your platform.',
162162
)
163163

164164
@parameters ||= []
@@ -169,7 +169,7 @@ def parameters
169169
# render-time. For now, this should re-resolve on every call.
170170
# may be able to memoize this
171171
def providers
172-
providers = YARD::Registry.all("puppet_providers_#{name}".intern)
172+
providers = YARD::Registry.all("puppet_providers_#{name}".to_sym)
173173
return providers if providers.empty?
174174

175175
providers.first.children
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# frozen_string_literal: true
22

3+
# Implements a helper that logs a warning if a summary tag has more than 140 characters
34
module PuppetStrings::Yard::Handlers::Helpers
4-
# Logs a warning if a summary tag has more than 140 characters
55
def self.validate_summary_tag(object)
6-
if object.has_tag?(:summary) && object.tag(:summary).text.length > 140
7-
log.warn "The length of the summary for #{object.type} '#{object.name}' exceeds the recommended limit of 140 characters."
8-
end
6+
return unless object.has_tag?(:summary) && object.tag(:summary).text.length > 140
7+
log.warn "The length of the summary for #{object.type} '#{object.name}' exceeds the recommended limit of 140 characters."
98
end
109
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

3+
# Implements the base class for all JSON handlers.
34
class PuppetStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base
45
def self.handles?(statement)
5-
handlers.any? {|handler| statement.is_a?(handler)}
6+
handlers.any? { |handler| statement.is_a?(handler) }
67
end
78
end

lib/puppet-strings/yard/handlers/json/task_handler.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'puppet-strings/yard/parsers'
55
require 'puppet-strings/yard/parsers/json/parser'
66

7+
# Implements the handler for JSON task metadata.
78
class PuppetStrings::Yard::Handlers::JSON::TaskHandler < PuppetStrings::Yard::Handlers::JSON::Base
89
handles PuppetStrings::Yard::Parsers::JSON::TaskStatement
910
namespace_only
@@ -24,10 +25,9 @@ def validate_description
2425
end
2526

2627
def validate_params
27-
unless @statement.parameters.empty?
28-
@statement.parameters.each do |param, val|
29-
log.warn "Missing description for param '#{param}' in #{@kind}" if val['description'].nil?
30-
end
28+
return if @statement.parameters.empty?
29+
@statement.parameters.each do |param, val|
30+
log.warn "Missing description for param '#{param}' in #{@kind}" if val['description'].nil?
3131
end
3232
end
3333
end

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
66
# @param statement The statement that was parsed.
77
# @return [Boolean] Returns true if the statement is handled by this handler or false if not.
88
def self.handles?(statement)
9-
handlers.any? {|handler| statement.is_a?(handler)}
9+
handlers.any? { |handler| statement.is_a?(handler) }
1010
end
1111

1212
protected
13+
1314
# Sets the parameter tag types for the given code object.
1415
# This also performs some validation on the parameter tags.
1516
# @param object The code object to set the parameter tag types for.
@@ -35,7 +36,11 @@ def set_parameter_types(object)
3536
end
3637

3738
# Warn if the parameter type and tag types don't match
38-
log.warn "The type of the @param tag for parameter '#{parameter.name}' does not match the parameter type specification near #{statement.file}:#{statement.line}: ignoring in favor of parameter type information." if parameter.type && tag.types && !tag.types.empty? && parameter.type != tag.types[0]
39+
if parameter.type && tag.types && !tag.types.empty? && parameter.type != tag.types[0]
40+
log.warn "The type of the @param tag for parameter '#{parameter.name}' "\
41+
"does not match the parameter type specification near #{statement.file}:#{statement.line}: "\
42+
'ignoring in favor of parameter type information.'
43+
end
3944

4045
if parameter.type
4146
tag.types = [parameter.type]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
3636
end
3737

3838
private
39-
def add_return_tag(object, type=nil)
39+
40+
def add_return_tag(object, type = nil)
4041
tag = object.tag(:return)
4142
if tag
4243
if (type && tag.types && tag.types.first) && (type != tag.types.first)
@@ -47,7 +48,7 @@ def add_return_tag(object, type=nil)
4748
return
4849
end
4950
log.warn "Missing @return tag near #{statement.file}:#{statement.line}."
50-
type = type || 'Any'
51+
type ||= 'Any'
5152
object.add_tag YARD::Tags::Tag.new(:return, '', type)
5253
end
5354
end

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
77
# A regular expression for detecting the start of a Ruby heredoc.
88
# Note: the first character of the heredoc start may have been cut off by YARD.
9-
HEREDOC_START = /^<?<[\-~]?['"]?(\w+)['"]?[^\n]*[\n]?/
9+
HEREDOC_START = %r{^<?<[\-~]?['"]?(\w+)['"]?[^\n]*[\n]?}.freeze
1010

1111
protected
12+
1213
# Converts the given Ruby AST node to a string representation.
1314
# @param node The Ruby AST node to convert.
1415
# @return [String] Returns a string representation of the node or nil if a string representation was not possible.
@@ -33,7 +34,7 @@ def node_as_string(node)
3334
source = node.source
3435
if source =~ HEREDOC_START
3536
lines = source.split("\n")
36-
source = lines[1..(lines.last.include?($1[0..-2]) ? -2 : -1)].join("\n") if lines.size > 1
37+
source = lines[1..(lines.last.include?(Regexp.last_match(1)[0..-2]) ? -2 : -1)].join("\n") if lines.size > 1
3738
end
3839

3940
source

0 commit comments

Comments
 (0)