puppet-strings 2.9.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +257 -237
- data/README.md +52 -65
- data/lib/puppet/face/strings.rb +30 -50
- data/lib/puppet/feature/rgen.rb +1 -1
- data/lib/puppet/feature/yard.rb +1 -1
- data/lib/puppet-strings/describe.rb +18 -18
- data/lib/puppet-strings/markdown/base.rb +63 -28
- data/lib/puppet-strings/markdown/data_type.rb +4 -0
- data/lib/puppet-strings/markdown/defined_type.rb +4 -0
- data/lib/puppet-strings/markdown/function.rb +13 -8
- data/lib/puppet-strings/markdown/helpers.rb +21 -0
- data/lib/puppet-strings/markdown/puppet_class.rb +4 -0
- data/lib/puppet-strings/markdown/puppet_plan.rb +4 -0
- data/lib/puppet-strings/markdown/puppet_task.rb +4 -1
- data/lib/puppet-strings/markdown/resource_type.rb +13 -3
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +4 -4
- data/lib/puppet-strings/markdown/templates/data_type.erb +5 -9
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +1 -1
- data/lib/puppet-strings/markdown/templates/function.erb +1 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +6 -6
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +8 -8
- data/lib/puppet-strings/markdown.rb +62 -20
- data/lib/puppet-strings/monkey_patches/display_object_command.rb +4 -1
- data/lib/puppet-strings/tasks/generate.rb +8 -10
- data/lib/puppet-strings/tasks/gh_pages.rb +6 -5
- data/lib/puppet-strings/tasks/validate.rb +1 -1
- data/lib/puppet-strings/tasks.rb +5 -7
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/data_type.rb +4 -4
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/function.rb +11 -11
- data/lib/puppet-strings/yard/code_objects/group.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
- data/lib/puppet-strings/yard/code_objects/provider.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/task.rb +6 -7
- data/lib/puppet-strings/yard/code_objects/type.rb +6 -6
- data/lib/puppet-strings/yard/handlers/helpers.rb +3 -4
- data/lib/puppet-strings/yard/handlers/json/base.rb +2 -1
- data/lib/puppet-strings/yard/handlers/json/task_handler.rb +4 -4
- data/lib/puppet-strings/yard/handlers/puppet/base.rb +7 -2
- data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -2
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +3 -2
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +19 -16
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +70 -50
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +2 -1
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +12 -9
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +27 -27
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +2 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +2 -1
- data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -2
- data/lib/puppet-strings/yard/parsers/json/task_statement.rb +3 -3
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +7 -7
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +16 -23
- data/lib/puppet-strings/yard/parsers.rb +1 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +1 -2
- data/lib/puppet-strings/yard/tags/factory.rb +1 -1
- data/lib/puppet-strings/yard/tags/overload_tag.rb +7 -7
- data/lib/puppet-strings/yard/tags/parameter_directive.rb +2 -2
- data/lib/puppet-strings/yard/tags/property_directive.rb +2 -2
- data/lib/puppet-strings/yard/tags/summary_tag.rb +1 -2
- data/lib/puppet-strings/yard/util.rb +11 -4
- data/lib/puppet-strings/yard.rb +6 -6
- data/lib/puppet-strings.rb +7 -13
- metadata +13 -20
- data/lib/puppet-strings/markdown/data_types.rb +0 -43
- data/lib/puppet-strings/markdown/defined_types.rb +0 -39
- data/lib/puppet-strings/markdown/functions.rb +0 -40
- data/lib/puppet-strings/markdown/puppet_classes.rb +0 -39
- data/lib/puppet-strings/markdown/puppet_plans.rb +0 -39
- data/lib/puppet-strings/markdown/puppet_tasks.rb +0 -36
- data/lib/puppet-strings/markdown/resource_types.rb +0 -39
- data/lib/puppet-strings/markdown/table_of_contents.rb +0 -26
@@ -13,7 +13,7 @@ class PuppetStrings::Yard::CodeObjects::DefinedTypes < PuppetStrings::Yard::Code
|
|
13
13
|
# Gets the display name of the group.
|
14
14
|
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
15
15
|
# @return [String] Returns the display name of the group.
|
16
|
-
def name(
|
16
|
+
def name(_prefix = false)
|
17
17
|
'Defined Types'
|
18
18
|
end
|
19
19
|
end
|
@@ -52,7 +52,7 @@ class PuppetStrings::Yard::CodeObjects::DefinedType < PuppetStrings::Yard::CodeO
|
|
52
52
|
hash[:file] = file
|
53
53
|
hash[:line] = line
|
54
54
|
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]
|
56
56
|
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
57
57
|
hash[:source] = source unless source.nil? || source.empty?
|
58
58
|
hash
|
@@ -8,13 +8,13 @@ class PuppetStrings::Yard::CodeObjects::Functions < PuppetStrings::Yard::CodeObj
|
|
8
8
|
# @param [Symbol] type The function type to get the group for.
|
9
9
|
# @return Returns the singleton instance of the group.
|
10
10
|
def self.instance(type)
|
11
|
-
super("puppet_functions_#{type}".
|
11
|
+
super("puppet_functions_#{type}".to_sym)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Gets the display name of the group.
|
15
15
|
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
16
16
|
# @return [String] Returns the display name of the group.
|
17
|
-
def name(
|
17
|
+
def name(_prefix = false)
|
18
18
|
'Puppet Functions'
|
19
19
|
end
|
20
20
|
end
|
@@ -62,18 +62,18 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
|
|
62
62
|
# Gets the Puppet signature of the function (single overload only).
|
63
63
|
# @return [String] Returns the Puppet signature of the function.
|
64
64
|
def signature
|
65
|
-
return '' if
|
65
|
+
return '' if has_tag? :overload
|
66
66
|
|
67
67
|
tags = self.tags(:param)
|
68
|
-
args = @parameters.map
|
68
|
+
args = @parameters.map { |parameter|
|
69
69
|
name, default = parameter
|
70
70
|
tag = tags.find { |t| t.name == name } if tags
|
71
71
|
type = tag&.types ? "#{tag.type} " : 'Any '
|
72
|
-
prefix =
|
72
|
+
prefix = (name[0]).to_s if name.start_with?('*', '&')
|
73
73
|
name = name[1..-1] if prefix
|
74
74
|
default = " = #{default}" if default
|
75
75
|
"#{type}#{prefix}$#{name}#{default}"
|
76
|
-
|
76
|
+
}.join(', ')
|
77
77
|
@name.to_s + '(' + args + ')'
|
78
78
|
end
|
79
79
|
|
@@ -88,17 +88,17 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
|
|
88
88
|
hash[:type] = @function_type.to_s
|
89
89
|
hash[:signatures] = []
|
90
90
|
|
91
|
-
if
|
91
|
+
if has_tag? :overload
|
92
92
|
# loop over overloads and append onto the signatures array
|
93
|
-
|
94
|
-
hash[:signatures] << { :
|
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]) }
|
95
95
|
end
|
96
96
|
else
|
97
|
-
hash[:signatures] << { :
|
97
|
+
hash[:signatures] << { signature: signature, docstring: PuppetStrings::Yard::Util.docstring_to_hash(docstring, [:param, :option, :enum, :return, :example]) }
|
98
98
|
end
|
99
99
|
|
100
100
|
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]
|
102
102
|
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
103
103
|
hash[:source] = source unless source.nil? || source.empty?
|
104
104
|
hash
|
@@ -13,7 +13,7 @@ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects
|
|
13
13
|
instance = P(:root, key)
|
14
14
|
return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
|
15
15
|
|
16
|
-
instance =
|
16
|
+
instance = new(:root, key)
|
17
17
|
instance.visibility = :hidden
|
18
18
|
P(:root).children << instance
|
19
19
|
instance
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'puppet-strings/yard/code_objects/group'
|
4
4
|
|
5
|
+
# Implements the group for Puppet plans.
|
5
6
|
class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group
|
6
7
|
# Gets the singleton instance of the group.
|
7
8
|
# @return Returns the singleton instance of the group.
|
@@ -12,11 +13,12 @@ class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects
|
|
12
13
|
# Gets the display name of the group.
|
13
14
|
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
14
15
|
# @return [String] Returns the display name of the group.
|
15
|
-
def name(
|
16
|
+
def name(_prefix = false)
|
16
17
|
'Puppet Plans'
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
# Implements the Puppet plan code object.
|
20
22
|
class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects::Base
|
21
23
|
attr_reader :statement
|
22
24
|
attr_reader :parameters
|
@@ -50,7 +52,7 @@ class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects:
|
|
50
52
|
hash[:file] = file
|
51
53
|
hash[:line] = line
|
52
54
|
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]
|
54
56
|
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
55
57
|
hash[:source] = source unless source.nil? || source.empty?
|
56
58
|
hash
|
@@ -8,13 +8,13 @@ class PuppetStrings::Yard::CodeObjects::Providers < PuppetStrings::Yard::CodeObj
|
|
8
8
|
# @param [String] type The resource type name for the provider.
|
9
9
|
# @return Returns the singleton instance of the group.
|
10
10
|
def self.instance(type)
|
11
|
-
super("puppet_providers_#{type}".
|
11
|
+
super("puppet_providers_#{type}".to_sym)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Gets the display name of the group.
|
15
15
|
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
16
16
|
# @return [String] Returns the display name of the group.
|
17
|
-
def name(
|
17
|
+
def name(_prefix = false)
|
18
18
|
'Providers'
|
19
19
|
end
|
20
20
|
end
|
@@ -11,9 +11,9 @@ class PuppetStrings::Yard::CodeObjects::Tasks < PuppetStrings::Yard::CodeObjects
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# 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.
|
15
15
|
# @return [String] Returns the display name of the group.
|
16
|
-
def name(
|
16
|
+
def name(_prefix = false)
|
17
17
|
'Puppet Tasks'
|
18
18
|
end
|
19
19
|
end
|
@@ -45,11 +45,11 @@ class PuppetStrings::Yard::CodeObjects::Task < PuppetStrings::Yard::CodeObjects:
|
|
45
45
|
|
46
46
|
def parameters
|
47
47
|
parameters = []
|
48
|
-
statement.parameters.each do |name,props|
|
48
|
+
statement.parameters.each do |name, props|
|
49
49
|
parameters.push({ name: name.to_s,
|
50
50
|
tag_name: 'param',
|
51
|
-
text: props['description'] ||
|
52
|
-
types: [props['type']] ||
|
51
|
+
text: props['description'] || '',
|
52
|
+
types: [props['type']] || '' })
|
53
53
|
end
|
54
54
|
parameters
|
55
55
|
end
|
@@ -66,7 +66,6 @@ class PuppetStrings::Yard::CodeObjects::Task < PuppetStrings::Yard::CodeObjects:
|
|
66
66
|
},
|
67
67
|
source: statement.source,
|
68
68
|
supports_noop: statement.json['supports_noop'] || false,
|
69
|
-
input_method: statement.json['input_method']
|
70
|
-
}
|
69
|
+
input_method: statement.json['input_method'] }
|
71
70
|
end
|
72
71
|
end
|
@@ -14,7 +14,7 @@ class PuppetStrings::Yard::CodeObjects::Types < PuppetStrings::Yard::CodeObjects
|
|
14
14
|
# Gets the display name of the group.
|
15
15
|
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
16
16
|
# @return [String] Returns the display name of the group.
|
17
|
-
def name(
|
17
|
+
def name(_prefix = false)
|
18
18
|
'Resource Types'
|
19
19
|
end
|
20
20
|
end
|
@@ -87,7 +87,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
87
87
|
# @param [String] docstring The docstring of the feature.
|
88
88
|
def initialize(name, docstring)
|
89
89
|
@name = name
|
90
|
-
@docstring = PuppetStrings::Yard::Util.scrub_string(docstring).
|
90
|
+
@docstring = PuppetStrings::Yard::Util.scrub_string(docstring).tr("\n", ' ')
|
91
91
|
end
|
92
92
|
|
93
93
|
# Converts the feature to a hash representation.
|
@@ -148,7 +148,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def parameters
|
151
|
-
@parameters ||= []
|
151
|
+
@parameters ||= [] # guard against not filled parameters
|
152
152
|
# just return params if there are no providers
|
153
153
|
return @parameters if providers.empty?
|
154
154
|
|
@@ -157,8 +157,8 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
157
157
|
|
158
158
|
provider_param = Parameter.new(
|
159
159
|
'provider',
|
160
|
-
"The specific backend to use for this `#{
|
161
|
-
|
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.',
|
162
162
|
)
|
163
163
|
|
164
164
|
@parameters ||= []
|
@@ -169,7 +169,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
|
|
169
169
|
# render-time. For now, this should re-resolve on every call.
|
170
170
|
# may be able to memoize this
|
171
171
|
def providers
|
172
|
-
providers = YARD::Registry.all("puppet_providers_#{name}".
|
172
|
+
providers = YARD::Registry.all("puppet_providers_#{name}".to_sym)
|
173
173
|
return providers if providers.empty?
|
174
174
|
|
175
175
|
providers.first.children
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Implements a helper that logs a warning if a summary tag has more than 140 characters
|
3
4
|
module PuppetStrings::Yard::Handlers::Helpers
|
4
|
-
# Logs a warning if a summary tag has more than 140 characters
|
5
5
|
def self.validate_summary_tag(object)
|
6
|
-
|
7
|
-
|
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."
|
9
8
|
end
|
10
9
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Implements the base class for all JSON handlers.
|
3
4
|
class PuppetStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base
|
4
5
|
def self.handles?(statement)
|
5
|
-
handlers.any? {|handler| statement.is_a?(handler)}
|
6
|
+
handlers.any? { |handler| statement.is_a?(handler) }
|
6
7
|
end
|
7
8
|
end
|
@@ -4,6 +4,7 @@ require 'puppet-strings/yard/handlers/json/base'
|
|
4
4
|
require 'puppet-strings/yard/parsers'
|
5
5
|
require 'puppet-strings/yard/parsers/json/parser'
|
6
6
|
|
7
|
+
# Implements the handler for JSON task metadata.
|
7
8
|
class PuppetStrings::Yard::Handlers::JSON::TaskHandler < PuppetStrings::Yard::Handlers::JSON::Base
|
8
9
|
handles PuppetStrings::Yard::Parsers::JSON::TaskStatement
|
9
10
|
namespace_only
|
@@ -24,10 +25,9 @@ class PuppetStrings::Yard::Handlers::JSON::TaskHandler < PuppetStrings::Yard::Ha
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def validate_params
|
27
|
-
|
28
|
-
|
29
|
-
|
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?
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -6,10 +6,11 @@ class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
|
|
6
6
|
# @param statement The statement that was parsed.
|
7
7
|
# @return [Boolean] Returns true if the statement is handled by this handler or false if not.
|
8
8
|
def self.handles?(statement)
|
9
|
-
handlers.any? {|handler| statement.is_a?(handler)}
|
9
|
+
handlers.any? { |handler| statement.is_a?(handler) }
|
10
10
|
end
|
11
11
|
|
12
12
|
protected
|
13
|
+
|
13
14
|
# Sets the parameter tag types for the given code object.
|
14
15
|
# This also performs some validation on the parameter tags.
|
15
16
|
# @param object The code object to set the parameter tag types for.
|
@@ -35,7 +36,11 @@ class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
|
|
35
36
|
end
|
36
37
|
|
37
38
|
# Warn if the parameter type and tag types don't match
|
38
|
-
|
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
|
39
44
|
|
40
45
|
if parameter.type
|
41
46
|
tag.types = [parameter.type]
|
@@ -36,7 +36,8 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
|
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
39
|
-
|
39
|
+
|
40
|
+
def add_return_tag(object, type = nil)
|
40
41
|
tag = object.tag(:return)
|
41
42
|
if tag
|
42
43
|
if (type && tag.types && tag.types.first) && (type != tag.types.first)
|
@@ -47,7 +48,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
|
|
47
48
|
return
|
48
49
|
end
|
49
50
|
log.warn "Missing @return tag near #{statement.file}:#{statement.line}."
|
50
|
-
type
|
51
|
+
type ||= 'Any'
|
51
52
|
object.add_tag YARD::Tags::Tag.new(:return, '', type)
|
52
53
|
end
|
53
54
|
end
|
@@ -6,9 +6,10 @@ require 'ripper'
|
|
6
6
|
class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
|
7
7
|
# A regular expression for detecting the start of a Ruby heredoc.
|
8
8
|
# Note: the first character of the heredoc start may have been cut off by YARD.
|
9
|
-
HEREDOC_START =
|
9
|
+
HEREDOC_START = %r{^<?<[\-~]?['"]?(\w+)['"]?[^\n]*[\n]?}.freeze
|
10
10
|
|
11
11
|
protected
|
12
|
+
|
12
13
|
# Converts the given Ruby AST node to a string representation.
|
13
14
|
# @param node The Ruby AST node to convert.
|
14
15
|
# @return [String] Returns a string representation of the node or nil if a string representation was not possible.
|
@@ -33,7 +34,7 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
|
|
33
34
|
source = node.source
|
34
35
|
if source =~ HEREDOC_START
|
35
36
|
lines = source.split("\n")
|
36
|
-
source = lines[1..(lines.last.include?(
|
37
|
+
source = lines[1..(lines.last.include?(Regexp.last_match(1)[0..-2]) ? -2 : -1)].join("\n") if lines.size > 1
|
37
38
|
end
|
38
39
|
|
39
40
|
source
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Naming/MethodName
|
4
|
+
|
3
5
|
require 'puppet-strings/yard/handlers/helpers'
|
4
6
|
require 'puppet-strings/yard/handlers/ruby/base'
|
5
7
|
require 'puppet-strings/yard/code_objects'
|
@@ -65,7 +67,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
65
67
|
parsed_interface = nil
|
66
68
|
|
67
69
|
# Recursively traverse the block looking for the first valid 'interface' call
|
68
|
-
|
70
|
+
find_ruby_ast_node(block, true) do |node|
|
69
71
|
next false unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
|
70
72
|
node.method_name &&
|
71
73
|
node.method_name.source == 'interface'
|
@@ -102,7 +104,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
102
104
|
# @yieldreturn [Boolean] Whether the node was what was searched for
|
103
105
|
# @return [YARD::Parser::Ruby::AstNode, nil]
|
104
106
|
def find_ruby_ast_node(ast_node, recurse = false, &block)
|
105
|
-
raise ArgumentError, 'find_ruby_ast_node requires a block' unless
|
107
|
+
raise ArgumentError, 'find_ruby_ast_node requires a block' unless block
|
106
108
|
|
107
109
|
is_found = yield ast_node
|
108
110
|
return ast_node if is_found
|
@@ -136,7 +138,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
136
138
|
# Anything else is ignored
|
137
139
|
class LazyLiteralEvaluator
|
138
140
|
def initialize
|
139
|
-
@literal_visitor = ::Puppet::Pops::Visitor.new(self,
|
141
|
+
@literal_visitor = ::Puppet::Pops::Visitor.new(self, 'literal', 0, 0)
|
140
142
|
end
|
141
143
|
|
142
144
|
def literal(ast)
|
@@ -150,12 +152,12 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
150
152
|
|
151
153
|
def literal_AccessExpression(o)
|
152
154
|
# Extract the raw text of the Access Expression
|
153
|
-
::
|
155
|
+
PuppetStrings::Yard::Util.ast_to_text(o)
|
154
156
|
end
|
155
157
|
|
156
158
|
def literal_QualifiedReference(o)
|
157
159
|
# Extract the raw text of the Qualified Reference
|
158
|
-
::
|
160
|
+
PuppetStrings::Yard::Util.ast_to_text(o)
|
159
161
|
end
|
160
162
|
|
161
163
|
# ----- The following methods are the same as the original Literal_evaluator
|
@@ -187,11 +189,11 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
187
189
|
o.value
|
188
190
|
end
|
189
191
|
|
190
|
-
def literal_LiteralUndef(
|
192
|
+
def literal_LiteralUndef(_o)
|
191
193
|
nil
|
192
194
|
end
|
193
195
|
|
194
|
-
def literal_LiteralDefault(
|
196
|
+
def literal_LiteralDefault(_o)
|
195
197
|
:default
|
196
198
|
end
|
197
199
|
|
@@ -210,9 +212,8 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
210
212
|
end
|
211
213
|
|
212
214
|
def literal_LiteralHash(o)
|
213
|
-
o.entries.
|
215
|
+
o.entries.each_with_object({}) do |entry, result|
|
214
216
|
result[literal(entry.key)] = literal(entry.value)
|
215
|
-
result
|
216
217
|
end
|
217
218
|
end
|
218
219
|
end
|
@@ -235,7 +236,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
235
236
|
default = value['value'] unless value['value'].nil?
|
236
237
|
end
|
237
238
|
data_type = [data_type] unless data_type.nil? || data_type.is_a?(Array)
|
238
|
-
params_hash[key] = { :
|
239
|
+
params_hash[key] = { types: data_type, default: default }
|
239
240
|
end
|
240
241
|
|
241
242
|
params_hash
|
@@ -250,7 +251,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
250
251
|
return funcs_hash if hash.nil? || hash['functions'].nil? || hash['functions'].empty?
|
251
252
|
|
252
253
|
hash['functions'].each do |key, func_type|
|
253
|
-
func_hash = { :
|
254
|
+
func_hash = { param_types: [], return_type: nil }
|
254
255
|
begin
|
255
256
|
callable_type = Puppet::Pops::Types::TypeParser.singleton.parse(func_type)
|
256
257
|
if callable_type.is_a?(Puppet::Pops::Types::PCallableType)
|
@@ -378,7 +379,9 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
378
379
|
if tag.tag_name == 'param'
|
379
380
|
index += 1
|
380
381
|
if index > actual_function[:param_types].count
|
381
|
-
log.warn "The @param tag for '#{tag.name}' should not exist for function
|
382
|
+
log.warn "The @param tag for '#{tag.name}' should not exist for function "\
|
383
|
+
"'#{meth.name}' that is defined near #{object.file}:#{object.line}. "\
|
384
|
+
"Expected only #{actual_function[:param_types].count} parameter/s"
|
382
385
|
true
|
383
386
|
else
|
384
387
|
false
|
@@ -392,14 +395,14 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
|
|
392
395
|
# Add missing params
|
393
396
|
if meth.docstring.tags(:param).count < actual_function[:param_types].count
|
394
397
|
start = meth.docstring.tags(:param).count + 1
|
395
|
-
(start..actual_function[:param_types].count).each do |
|
396
|
-
meth.add_tag(YARD::Tags::Tag.new(:param, '', actual_function[:param_types][
|
398
|
+
(start..actual_function[:param_types].count).each do |param_type_index| # Using 1-based index here instead of usual zero
|
399
|
+
meth.add_tag(YARD::Tags::Tag.new(:param, '', actual_function[:param_types][param_type_index - 1], "param#{param_type_index}"))
|
397
400
|
end
|
398
401
|
end
|
399
402
|
|
400
403
|
# Ensure the parameter types are correct
|
401
|
-
meth.docstring.tags(:param).each_with_index do |tag,
|
402
|
-
actual_types = [actual_function[:param_types][
|
404
|
+
meth.docstring.tags(:param).each_with_index do |tag, actual_type_index|
|
405
|
+
actual_types = [actual_function[:param_types][actual_type_index]]
|
403
406
|
if tag.types != actual_types
|
404
407
|
log.warn "The @param tag for '#{tag.name}' for function '#{meth.name}' has a different type definition than the actual function near #{object.file}:#{object.line}. Expected #{actual_types}"
|
405
408
|
tag.types = actual_types
|