puppet-strings 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -6
  3. data/lib/puppet-strings.rb +2 -0
  4. data/lib/puppet-strings/describe.rb +2 -0
  5. data/lib/puppet-strings/json.rb +2 -0
  6. data/lib/puppet-strings/markdown.rb +11 -9
  7. data/lib/puppet-strings/markdown/base.rb +11 -3
  8. data/lib/puppet-strings/markdown/data_type.rb +2 -0
  9. data/lib/puppet-strings/markdown/data_types.rb +3 -1
  10. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  11. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  12. data/lib/puppet-strings/markdown/function.rb +9 -7
  13. data/lib/puppet-strings/markdown/functions.rb +3 -1
  14. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  15. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  20. data/lib/puppet-strings/markdown/resource_type.rb +2 -0
  21. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  22. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  23. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +7 -3
  24. data/lib/puppet-strings/markdown/templates/data_type.erb +12 -4
  25. data/lib/puppet-strings/markdown/templates/data_type_function.erb +1 -1
  26. data/lib/puppet-strings/markdown/templates/function.erb +1 -1
  27. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  28. data/lib/puppet-strings/markdown/templates/resource_type.erb +8 -2
  29. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  30. data/lib/puppet-strings/tasks.rb +2 -0
  31. data/lib/puppet-strings/tasks/generate.rb +2 -0
  32. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  33. data/lib/puppet-strings/version.rb +3 -1
  34. data/lib/puppet-strings/yard.rb +3 -0
  35. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  36. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  37. data/lib/puppet-strings/yard/code_objects/class.rb +4 -2
  38. data/lib/puppet-strings/yard/code_objects/data_type.rb +4 -2
  39. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/defined_type.rb +4 -2
  41. data/lib/puppet-strings/yard/code_objects/function.rb +6 -3
  42. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  43. data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
  44. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  45. data/lib/puppet-strings/yard/code_objects/task.rb +2 -0
  46. data/lib/puppet-strings/yard/code_objects/type.rb +3 -0
  47. data/lib/puppet-strings/yard/handlers.rb +2 -0
  48. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  49. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  50. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  51. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  52. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  56. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  57. data/lib/puppet-strings/yard/handlers/ruby/base.rb +5 -0
  58. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +33 -17
  59. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -7
  60. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  61. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +4 -1
  62. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +14 -6
  63. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +5 -2
  64. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +12 -1
  65. data/lib/puppet-strings/yard/parsers.rb +2 -0
  66. data/lib/puppet-strings/yard/parsers/json/parser.rb +2 -0
  67. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  68. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +12 -10
  69. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +4 -0
  70. data/lib/puppet-strings/yard/tags.rb +2 -0
  71. data/lib/puppet-strings/yard/tags/enum_tag.rb +2 -0
  72. data/lib/puppet-strings/yard/tags/factory.rb +2 -0
  73. data/lib/puppet-strings/yard/tags/overload_tag.rb +4 -1
  74. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  75. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  76. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  77. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  78. data/lib/puppet-strings/yard/util.rb +4 -1
  79. data/lib/puppet/application/strings.rb +2 -0
  80. data/lib/puppet/face/strings.rb +4 -1
  81. data/lib/puppet/feature/rgen.rb +2 -0
  82. data/lib/puppet/feature/yard.rb +2 -0
  83. metadata +5 -5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -29,6 +31,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
29
31
  # newline, YARD ignores the namespace and uses `newfunction` as the source of the
30
32
  # first statement.
31
33
  return unless statement.count > 1
34
+
32
35
  module_name = statement[0].source
33
36
  return unless module_name == 'Puppet::Functions' || module_name == 'Puppet::Parser::Functions' || module_name == 'newfunction'
34
37
 
@@ -219,8 +222,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
219
222
 
220
223
  # Populate the required parameters
221
224
  params = parameters.unnamed_required_params
222
- if params
223
- params.each do |parameter|
225
+ params&.each do |parameter|
224
226
  add_param_tag(
225
227
  overload_tag,
226
228
  param_tags,
@@ -229,12 +231,10 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
229
231
  parameter.line
230
232
  )
231
233
  end
232
- end
233
234
 
234
235
  # Populate the optional parameters
235
236
  params = parameters.unnamed_optional_params
236
- if params
237
- params.each do |parameter|
237
+ params&.each do |parameter|
238
238
  add_param_tag(
239
239
  overload_tag,
240
240
  param_tags,
@@ -246,7 +246,6 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
246
246
  true
247
247
  )
248
248
  end
249
- end
250
249
 
251
250
  # Populate the splat parameter
252
251
  param = parameters.splat_param
@@ -301,7 +300,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
301
300
  name = '&' + name
302
301
  end
303
302
 
304
- type ||= tag && tag.types ? tag.type : 'Any'
303
+ type ||= tag&.types ? tag.type : 'Any'
305
304
  type = optional ? "Optional[#{type}]" : type
306
305
 
307
306
  object.parameters << [name, to_puppet_literal(default)]
@@ -328,6 +327,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
328
327
  # Validate that tags have matching parameters
329
328
  overload.tags(:param).each do |tag|
330
329
  next if overload.parameters.find { |p| tag.name == p[0] }
330
+
331
331
  log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{file}:#{line}."
332
332
  end
333
333
  end
@@ -338,9 +338,11 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
338
338
  parameters[1].each do |kvp|
339
339
  next unless kvp.count == 2
340
340
  next unless node_as_string(kvp[0]) == 'doc'
341
+
341
342
  docstring = node_as_string(kvp[1])
342
343
 
343
344
  log.error "Failed to parse docstring for 3.x Puppet function '#{name}' near #{statement.file}:#{statement.line}." and return nil unless docstring
345
+
344
346
  return PuppetStrings::Yard::Util.scrub_string(docstring)
345
347
  end
346
348
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -20,6 +22,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
20
22
  # Extract the type name
21
23
  type_call_parameters = type_call.parameters(false)
22
24
  return unless type_call_parameters.count >= 1
25
+
23
26
  type_name = node_as_string(type_call_parameters.first)
24
27
  raise YARD::Parser::UndocumentableError, "Could not determine the resource type name for the provider defined at #{statement.file}:#{statement.line}." unless type_name
25
28
 
@@ -47,8 +50,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
47
50
  if child.type == :assign
48
51
  ivar = child.jump(:ivar)
49
52
  next unless ivar != child && ivar.source == '@doc'
53
+
50
54
  docstring = node_as_string(child[1])
51
55
  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
+
52
57
  register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
53
58
  return nil
54
59
  elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
@@ -60,6 +65,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
60
65
 
61
66
  docstring = node_as_string(child.parameters[0])
62
67
  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
+
63
69
  register_docstring(object, PuppetStrings::Yard::Util.scrub_string(docstring), nil)
64
70
  return nil
65
71
  end
@@ -71,6 +77,7 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
71
77
  # Traverse the block looking for confines/defaults/commands
72
78
  block = statement.block
73
79
  return unless block && block.count >= 2
80
+
74
81
  block[1].children.each do |node|
75
82
  next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) && node.method_name
76
83
 
@@ -80,8 +87,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
80
87
  if method_name == 'confine'
81
88
  # Add a confine to the object
82
89
  next unless parameters.count >= 1
90
+
83
91
  parameters[0].each do |kvp|
84
92
  next unless kvp.count == 2
93
+
85
94
  object.add_confine(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
86
95
  end
87
96
  elsif method_name == 'has_feature' || method_name == 'has_features'
@@ -92,9 +101,11 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
92
101
  elsif method_name == 'defaultfor'
93
102
  # Add a default to the object
94
103
  next unless parameters.count >= 1
104
+
95
105
  # Some defaultfor statements contain multiple constraints.
96
106
  parameters.each do |kvps|
97
107
  next unless kvps.count >= 1
108
+
98
109
  defaultfor = []
99
110
  kvps.each do |kvp|
100
111
  defaultfor << [node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source]
@@ -104,8 +115,10 @@ class PuppetStrings::Yard::Handlers::Ruby::ProviderHandler < PuppetStrings::Yard
104
115
  elsif method_name == 'commands'
105
116
  # Add the commands to the object
106
117
  next unless parameters.count >= 1
118
+
107
119
  parameters[0].each do |kvp|
108
120
  next unless kvp.count == 2
121
+
109
122
  object.add_command(node_as_string(kvp[0]) || kvp[0].source, node_as_string(kvp[1]) || kvp[1].source)
110
123
  end
111
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
6
8
  # Implements the handler for Puppet resource types written in Ruby.
7
9
  class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::Handlers::Ruby::Base
8
10
  # The default docstring when ensurable is used without given a docstring.
9
- DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze
11
+ DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
10
12
 
11
13
  namespace_only
12
14
  handles method_call(:register_type)
@@ -14,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
14
16
  process do
15
17
  # Only accept calls to Puppet::ResourceApi
16
18
  return unless statement.count > 1
19
+
17
20
  module_name = statement[0].source
18
21
  return unless ['Puppet::ResourceApi'].include? module_name
19
22
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/ruby/base'
2
4
 
3
5
  class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handlers::Ruby::Base
@@ -22,8 +24,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
22
24
  if child.type == :assign
23
25
  ivar = child.jump(:ivar)
24
26
  next unless ivar != child && ivar.source == '@doc'
27
+
25
28
  docstring = node_as_string(child[1])
26
29
  log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
30
+
27
31
  return PuppetStrings::Yard::Util.scrub_string(docstring)
28
32
  elsif child.is_a?(YARD::Parser::Ruby::MethodCallNode)
29
33
  # Look for a call to a dispatch method with a block
@@ -33,6 +37,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
33
37
 
34
38
  docstring = node_as_string(child.parameters[0])
35
39
  log.error "Failed to parse docstring for #{kind} near #{child.file}:#{child.line}." and return nil unless docstring
40
+
36
41
  return PuppetStrings::Yard::Util.scrub_string(docstring)
37
42
  end
38
43
  end
@@ -69,6 +74,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
69
74
 
70
75
  if method_name == 'newvalue'
71
76
  next unless parameters.count >= 1
77
+
72
78
  object.add(node_as_string(parameters[0]) || parameters[0].source)
73
79
  elsif method_name == 'newvalues'
74
80
  parameters.each do |p|
@@ -76,9 +82,11 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
76
82
  end
77
83
  elsif method_name == 'aliasvalue'
78
84
  next unless parameters.count >= 2
85
+
79
86
  object.alias(node_as_string(parameters[0]) || parameters[0].source, node_as_string(parameters[1]) || parameters[1].source)
80
87
  elsif method_name == 'defaultto'
81
88
  next unless parameters.count >= 1
89
+
82
90
  object.default = node_as_string(parameters[0]) || parameters[0].source
83
91
  elsif method_name == 'isnamevar'
84
92
  object.isnamevar = true
@@ -103,6 +111,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
103
111
  parameters[1].each do |kvp|
104
112
  next unless kvp.count == 2
105
113
  next unless node_as_string(kvp[0]) == 'parent'
114
+
106
115
  if kvp[1].source == 'Puppet::Parameter::Boolean'
107
116
  object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
108
117
  object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
@@ -117,19 +126,18 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
117
126
 
118
127
  def set_default_namevar(object)
119
128
  return unless object.properties || object.parameters
129
+
120
130
  default = nil
121
- if object.properties
122
- object.properties.each do |property|
131
+ object.properties&.each do |property|
123
132
  return nil if property.isnamevar
133
+
124
134
  default = property if property.name == 'name'
125
135
  end
126
- end
127
- if object.parameters
128
- object.parameters.each do |parameter|
136
+ object.parameters&.each do |parameter|
129
137
  return nil if parameter.isnamevar
138
+
130
139
  default ||= parameter if parameter.name == 'name'
131
140
  end
132
- end
133
141
  default.isnamevar = true if default
134
142
  end
135
143
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/type_base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
6
8
  # Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby.
7
9
  class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
8
10
  # The default docstring when ensurable is used without given a docstring.
9
- DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze
11
+ DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
10
12
 
11
13
  namespace_only
12
14
  handles method_call(:newparam)
@@ -31,9 +33,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
31
33
  # propertyname: "content"
32
34
 
33
35
  return unless (statement.count > 1) && (statement[0].children.count > 2)
36
+
34
37
  module_name = statement[0].children[0].source
35
38
  method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
36
- return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'
39
+ return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
37
40
 
38
41
  typename = get_name(statement[0], 'Puppet::Type.type')
39
42
  method2_name = caller_method
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/type_base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -6,7 +8,7 @@ require 'puppet-strings/yard/util'
6
8
  # Implements the handler for Puppet resource types written in Ruby.
7
9
  class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
8
10
  # The default docstring when ensurable is used without given a docstring.
9
- DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'.freeze
11
+ DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
10
12
 
11
13
  namespace_only
12
14
  handles method_call(:newtype)
@@ -14,6 +16,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
14
16
  process do
15
17
  # Only accept calls to Puppet::Type
16
18
  return unless statement.count > 1
19
+
17
20
  module_name = statement[0].source
18
21
  return unless module_name == 'Puppet::Type' || module_name == 'Type'
19
22
 
@@ -40,6 +43,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
40
43
  # Traverse the block looking for properties/parameters/features
41
44
  block = statement.block
42
45
  return unless block && block.count >= 2
46
+
43
47
  block[1].children.each do |node|
44
48
  next unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
45
49
  node.method_name
@@ -50,24 +54,31 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeHandler < PuppetStrings::Yard::Ha
50
54
  if method_name == 'newproperty'
51
55
  # Add a property to the object
52
56
  next unless parameters.count >= 1
57
+
53
58
  name = node_as_string(parameters[0])
54
59
  next unless name
60
+
55
61
  object.add_property(create_property(name, node))
56
62
  elsif method_name == 'newparam'
57
63
  # Add a parameter to the object
58
64
  next unless parameters.count >= 1
65
+
59
66
  name = node_as_string(parameters[0])
60
67
  next unless name
68
+
61
69
  object.add_parameter(create_parameter(name, node))
62
70
  elsif method_name == 'newcheck'
63
71
  # Add a check to the object
64
72
  next unless parameters.count >= 1
73
+
65
74
  name = node_as_string(parameters[0])
66
75
  next unless name
76
+
67
77
  object.add_check(create_check(name, node))
68
78
  elsif method_name == 'feature'
69
79
  # Add a feature to the object
70
80
  next unless parameters.count >= 2
81
+
71
82
  name = node_as_string(parameters[0])
72
83
  next unless name
73
84
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD parsers.
2
4
  module PuppetStrings::Yard::Parsers
3
5
  # The module for custom YARD parsers for JSON.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/parsers/json/task_statement'
2
4
 
3
5
  class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetStrings::Yard::Parsers::JSON
2
4
  # Represents the Puppet Task statement.
3
5
  class TaskStatement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet'
2
4
  require 'puppet/pops'
3
5
  require 'puppet-strings/yard/parsers/puppet/statement'
@@ -26,8 +28,8 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
26
28
  return
27
29
  end
28
30
  @statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
29
- rescue ::Puppet::ParseError => ex
30
- log.error "Failed to parse #{@file}: #{ex.message}"
31
+ rescue ::Puppet::ParseError => e
32
+ log.error "Failed to parse #{@file}: #{e.message}"
31
33
  @statements = []
32
34
  end
33
35
  @statements.freeze
@@ -42,47 +44,47 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
42
44
 
43
45
  private
44
46
 
45
- def transform_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName
47
+ def transform_Program(o)
46
48
  # Cache the lines of the source text; we'll use this to locate comments
47
49
  @lines = o.source_text.lines.to_a
48
50
  o.definitions.map { |d| @visitor.visit(d) }
49
51
  end
50
52
 
51
- def transform_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName
53
+ def transform_Factory(o)
52
54
  @visitor.visit(o.current)
53
55
  end
54
56
 
55
- def transform_HostClassDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
57
+ def transform_HostClassDefinition(o)
56
58
  statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file)
57
59
  statement.extract_docstring(@lines)
58
60
  statement
59
61
  end
60
62
 
61
- def transform_ResourceTypeDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
63
+ def transform_ResourceTypeDefinition(o)
62
64
  statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file)
63
65
  statement.extract_docstring(@lines)
64
66
  statement
65
67
  end
66
68
 
67
- def transform_FunctionDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
69
+ def transform_FunctionDefinition(o)
68
70
  statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file)
69
71
  statement.extract_docstring(@lines)
70
72
  statement
71
73
  end
72
74
 
73
- def transform_PlanDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
75
+ def transform_PlanDefinition(o)
74
76
  statement = PuppetStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file)
75
77
  statement.extract_docstring(@lines)
76
78
  statement
77
79
  end
78
80
 
79
- def transform_TypeAlias(o) # rubocop:disable Naming/UncommunicativeMethodParamName
81
+ def transform_TypeAlias(o)
80
82
  statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file)
81
83
  statement.extract_docstring(@lines)
82
84
  statement
83
85
  end
84
86
 
85
- def transform_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName
87
+ def transform_Object(o)
86
88
  # Ignore anything else (will be compacted out of the resulting array)
87
89
  end
88
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet'
2
4
  require 'puppet/pops'
3
5
 
@@ -32,11 +34,13 @@ module PuppetStrings::Yard::Parsers::Puppet
32
34
  comment = []
33
35
  (0..@line-2).reverse_each do |index|
34
36
  break unless index <= lines.count
37
+
35
38
  line = lines[index].strip
36
39
  count = line.size
37
40
  line.gsub!(COMMENT_REGEX, '')
38
41
  # Break out if nothing was removed (wasn't a comment line)
39
42
  break unless line.size < count
43
+
40
44
  comment << line
41
45
  end
42
46
  @comments_range = (@line - comment.size - 1..@line - 1)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD tags.
2
4
  module PuppetStrings::Yard::Tags
3
5
  require 'puppet-strings/yard/tags/factory'