Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-4125

Add migration check for upper case bare word evaluation

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: PUP 3.8.0, PUP 4.1.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2015-04-01

      Description

      Rationale


      This migration check is of value since it is a common mistake to use an uppercase bare word e.g. Debian with the intent that this is a String when it in 4.0 is an instance of Type.

      Note that not all usage of UC bareword can be flagged, since they appear as types also in 3x (i.e. references to either a resource type e.g. File, or as a reference to a specific resource e.g. File[foo]).

      Instead we need to check the evaluated result of case/selector options, and report if the result is a Type instance. We do the same for evaluation of comparison expressions

      ==, !=, <, >, <=, =>
      

      as 3.x puppet code never compare on type. We also need to check the LHS of

      =~  and !~
      

      if it is a Type instance. In these cases we report the location of the operator (since we otherwise would have to track deeply where a value came from in the LHS and RHS expressions) - the user should be able to figure it out (and most will be immediate operands so problem is easy to spot).

      It is not anticipated that users have a frequent reason to place puppet resource type references in arrays or hashes - thus the intent is most likely that they should be quoted. There are valid cases though when relationships are formed:

      e.g - something like this:

      $a = [ MyType, MyType::Special ]
      $b = [ MyOtherType, MyOtherType::Special ]

      $a -> $b

      It would be irritating to be told to quote those UC bare words (it would be wrong). Instead, since we are instrumenting comparison and matching evaluation we will catch cases where such structures are used in conditionals (which is really what we care about).

      This will also catch use of the in operator with a LHS being an UC bareword since in uses the implementation of the comparison operators.

      Implementation


      Add the issue MIGRATE4_UC_BAREWORD_IS_TYPE to MigrationIssues with the text

      "Upper cased non quoted word '#{word}' evaluates to a Type (3.x evaluates to a String)"
      

      Add a method report_uc_bareword_type(value, o) where o is the semantic object to the MigrationChecker that checks and reports if the value is a type instance.

      Add calls to the report_uc_bareword_type method from all comparison operators, equality operators, match operators, case and selector option evaluation, and in operator (some of these are probably already covered by the equality and comparison operators).

      (Add API stubs to the MigrationChecker in the puppet repository, and the specific methods to the implementation in the module created in PUP-4149).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                henrik.lindberg Henrik Lindberg
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support