Class: Puppet::Pops::Validation::Checker4_0 Private

Inherits:
Evaluator::LiteralEvaluator show all
Includes:
Evaluator::ExternalSyntaxSupport
Defined in:
lib/puppet/pops/validation/checker4_0.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A Validator validates a model.

Validation is performed on each model element in isolation. Each method should validate the model element's state but not validate its referenced/contained elements except to check their validity in their respective role. The intent is to drive the validation with a tree iterator that visits all elements in a model.

TODO: Add validation of multiplicities - this is a general validation that can be checked for all

Model objects via their metamodel. (I.e an extra call to multiplicity check in polymorph check).
This is however mostly valuable when validating model to model transformations, and is therefore T.B.D

Direct Known Subclasses

TasksChecker

Constant Summary collapse

RESERVED_TYPE_NAMES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'type' => true,
  'any' => true,
  'unit' => true,
  'scalar' => true,
  'boolean' => true,
  'numeric' => true,
  'integer' => true,
  'float' => true,
  'collection' => true,
  'array' => true,
  'hash' => true,
  'tuple' => true,
  'struct' => true,
  'variant' => true,
  'optional' => true,
  'enum' => true,
  'regexp' => true,
  'pattern' => true,
  'runtime' => true,
}
FUTURE_RESERVED_WORDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'plan' => true
}
NO_NAMESPACE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:no_namespace
NO_PATH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:no_path
BAD_MODULE_FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:bad_module_file
RESERVED_PARAMETERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'name' => true,
  'title' => true,
}

Constants inherited from Evaluator::LiteralEvaluator

Evaluator::LiteralEvaluator::COMMA_SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Evaluator::ExternalSyntaxSupport

#assert_external_syntax, #checker_for_syntax, #lookup_keys_for_syntax

Methods inherited from Evaluator::LiteralEvaluator

#literal, #literal_ConcatenatedString, #literal_Factory, #literal_LiteralBoolean, #literal_LiteralDefault, #literal_LiteralHash, #literal_LiteralList, #literal_LiteralNumber, #literal_LiteralRegularExpression, #literal_LiteralString, #literal_LiteralUndef, #literal_Object, #literal_Program, #literal_QualifiedName

Constructor Details

#initialize(diagnostics_producer) ⇒ Checker4_0

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the validator with a diagnostics producer. This object must respond to `:will_accept?` and `:accept`.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/pops/validation/checker4_0.rb', line 32

def initialize(diagnostics_producer)
  super()
  @@rvalue_visitor      ||= Visitor.new(nil, "rvalue", 0, 0)
  @@hostname_visitor    ||= Visitor.new(nil, "hostname", 1, 2)
  @@assignment_visitor  ||= Visitor.new(nil, "assign", 0, 1)
  @@query_visitor       ||= Visitor.new(nil, "query", 0, 0)
  @@relation_visitor    ||= Visitor.new(nil, "relation", 0, 0)
  @@idem_visitor        ||= Visitor.new(nil, "idem", 0, 0)

  @check_visitor = self.class.check_visitor
  @acceptor = diagnostics_producer

  # Use null migration checker unless given in context
  @migration_checker = (Puppet.lookup(:migration_checker) { Migration::MigrationChecker.new() })
end

Instance Attribute Details

#acceptorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


20
21
22
# File 'lib/puppet/pops/validation/checker4_0.rb', line 20

def acceptor
  @acceptor
end

#migration_checkerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


21
22
23
# File 'lib/puppet/pops/validation/checker4_0.rb', line 21

def migration_checker
  @migration_checker
end

Class Method Details

.check_visitorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


23
24
25
26
27
# File 'lib/puppet/pops/validation/checker4_0.rb', line 23

def self.check_visitor
  # Class instance variable rather than Class variable because methods visited
  # may be overridden in subclass
  @check_visitor ||= Visitor.new(nil, 'check', 0, 0)
end

Instance Method Details

#assign(o, via_index = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks the LHS of an assignment (is it assignable?). If args is true, assignment via index is checked.


123
124
125
# File 'lib/puppet/pops/validation/checker4_0.rb', line 123

def assign(o, via_index = false)
  @@assignment_visitor.visit_this_1(self, o, via_index)
end

#assign_AccessExpression(o, via_index) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


164
165
166
167
168
169
170
171
172
# File 'lib/puppet/pops/validation/checker4_0.rb', line 164

def assign_AccessExpression(o, via_index)
  # Are indexed assignments allowed at all ? $x[x] = '...'
  if acceptor.will_accept? Issues::ILLEGAL_INDEXED_ASSIGNMENT
    acceptor.accept(Issues::ILLEGAL_INDEXED_ASSIGNMENT, o)
  else
    # Then the left expression must be assignable-via-index
    assign(o.left_expr, true)
  end
end

#assign_LiteralList(o, via_index) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


174
175
176
# File 'lib/puppet/pops/validation/checker4_0.rb', line 174

def assign_LiteralList(o, via_index)
  o.values.each {|x| assign(x) }
end

#assign_Object(o, via_index) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


178
179
180
181
182
183
# File 'lib/puppet/pops/validation/checker4_0.rb', line 178

def assign_Object(o, via_index)
  # Can not assign to anything else (differentiate if this is via index or not)
  # i.e. 10 = 'hello' vs. 10['x'] = 'hello' (the root is reported as being in error in both cases)
  #
  acceptor.accept(via_index ? Issues::ILLEGAL_ASSIGNMENT_VIA_INDEX : Issues::ILLEGAL_ASSIGNMENT, o)
end

#assign_VariableExpression(o, via_index) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

—ASSIGNMENT CHECKS


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/puppet/pops/validation/checker4_0.rb', line 148

def assign_VariableExpression(o, via_index)
  varname_string = varname_to_s(o.expr)
  if varname_string =~ Patterns::NUMERIC_VAR_NAME
    acceptor.accept(Issues::ILLEGAL_NUMERIC_ASSIGNMENT, o, :varname => varname_string)
  end
  # Can not assign to something in another namespace (i.e. a '::' in the name is not legal)
  if acceptor.will_accept? Issues::CROSS_SCOPE_ASSIGNMENT
    if varname_string =~ /::/
      acceptor.accept(Issues::CROSS_SCOPE_ASSIGNMENT, o, :name => varname_string)
    end
  end

  # TODO: Could scan for reassignment of the same variable if done earlier in the same container
  #       Or if assigning to a parameter (more work).
end

#check(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs regular validity check


65
66
67
# File 'lib/puppet/pops/validation/checker4_0.rb', line 65

def check(o)
  @check_visitor.visit_this_0(self, o)
end

#check_AccessExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


194
195
196
197
198
199
200
# File 'lib/puppet/pops/validation/checker4_0.rb', line 194

def check_AccessExpression(o)
  # Only min range is checked, all other checks are RT checks as they depend on the resulting type
  # of the LHS.
  if o.keys.size < 1
    acceptor.accept(Issues::MISSING_INDEX, o)
  end
end

#check_Application(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


202
203
204
205
# File 'lib/puppet/pops/validation/checker4_0.rb', line 202

def check_Application(o)
  check_NamedDefinition(o)
  acceptor.accept(Issues::DEPRECATED_APP_ORCHESTRATION, o, {:klass => o})
end

#check_AssignmentExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


207
208
209
210
211
212
213
214
215
216
217
# File 'lib/puppet/pops/validation/checker4_0.rb', line 207

def check_AssignmentExpression(o)
  case o.operator
  when '='
    assign(o.left_expr)
    rvalue(o.right_expr)
  when '+=', '-='
    acceptor.accept(Issues::APPENDS_DELETES_NO_LONGER_SUPPORTED, o, {:operator => o.operator})
  else
    acceptor.accept(Issues::UNSUPPORTED_OPERATOR, o, {:operator => o.operator})
  end
end

#check_AttributeOperation(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks that operation with :+> is contained in a ResourceOverride or Collector.

Parent of an AttributeOperation can be one of:

  • CollectExpression

  • ResourceOverride

  • ResourceBody (ILLEGAL this is a regular resource expression)

  • ResourceDefaults (ILLEGAL)


227
228
229
230
231
232
233
234
235
236
# File 'lib/puppet/pops/validation/checker4_0.rb', line 227

def check_AttributeOperation(o)
  if o.operator == '+>'
    # Append operator use is constrained
    p = container
    unless p.is_a?(Model::CollectExpression) || p.is_a?(Model::ResourceOverrideExpression)
      acceptor.accept(Issues::ILLEGAL_ATTRIBUTE_APPEND, o, {:name=>o.attribute_name, :parent=>p})
    end
  end
  rvalue(o.value_expr)
end

#check_AttributesOperation(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/puppet/pops/validation/checker4_0.rb', line 238

def check_AttributesOperation(o)
  # Append operator use is constrained
  p = container
  case p
  when Model::AbstractResource
  when Model::CollectExpression
  when Model::CapabilityMapping
    acceptor.accept(Issues::UNSUPPORTED_OPERATOR_IN_CONTEXT, p, :operator=>'* =>')
  else
    # protect against just testing a snippet that has no parent, error message will be a bit strange
    # but it is not for a real program.
    parent2 = p.nil? ? o : container(-2)
    unless parent2.is_a?(Model::AbstractResource)
      acceptor.accept(Issues::UNSUPPORTED_OPERATOR_IN_CONTEXT, parent2, :operator=>'* =>')
    end
  end
  rvalue(o.expr)
end

#check_BinaryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


257
258
259
260
# File 'lib/puppet/pops/validation/checker4_0.rb', line 257

def check_BinaryExpression(o)
  rvalue(o.left_expr)
  rvalue(o.right_expr)
end

#check_BlockExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/puppet/pops/validation/checker4_0.rb', line 271

def check_BlockExpression(o)
  if resource_without_title?(o)
    acceptor.accept(Issues::RESOURCE_WITHOUT_TITLE, o, :name => o.statements[0].value)
  else
    o.statements[0..-2].each do |statement|
      if idem(statement)
        acceptor.accept(Issues::IDEM_EXPRESSION_NOT_LAST, statement)
        break # only flag the first
      end
    end
  end
end

#check_CallNamedFunctionExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/puppet/pops/validation/checker4_0.rb', line 284

def check_CallNamedFunctionExpression(o)
  functor = o.functor_expr
  if functor.is_a?(Model::QualifiedReference) ||
    functor.is_a?(Model::AccessExpression) && functor.left_expr.is_a?(Model::QualifiedReference)
    # ok (a call to a type)
    return nil
  end
  case functor
  when Model::QualifiedName
    # ok
    nil
  when Model::RenderStringExpression
    # helpful to point out this easy to make Epp error
    acceptor.accept(Issues::ILLEGAL_EPP_PARAMETERS, o)
  else
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, {:feature=>'function name', :container => o})
  end
end

#check_CapabilityMapping(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/puppet/pops/validation/checker4_0.rb', line 303

def check_CapabilityMapping(o)
  acceptor.accept(Issues::DEPRECATED_APP_ORCHESTRATION, o, {:klass => o})
  ok =
  case o.component
  when Model::QualifiedReference
    name = o.component.cased_value
    acceptor.accept(Issues::ILLEGAL_CLASSREF, o.component, {:name=>name}) unless name =~ Patterns::CLASSREF_EXT
    true
  when Model::AccessExpression
    keys = o.component.keys
    expr = o.component.left_expr
    if expr.is_a?(Model::QualifiedReference) && keys.size == 1
      key = keys[0]
      key.is_a?(Model::LiteralString) || key.is_a?(Model::QualifiedName) || key.is_a?(Model::QualifiedReference)
    else
      false
    end
  else
    false
  end
  acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.component, :feature=>'capability mapping', :container => o) unless ok

  if o.capability !~ Patterns::CLASSREF_EXT
    acceptor.accept(Issues::ILLEGAL_CLASSREF, o, {:name=>o.capability})
  end
end

#check_CaseExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/puppet/pops/validation/checker4_0.rb', line 352

def check_CaseExpression(o)
  rvalue(o.test)
  # There can only be one LiteralDefault case option value
  found_default = false
  o.options.each do |option|
    option.values.each do |value|
      if value.is_a?(Model::LiteralDefault)
        # Flag the second default as 'unreachable'
        acceptor.accept(Issues::DUPLICATE_DEFAULT, value, :container => o) if found_default
        found_default = true
      end
    end
  end
end

#check_CaseOption(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


367
368
369
# File 'lib/puppet/pops/validation/checker4_0.rb', line 367

def check_CaseOption(o)
  o.values.each { |v| rvalue(v) }
end

#check_CollectExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


371
372
373
374
375
# File 'lib/puppet/pops/validation/checker4_0.rb', line 371

def check_CollectExpression(o)
  unless o.type_expr.is_a? Model::QualifiedReference
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.type_expr, :feature=> 'type name', :container => o)
  end
end

#check_EppExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


330
331
332
333
334
335
336
# File 'lib/puppet/pops/validation/checker4_0.rb', line 330

def check_EppExpression(o)
  p = container
  if p.is_a?(Model::LambdaExpression)
    internal_check_no_capture(p, o)
    internal_check_parameter_name_uniqueness(p)
  end
end

#check_Factory(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


190
191
192
# File 'lib/puppet/pops/validation/checker4_0.rb', line 190

def check_Factory(o)
  check(o.model)
end

#check_FunctionDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


484
485
486
487
488
# File 'lib/puppet/pops/validation/checker4_0.rb', line 484

def check_FunctionDefinition(o)
  check_NamedDefinition(o)
  internal_check_return_type(o)
  internal_check_parameter_name_uniqueness(o)
end

#check_HeredocExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


338
339
340
341
342
343
344
# File 'lib/puppet/pops/validation/checker4_0.rb', line 338

def check_HeredocExpression(o)
  # Only syntax check static text in heredoc during validation - dynamic text is validated by the evaluator.
  expr = o.text_expr
  if expr.is_a?(Model::LiteralString)
    assert_external_syntax(nil, expr.value, o.syntax, o.text_expr)
  end
end

#check_HostClassDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


490
491
492
493
494
495
496
# File 'lib/puppet/pops/validation/checker4_0.rb', line 490

def check_HostClassDefinition(o)
  check_NamedDefinition(o)
  internal_check_no_capture(o)
  internal_check_parameter_name_uniqueness(o)
  internal_check_reserved_params(o)
  internal_check_no_idem_last(o)
end

#check_IfExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


703
704
705
# File 'lib/puppet/pops/validation/checker4_0.rb', line 703

def check_IfExpression(o)
  rvalue(o.test)
end

#check_KeyedEntry(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


707
708
709
710
711
712
# File 'lib/puppet/pops/validation/checker4_0.rb', line 707

def check_KeyedEntry(o)
  rvalue(o.key)
  rvalue(o.value)
  # In case there are additional things to forbid than non-rvalues
  # acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.key, :feature => 'hash key', :container => container)
end

#check_LambdaExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


714
715
716
717
# File 'lib/puppet/pops/validation/checker4_0.rb', line 714

def check_LambdaExpression(o)
  internal_check_capture_last(o)
  internal_check_return_type(o)
end

#check_LiteralHash(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


730
731
732
733
734
735
736
737
738
739
# File 'lib/puppet/pops/validation/checker4_0.rb', line 730

def check_LiteralHash(o)
  # the keys of a literal hash may be non-literal expressions. They cannot be checked.
  unique = Set.new
  o.entries.each do |entry|
    catch(:not_literal) do
      literal_key = literal(entry.key)
      acceptor.accept(Issues::DUPLICATE_KEY, entry, {:key => literal_key}) if unique.add?(literal_key).nil?
    end
  end
end

#check_LiteralInteger(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


723
724
725
726
727
728
# File 'lib/puppet/pops/validation/checker4_0.rb', line 723

def check_LiteralInteger(o)
  v = o.value
  if v < MIN_INTEGER || v > MAX_INTEGER
    acceptor.accept(Issues::NUMERIC_OVERFLOW, o, {:value => v})
  end
end

#check_LiteralList(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


719
720
721
# File 'lib/puppet/pops/validation/checker4_0.rb', line 719

def check_LiteralList(o)
  o.values.each {|v| rvalue(v) }
end

#check_MethodCallExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


346
347
348
349
350
# File 'lib/puppet/pops/validation/checker4_0.rb', line 346

def check_MethodCallExpression(o)
  unless o.functor_expr.is_a? Model::QualifiedName
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, :feature => 'function name', :container => o)
  end
end

#check_NamedAccessExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Only used for function names, grammar should not be able to produce something faulty, but check anyway if model is created programmatically (it will fail in transformation to AST for sure).


379
380
381
382
383
384
# File 'lib/puppet/pops/validation/checker4_0.rb', line 379

def check_NamedAccessExpression(o)
  name = o.right_expr
  unless name.is_a? Model::QualifiedName
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, name, :feature=> 'function name', :container => container)
  end
end

#check_NamedDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

for 'class', 'define', and function


413
414
415
416
417
418
419
420
421
422
# File 'lib/puppet/pops/validation/checker4_0.rb', line 413

def check_NamedDefinition(o)
  top(o)
  if o.name !~ Patterns::CLASSREF_DECL
    acceptor.accept(Issues::ILLEGAL_DEFINITION_NAME, o, {:name=>o.name})
  end

  internal_check_file_namespace(o)
  internal_check_reserved_type_name(o, o.name)
  internal_check_future_reserved_word(o, o.name)
end

#check_NodeDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/puppet/pops/validation/checker4_0.rb', line 741

def check_NodeDefinition(o)
  # Check that hostnames are valid hostnames (or regular expressions)
  hostname(o.host_matches, o)
  top(o)
  violator = ends_with_idem(o.body)
  if violator
    acceptor.accept(Issues::IDEM_NOT_ALLOWED_LAST, violator, {:container => o}) unless resource_without_title?(violator)
  end
  unless o.parent.nil?
    acceptor.accept(Issues::ILLEGAL_NODE_INHERITANCE, o.parent)
  end
end

#check_Object(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

—CHECKS


187
188
# File 'lib/puppet/pops/validation/checker4_0.rb', line 187

def check_Object(o)
end

#check_Parameter(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


783
784
785
786
787
788
789
790
791
792
793
794
# File 'lib/puppet/pops/validation/checker4_0.rb', line 783

def check_Parameter(o)
  if o.name =~ /^(?:0x)?[0-9]+$/
    acceptor.accept(Issues::ILLEGAL_NUMERIC_PARAMETER, o, :name => o.name)
  end

  unless o.name =~ Patterns::PARAM_NAME
    acceptor.accept(Issues::ILLEGAL_PARAM_NAME, o, :name => o.name)
  end
  return unless o.value

  internal_check_illegal_assignment(o.value)
end

#check_QualifiedName(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

No checking takes place - all expressions using a QualifiedName need to check. This because the rules are slightly different depending on the container (A variable allows a numeric start, but not other names). This means that (if the lexer/parser so chooses) a QualifiedName can be anything when it represents a Bare Word and evaluates to a String.


759
760
# File 'lib/puppet/pops/validation/checker4_0.rb', line 759

def check_QualifiedName(o)
end

#check_QualifiedReference(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks that the value is a valid UpperCaseWord (a CLASSREF), and optionally if it contains a hypen. DOH: QualifiedReferences are created with LOWER CASE NAMES at parse time


764
765
766
767
768
769
# File 'lib/puppet/pops/validation/checker4_0.rb', line 764

def check_QualifiedReference(o)
  # Is this a valid qualified name?
  if o.cased_value !~ Patterns::CLASSREF_EXT
    acceptor.accept(Issues::ILLEGAL_CLASSREF, o, {:name=>o.cased_value})
  end
end

#check_QueryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


771
772
773
# File 'lib/puppet/pops/validation/checker4_0.rb', line 771

def check_QueryExpression(o)
  query(o.expr) if o.expr  # is optional
end

#check_RelationshipExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

relationship_side: resource

| resourceref
| collection
| variable
| quotedtext
| selector
| casestatement
| hasharrayaccesses

815
816
817
818
# File 'lib/puppet/pops/validation/checker4_0.rb', line 815

def check_RelationshipExpression(o)
  relation(o.left_expr)
  relation(o.right_expr)
end

#check_ReservedWord(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


856
857
858
859
860
861
862
# File 'lib/puppet/pops/validation/checker4_0.rb', line 856

def check_ReservedWord(o)
  if o.future
    acceptor.accept(Issues::FUTURE_RESERVED_WORD, o, :word => o.word)
  else
    acceptor.accept(Issues::RESERVED_WORD, o, :word => o.word)
  end
end

#check_ResourceBody(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


831
832
833
834
835
836
837
838
839
840
841
842
# File 'lib/puppet/pops/validation/checker4_0.rb', line 831

def check_ResourceBody(o)
  seenUnfolding = false
  o.operations.each do |ao|
    if ao.is_a?(Model::AttributesOperation)
      if seenUnfolding
        acceptor.accept(Issues::MULTIPLE_ATTRIBUTES_UNFOLD, ao)
      else
        seenUnfolding = true
      end
    end
  end
end

#check_ResourceDefaultsExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


844
845
846
847
848
# File 'lib/puppet/pops/validation/checker4_0.rb', line 844

def check_ResourceDefaultsExpression(o)
  if o.form != 'regular'
    acceptor.accept(Issues::NOT_VIRTUALIZEABLE, o)
  end
end

#check_ResourceExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


820
821
822
823
824
825
826
827
828
829
# File 'lib/puppet/pops/validation/checker4_0.rb', line 820

def check_ResourceExpression(o)
  # The expression for type name cannot be statically checked - this is instead done at runtime
  # to enable better error message of the result of the expression rather than the static instruction.
  # (This can be revised as there are static constructs that are illegal, but require updating many
  # tests that expect the detailed reporting).
  type_name_expr = o.type_name
  if o.form && o.form != 'regular' && type_name_expr.is_a?(Model::QualifiedName) && type_name_expr.value == 'class'
    acceptor.accept(Issues::CLASS_NOT_VIRTUALIZABLE, o)
  end
end

#check_ResourceOverrideExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


850
851
852
853
854
# File 'lib/puppet/pops/validation/checker4_0.rb', line 850

def check_ResourceOverrideExpression(o)
  if o.form != 'regular'
    acceptor.accept(Issues::NOT_VIRTUALIZEABLE, o)
  end
end

#check_ResourceTypeDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


498
499
500
501
502
503
504
# File 'lib/puppet/pops/validation/checker4_0.rb', line 498

def check_ResourceTypeDefinition(o)
  check_NamedDefinition(o)
  internal_check_no_capture(o)
  internal_check_parameter_name_uniqueness(o)
  internal_check_reserved_params(o)
  internal_check_no_idem_last(o)
end

#check_SelectorEntry(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


874
875
876
# File 'lib/puppet/pops/validation/checker4_0.rb', line 874

def check_SelectorEntry(o)
  rvalue(o.matching_expr)
end

#check_SelectorExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


864
865
866
867
868
869
870
871
872
# File 'lib/puppet/pops/validation/checker4_0.rb', line 864

def check_SelectorExpression(o)
  rvalue(o.left_expr)
  # There can only be one LiteralDefault case option value
  defaults = o.selectors.select {|v| v.matching_expr.is_a?(Model::LiteralDefault) }
  unless defaults.size <= 1
    # Flag the second default as 'unreachable'
    acceptor.accept(Issues::DUPLICATE_DEFAULT, defaults[1].matching_expr, :container => o)
  end
end

#check_SiteDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


878
879
880
# File 'lib/puppet/pops/validation/checker4_0.rb', line 878

def check_SiteDefinition(o)
  acceptor.accept(Issues::DEPRECATED_APP_ORCHESTRATION, o, {:klass => o})
end

#check_TypeAlias(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


424
425
426
427
428
429
430
431
# File 'lib/puppet/pops/validation/checker4_0.rb', line 424

def check_TypeAlias(o)
  top(o)
  if o.name !~ Patterns::CLASSREF_EXT_DECL
    acceptor.accept(Issues::ILLEGAL_DEFINITION_NAME, o, {:name=>o.name})
  end
  internal_check_reserved_type_name(o, o.name)
  internal_check_type_ref(o, o.type_expr)
end

#check_TypeDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


477
478
479
480
481
482
# File 'lib/puppet/pops/validation/checker4_0.rb', line 477

def check_TypeDefinition(o)
  top(o)
  internal_check_reserved_type_name(o, o.name)
  # TODO: Check TypeDefinition body. For now, just error out
  acceptor.accept(Issues::UNSUPPORTED_EXPRESSION, o)
end

#check_TypeMapping(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/puppet/pops/validation/checker4_0.rb', line 433

def check_TypeMapping(o)
  top(o)
  lhs = o.type_expr
  lhs_type = 0 # Not Runtime
  if lhs.is_a?(Model::AccessExpression)
    left = lhs.left_expr
    if left.is_a?(Model::QualifiedReference) && left.cased_value == 'Runtime'
      lhs_type = 1 # Runtime
      keys = lhs.keys

      # Must be a literal string or pattern replacement
      lhs_type = 2 if keys.size == 2 && pattern_with_replacement?(keys[1])
    end
  end

  if lhs_type == 0
    # This is not a TypeMapping. Something other than Runtime[] on LHS
    acceptor.accept(Issues::UNSUPPORTED_EXPRESSION, o)
  else
    rhs = o.mapping_expr
    if pattern_with_replacement?(rhs)
      acceptor.accept(Issues::ILLEGAL_SINGLE_TYPE_MAPPING, o) if lhs_type == 1
    elsif type_ref?(rhs)
      acceptor.accept(Issues::ILLEGAL_REGEXP_TYPE_MAPPING, o) if lhs_type == 2
    else
      acceptor.accept(lhs_type == 1 ? Issues::ILLEGAL_SINGLE_TYPE_MAPPING : Issues::ILLEGAL_REGEXP_TYPE_MAPPING, o)
    end
  end
end

#check_UnaryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


882
883
884
# File 'lib/puppet/pops/validation/checker4_0.rb', line 882

def check_UnaryExpression(o)
  rvalue(o.expr)
end

#check_UnlessExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


886
887
888
889
# File 'lib/puppet/pops/validation/checker4_0.rb', line 886

def check_UnlessExpression(o)
  rvalue(o.test)
  # TODO: Unless may not have an else part that is an IfExpression (grammar denies this though)
end

#check_VariableExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks that variable is either strictly 0, or a non 0 starting decimal number, or a valid VAR_NAME


892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'lib/puppet/pops/validation/checker4_0.rb', line 892

def check_VariableExpression(o)
  # The expression must be a qualified name or an integer
  name_expr = o.expr
  return if name_expr.is_a?(Model::LiteralInteger)
  if !name_expr.is_a?(Model::QualifiedName)
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, :feature => 'name', :container => o)
  else
    # name must be either a decimal string value, or a valid NAME
    name = o.expr.value
    if name[0,1] =~ /[0-9]/
      unless name =~ Patterns::NUMERIC_VAR_NAME
        acceptor.accept(Issues::ILLEGAL_NUMERIC_VAR_NAME, o, :name => name)
      end
    else
      unless name =~ Patterns::VAR_NAME
        acceptor.accept(Issues::ILLEGAL_VAR_NAME, o, :name => name)
      end
    end
  end
end

#container(index = -1)) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


60
61
62
# File 'lib/puppet/pops/validation/checker4_0.rb', line 60

def container(index = -1)
  @path[index]
end

#dir_to_names(relative_path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/puppet/pops/validation/checker4_0.rb', line 657

def dir_to_names(relative_path)
  # Downcasing here because check is case-insensitive
  path_components = relative_path.to_s.downcase.split(File::SEPARATOR)

  # Example definition dir: manifests in this path:
  # <module name>/manifests/<module subdir>/<classfile>.pp
  dir = path_components[1]

  # How can we get this result?
  # If it is not an initial manifest, it must come from a module,
  # and from the manifests dir there.  This may never get used...
  return BAD_MODULE_FILE unless dir == 'manifests' || dir == 'functions' || dir == 'types' || dir == 'plans'

  names = path_components[2 .. -2] # Directories inside module
  names.unshift(path_components[0]) # Name of the module itself

  # Do not include name of module init file at top level of module
  # e.g. <module name>/manifests/init.pp
  filename = path_components[-1]
  if !(path_components.length == 3 && filename == 'init.pp')
    names.push(filename[0 .. -4]) # Remove .pp from filename
  end

  names
end

#ends_with_idem(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the last expression in a block, or the expression, if that expression is idem


137
138
139
140
141
142
143
144
# File 'lib/puppet/pops/validation/checker4_0.rb', line 137

def ends_with_idem(o)
  if o.is_a?(Model::BlockExpression)
    last = o.statements[-1]
    idem(last) ? last : nil
  else
    idem(o) ? o : nil
  end
end

#get_module_relative_path(file_path, modulepath_directories) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


642
643
644
645
646
647
648
# File 'lib/puppet/pops/validation/checker4_0.rb', line 642

def get_module_relative_path(file_path, modulepath_directories)
  clean_file = file_path.cleanpath
  parent_path = modulepath_directories.find { |path_dir| is_parent_dir_of(path_dir, clean_file) }
  return NO_PATH if parent_path.nil?

  file_path.relative_path_from(Pathname.new(parent_path))
end

#hostname(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs check if this is a vaid hostname expression

Parameters:

  • single_feature_name (String, nil)

    the name of a single valued hostname feature of the value's container. e.g. 'parent'


71
72
73
# File 'lib/puppet/pops/validation/checker4_0.rb', line 71

def hostname(o, semantic)
  @@hostname_visitor.visit_this_1(self, o, semantic)
end

#hostname_Array(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Transforms Array of host matching expressions into a (Ruby) array of AST::HostName


916
917
918
# File 'lib/puppet/pops/validation/checker4_0.rb', line 916

def hostname_Array(o, semantic)
  o.each {|x| hostname(x, semantic) }
end

#hostname_ConcatenatedString(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


934
935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'lib/puppet/pops/validation/checker4_0.rb', line 934

def hostname_ConcatenatedString(o, semantic)
  # Puppet 3.1. only accepts a concatenated string without interpolated expressions
  the_expr = o.segments.index {|s| s.is_a?(Model::TextExpression) }
  if the_expr
    acceptor.accept(Issues::ILLEGAL_HOSTNAME_INTERPOLATION, o.segments[the_expr].expr)
  elsif o.segments.size() != 1
    # corner case, bad model, concatenation of several plain strings
    acceptor.accept(Issues::ILLEGAL_HOSTNAME_INTERPOLATION, o)
  else
    # corner case, may be ok, but lexer may have replaced with plain string, this is
    # here if it does not
    hostname_String(o.segments[0], o.segments[0])
  end
end

#hostname_LiteralDefault(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


961
962
963
# File 'lib/puppet/pops/validation/checker4_0.rb', line 961

def hostname_LiteralDefault(o, semantic)
  # always ok
end

#hostname_LiteralNumber(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


957
958
959
# File 'lib/puppet/pops/validation/checker4_0.rb', line 957

def hostname_LiteralNumber(o, semantic)
  # always ok
end

#hostname_LiteralRegularExpression(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


965
966
967
# File 'lib/puppet/pops/validation/checker4_0.rb', line 965

def hostname_LiteralRegularExpression(o, semantic)
  # always ok
end

#hostname_LiteralValue(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


930
931
932
# File 'lib/puppet/pops/validation/checker4_0.rb', line 930

def hostname_LiteralValue(o, semantic)
  hostname_String(o.value.to_s, o)
end

#hostname_Object(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


969
970
971
# File 'lib/puppet/pops/validation/checker4_0.rb', line 969

def hostname_Object(o, semantic)
  acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, {:feature => 'hostname', :container => semantic})
end

#hostname_QualifiedName(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


949
950
951
# File 'lib/puppet/pops/validation/checker4_0.rb', line 949

def hostname_QualifiedName(o, semantic)
  hostname_String(o.value.to_s, o)
end

#hostname_QualifiedReference(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


953
954
955
# File 'lib/puppet/pops/validation/checker4_0.rb', line 953

def hostname_QualifiedReference(o, semantic)
  hostname_String(o.value.to_s, o)
end

#hostname_String(o, semantic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


920
921
922
923
924
925
926
927
928
# File 'lib/puppet/pops/validation/checker4_0.rb', line 920

def hostname_String(o, semantic)
  # The 3.x checker only checks for illegal characters - if matching /[^-\w.]/ the name is invalid,
  # but this allows pathological names like "a..b......c", "----"
  # TODO: Investigate if more illegal hostnames should be flagged.
  #
  if o =~ Patterns::ILLEGAL_HOSTNAME_CHARS
    acceptor.accept(Issues::ILLEGAL_HOSTNAME_CHARS, semantic, :hostname => o)
  end
end

#idem(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if the expression has side effect ('idem' is latin for 'the same', here meaning that the evaluation state is known to be unchanged after the expression has been evaluated). The result is not 100% authoritative for negative answers since analysis of function behavior is not possible.

Returns:

  • (Boolean)

    true if expression is known to have no effect on evaluation state


132
133
134
# File 'lib/puppet/pops/validation/checker4_0.rb', line 132

def idem(o)
  @@idem_visitor.visit_this_0(self, o)
end

#idem_AccessExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1058
1059
1060
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1058

def idem_AccessExpression(o)
  true
end

#idem_ApplyExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

An apply expression exists purely for the side effect of applying a catalog somewhere, so it always has side effects


1123
1124
1125
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1123

def idem_ApplyExpression(o)
  false
end

#idem_AssignmentExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1075
1076
1077
1078
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1075

def idem_AssignmentExpression(o)
  # Always side effect
  false
end

#idem_BinaryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1062
1063
1064
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1062

def idem_BinaryExpression(o)
  true
end

#idem_BlockExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1098
1099
1100
1101
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1098

def idem_BlockExpression(o)
  # productive if there is at least one productive expression
  ! o.statements.any? {|expr| !idem(expr) }
end

#idem_CaseExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Case expression is idem, if test, and all options are idem


1132
1133
1134
1135
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1132

def idem_CaseExpression(o)
  return false if !idem(o.test)
  ! o.options.any? {|opt| !idem(opt) }
end

#idem_CaseOption(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

An option is idem if values and the then_expression are idem


1138
1139
1140
1141
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1138

def idem_CaseOption(o)
  return false if o.values.any? { |value| !idem(value) }
  idem(o.then_expr)
end

#idem_ConcatenatedString(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true even though there may be interpolated expressions that have side effect. Report as idem anyway, as it is very bad design to evaluate an interpolated string for its side effect only.


1106
1107
1108
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1106

def idem_ConcatenatedString(o)
  true
end

#idem_Factory(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1054
1055
1056
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1054

def idem_Factory(o)
  idem(o.model)
end

#idem_HeredocExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Heredoc is just a string, but may contain interpolated string (which may have side effects). This is still bad design and should be reported as idem.


1112
1113
1114
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1112

def idem_HeredocExpression(o)
  true
end

#idem_IfExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1127
1128
1129
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1127

def idem_IfExpression(o)
  [o.test, o.then_expr, o.else_expr].all? {|e| idem(e) }
end

#idem_Literal(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1042
1043
1044
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1042

def idem_Literal(o)
  true
end

#idem_LiteralHash(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1050
1051
1052
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1050

def idem_LiteralHash(o)
  true
end

#idem_LiteralList(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1046
1047
1048
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1046

def idem_LiteralList(o)
  true
end

#idem_MatchExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1066
1067
1068
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1066

def idem_MatchExpression(o)
  false # can have side effect of setting $n match variables
end

#idem_NilClass(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1038
1039
1040
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1038

def idem_NilClass(o)
  true
end

#idem_Nop(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1034
1035
1036
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1034

def idem_Nop(o)
  true
end

#idem_Object(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

–IDEM CHECK


1030
1031
1032
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1030

def idem_Object(o)
  false
end

#idem_ParenthesizedExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allow (no-effect parentheses) to be used around a productive expression


1086
1087
1088
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1086

def idem_ParenthesizedExpression(o)
  idem(o.expr)
end

#idem_RelationshipExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1070
1071
1072
1073
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1070

def idem_RelationshipExpression(o)
  # Always side effect
  false
end

#idem_RenderExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1090
1091
1092
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1090

def idem_RenderExpression(o)
  false
end

#idem_RenderStringExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1094
1095
1096
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1094

def idem_RenderStringExpression(o)
  false
end

#idem_SelectorExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

May technically have side effects inside the Selector, but this is bad design - treat as idem


1117
1118
1119
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1117

def idem_SelectorExpression(o)
  true
end

#idem_UnaryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handles UnaryMinusExpression, NotExpression, VariableExpression


1081
1082
1083
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1081

def idem_UnaryExpression(o)
  true
end

#initial_manifest?(path, manifest_setting) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

634
635
636
637
638
639
640
# File 'lib/puppet/pops/validation/checker4_0.rb', line 634

def initial_manifest?(path, manifest_setting)
  return false if manifest_setting.nil? || manifest_setting == :no_manifest

  string_path = path.to_s

  string_path == manifest_setting || string_path.start_with?(manifest_setting)
end

#internal_check_capture_last(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


527
528
529
530
531
532
533
534
# File 'lib/puppet/pops/validation/checker4_0.rb', line 527

def internal_check_capture_last(o)
  accepted_index = o.parameters.size() -1
  o.parameters.each_with_index do |p, index|
    if p.captures_rest && index != accepted_index
      acceptor.accept(Issues::CAPTURES_REST_NOT_LAST, p, {:param_name => p.name})
    end
  end
end

#internal_check_file_namespace(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/puppet/pops/validation/checker4_0.rb', line 560

def internal_check_file_namespace(o)
  file = o.locator.file
  return if file.nil? || file == '' #e.g. puppet apply -e '...'

  file_namespace = namespace_for_file(file)
  return if file_namespace == NO_NAMESPACE

  # Downcasing here because check is case-insensitive
  if file_namespace == BAD_MODULE_FILE || !o.name.downcase.start_with?(file_namespace)
    acceptor.accept(Issues::ILLEGAL_DEFINITION_LOCATION, o, {:name => o.name, :file => file})
  end
end

#internal_check_future_reserved_word(o, name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


550
551
552
553
554
# File 'lib/puppet/pops/validation/checker4_0.rb', line 550

def internal_check_future_reserved_word(o, name)
  if FUTURE_RESERVED_WORDS[name]
    acceptor.accept(Issues::FUTURE_RESERVED_WORD, o, {:word => name})
  end
end

#internal_check_illegal_assignment(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


796
797
798
799
800
801
802
803
804
# File 'lib/puppet/pops/validation/checker4_0.rb', line 796

def internal_check_illegal_assignment(o)
  if o.is_a?(Model::AssignmentExpression)
    acceptor.accept(Issues::ILLEGAL_ASSIGNMENT_CONTEXT, o)
  else
    # recursively check all contents unless it's a lambda expression. A lambda may contain
    # local assignments
    o._pcore_contents {|model| internal_check_illegal_assignment(model) } unless o.is_a?(Model::LambdaExpression)
  end
end

#internal_check_no_capture(o, container = o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


536
537
538
539
540
541
542
# File 'lib/puppet/pops/validation/checker4_0.rb', line 536

def internal_check_no_capture(o, container = o)
  o.parameters.each do |p|
    if p.captures_rest
      acceptor.accept(Issues::CAPTURES_REST_NOT_SUPPORTED, p, {:container => container, :param_name => p.name})
    end
  end
end

#internal_check_no_idem_last(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


520
521
522
523
524
525
# File 'lib/puppet/pops/validation/checker4_0.rb', line 520

def internal_check_no_idem_last(o)
  violator = ends_with_idem(o.body)
  if violator
    acceptor.accept(Issues::IDEM_NOT_ALLOWED_LAST, violator, {:container => o}) unless resource_without_title?(violator)
  end
end

#internal_check_parameter_name_uniqueness(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


696
697
698
699
700
701
# File 'lib/puppet/pops/validation/checker4_0.rb', line 696

def internal_check_parameter_name_uniqueness(o)
  unique = Set.new
  o.parameters.each do |p|
    acceptor.accept(Issues::DUPLICATE_PARAMETER, p, {:param_name => p.name}) unless unique.add?(p.name)
  end
end

#internal_check_reserved_params(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


688
689
690
691
692
693
694
# File 'lib/puppet/pops/validation/checker4_0.rb', line 688

def internal_check_reserved_params(o)
  o.parameters.each do |p|
    if RESERVED_PARAMETERS[p.name]
      acceptor.accept(Issues::RESERVED_PARAMETER, p, {:container => o, :param_name => p.name})
    end
  end
end

#internal_check_reserved_type_name(o, name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


544
545
546
547
548
# File 'lib/puppet/pops/validation/checker4_0.rb', line 544

def internal_check_reserved_type_name(o, name)
  if RESERVED_TYPE_NAMES[name]
    acceptor.accept(Issues::RESERVED_TYPE_NAME, o, {:name => name})
  end
end

#internal_check_return_type(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


506
507
508
509
# File 'lib/puppet/pops/validation/checker4_0.rb', line 506

def internal_check_return_type(o)
  r = o.return_type
  internal_check_type_ref(o, r) unless r.nil?
end

#internal_check_top_construct_in_module(prog) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/puppet/pops/validation/checker4_0.rb', line 573

def internal_check_top_construct_in_module(prog)
  return unless prog.is_a?(Model::Program) && !prog.body.nil?

  #Check that this is a module autoloaded file
  file = prog.locator.file
  return if file.nil?
  return if namespace_for_file(file) == NO_NAMESPACE

  body = prog.body
  return if prog.body.is_a?(Model::Nop) #Ignore empty or comment-only files

  if(body.is_a?(Model::BlockExpression))
    body.statements.each { |s| acceptor.accept(Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION, s) unless valid_top_construct?(s) }
  else
    acceptor.accept(Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION, body) unless valid_top_construct?(body)
  end
end

#internal_check_type_ref(o, r) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


511
512
513
514
515
516
517
518
# File 'lib/puppet/pops/validation/checker4_0.rb', line 511

def internal_check_type_ref(o, r)
  n = r.is_a?(Model::AccessExpression) ? r.left_expr : r
  if n.is_a? Model::QualifiedReference
    internal_check_future_reserved_word(r, n.value)
  else
    acceptor.accept(Issues::ILLEGAL_EXPRESSION, r, :feature => 'a type reference', :container => o)
  end
end

#is_parent_dir_of(parent_dir, child_dir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


650
651
652
653
654
655
# File 'lib/puppet/pops/validation/checker4_0.rb', line 650

def is_parent_dir_of(parent_dir, child_dir)
  parent_dir_path = Pathname.new(parent_dir)
  clean_parent = parent_dir_path.cleanpath.to_s + File::SEPARATOR

  return child_dir.to_s.start_with?(clean_parent)
end

#namespace_for_file(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/puppet/pops/validation/checker4_0.rb', line 606

def namespace_for_file(file)
  env = Puppet.lookup(:current_environment)
  return NO_NAMESPACE if env.nil?

  adapter = Puppet::Util::FileNamespaceAdapter.adapt(env)

  file_namespace = adapter.file_to_namespace[file]
  return file_namespace unless file_namespace.nil? # No cache entry, so we do the calculation

  path = Pathname.new(file)

  return adapter.file_to_namespace[file] = NO_NAMESPACE if path.extname != ".pp"

  path = path.expand_path

  return adapter.file_to_namespace[file] = NO_NAMESPACE if initial_manifest?(path, env.manifest)

  #All auto-loaded files from modules come from a module search path dir
  relative_path = get_module_relative_path(path, env.full_modulepath)

  return adapter.file_to_namespace[file] = NO_NAMESPACE if relative_path == NO_PATH

  #If a file comes from a module, but isn't in the right place, always error
  names = dir_to_names(relative_path)

  return adapter.file_to_namespace[file] = (names == BAD_MODULE_FILE ? BAD_MODULE_FILE : names.join("::").freeze)
end

#pattern_with_replacement?(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

463
464
465
466
467
468
469
470
# File 'lib/puppet/pops/validation/checker4_0.rb', line 463

def pattern_with_replacement?(o)
  if o.is_a?(Model::LiteralList)
    v = o.values
    v.size == 2 && v[0].is_a?(Model::LiteralRegularExpression) && v[1].is_a?(Model::LiteralString)
  else
    false
  end
end

#query(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs check if this is valid as a query


76
77
78
# File 'lib/puppet/pops/validation/checker4_0.rb', line 76

def query(o)
  @@query_visitor.visit_this_0(self, o)
end

#query_BooleanExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Allows AND, OR, and checks if left/right are allowed in query.


987
988
989
990
# File 'lib/puppet/pops/validation/checker4_0.rb', line 987

def query_BooleanExpression(o)
  query o.left_expr
  query o.right_expr
end

#query_ComparisonExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Puppet AST only allows == and !=


982
983
984
# File 'lib/puppet/pops/validation/checker4_0.rb', line 982

def query_ComparisonExpression(o)
  acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o) unless ['==', '!='].include? o.operator
end

#query_LiteralBoolean(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1004
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1004

def query_LiteralBoolean(o); end

#query_LiteralNumber(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1000
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1000

def query_LiteralNumber(o); end

#query_LiteralString(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1002
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1002

def query_LiteralString(o); end

#query_Object(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Anything not explicitly allowed is flagged as error.


976
977
978
# File 'lib/puppet/pops/validation/checker4_0.rb', line 976

def query_Object(o)
  acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o)
end

#query_ParenthesizedExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


992
993
994
# File 'lib/puppet/pops/validation/checker4_0.rb', line 992

def query_ParenthesizedExpression(o)
  query(o.expr)
end

#query_QualifiedName(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


998
# File 'lib/puppet/pops/validation/checker4_0.rb', line 998

def query_QualifiedName(o); end

#query_VariableExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


996
# File 'lib/puppet/pops/validation/checker4_0.rb', line 996

def query_VariableExpression(o); end

#relation(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs check if this is valid as a relationship side


81
82
83
# File 'lib/puppet/pops/validation/checker4_0.rb', line 81

def relation(o)
  @@relation_visitor.visit_this_0(self, o)
end

#relation_CollectExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


779
# File 'lib/puppet/pops/validation/checker4_0.rb', line 779

def relation_CollectExpression(o); end

#relation_Object(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


775
776
777
# File 'lib/puppet/pops/validation/checker4_0.rb', line 775

def relation_Object(o)
  rvalue(o)
end

#relation_RelationshipExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


781
# File 'lib/puppet/pops/validation/checker4_0.rb', line 781

def relation_RelationshipExpression(o); end

#resource_without_title?(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

262
263
264
265
266
267
268
269
# File 'lib/puppet/pops/validation/checker4_0.rb', line 262

def resource_without_title?(o)
  if o.instance_of?(Model::BlockExpression)
    statements = o.statements
    statements.length == 2 && statements[0].instance_of?(Model::QualifiedName) && statements[1].instance_of?(Model::LiteralHash)
  else
    false
  end
end

#rvalue(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs check if this is valid as a rvalue


86
87
88
# File 'lib/puppet/pops/validation/checker4_0.rb', line 86

def rvalue(o)
  @@rvalue_visitor.visit_this_0(self, o)
end

#rvalue_CollectExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1013
1014
1015
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1013

def rvalue_CollectExpression(o)
  acceptor.accept(Issues::NOT_RVALUE, o)
end

#rvalue_Definition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1017
1018
1019
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1017

def rvalue_Definition(o)
  acceptor.accept(Issues::NOT_RVALUE, o)
end

#rvalue_Expression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

By default, all expressions are reported as being rvalues Implement specific rvalue checks for those that are not.


1011
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1011

def rvalue_Expression(o); end

#rvalue_NodeDefinition(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1021
1022
1023
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1021

def rvalue_NodeDefinition(o)
  acceptor.accept(Issues::NOT_RVALUE, o)
end

#rvalue_UnaryExpression(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


1025
1026
1027
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1025

def rvalue_UnaryExpression(o)
  rvalue o.expr
end

#top(definition, idx = -1)) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

—TOP CHECK Performs check if this is valid as a container of a definition (class, define, node)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/puppet/pops/validation/checker4_0.rb', line 92

def top(definition, idx = -1)
  o = container(idx)
  idx -= 1
  case o
  when NilClass, Model::ApplyExpression, Model::HostClassDefinition, Model::Program
    # ok, stop scanning parents
  when Model::BlockExpression
    c = container(idx)
    if !c.is_a?(Model::Program) &&
      (definition.is_a?(Model::FunctionDefinition) || definition.is_a?(Model::TypeAlias) || definition.is_a?(Model::TypeDefinition))

      # not ok. These can never be nested in a block
      acceptor.accept(Issues::NOT_ABSOLUTE_TOP_LEVEL, definition)
    else
      # ok, if this is a block representing the body of a class, or is top level
      top(definition, idx)
    end
  when Model::LambdaExpression
    # A LambdaExpression is a BlockExpression, and this check is needed to prevent the polymorph method for BlockExpression
    # to accept a lambda.
    # A lambda can not iteratively create classes, nodes or defines as the lambda does not have a closure.
    acceptor.accept(Issues::NOT_TOP_LEVEL, definition)
  else
    # fail, reached a container that is not top level
    acceptor.accept(Issues::NOT_TOP_LEVEL, definition)
  end
end

#type_ref?(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

472
473
474
475
# File 'lib/puppet/pops/validation/checker4_0.rb', line 472

def type_ref?(o)
  o = o.left_expr if o.is_a?(Model::AccessExpression)
  o.is_a?(Model::QualifiedReference)
end

#valid_top_construct?(o) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

591
592
593
# File 'lib/puppet/pops/validation/checker4_0.rb', line 591

def valid_top_construct?(o)
  o.is_a?(Model::Definition) && !o.is_a?(Model::NodeDefinition)
end

#validate(model) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validates the entire model by visiting each model element and calling `check`. The result is collected (or acted on immediately) by the configured diagnostic provider/acceptor given when creating this Checker.


52
53
54
55
56
57
58
# File 'lib/puppet/pops/validation/checker4_0.rb', line 52

def validate(model)
  # tree iterate the model, and call check for each element
  @path = []
  check(model)
  internal_check_top_construct_in_module(model)
  model._pcore_all_contents(@path) { |element| check(element) }
end

#varname_to_s(o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Produces string part of something named, or nil if not a QualifiedName or QualifiedReference


1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
# File 'lib/puppet/pops/validation/checker4_0.rb', line 1147

def varname_to_s(o)
  case o
  when Model::QualifiedName
    o.value
  when Model::QualifiedReference
    o.value
  else
    nil
  end
end