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

Add migration check for unquoted numbers



    • New Feature
    • Status: Closed
    • Normal
    • Resolution: Done
    • None
    • PUP 3.8.0, PUP 4.1.0
    • None
    • None


      It is common to forget to quote sequences of digits intended to be strings. This is particularly bad for the order feature of the concat module (and others with similar functionality). Users write 01, 02 etc instead of '01', '02' (the order is based on strings). This works up to 07, but if user writes 08 they get an "invalid octal" error, the order for the elements 01 to 07 is however not what user intended since they are numbers, and converted to strings to produce '1', to '7' which will sort them wrong.

      The migration check is to flag all octal, hex and floating point values and warn that they are ambiguous. This will probably only result in few false positives as arithmetic on octal, hex and float values is done very infrequently (especially since File.mode now only accepts a string value).

      Add MIGRATE4_AMBIGOUS_INTEGER to MigrationIssues with the text

      "This #{radix == 8 ? 'octal' : 'hex'} value evaluates to the decimal value '#{value}': Quote if a String  value was intended (3.x bare word numbers are strings)".

      Add MIGRATE4_AMBIGOUS_FLOAT to MigrationIssues with the text "This float value parses to an imprecise floating point value. Quote if a String value was intended (3.x bare word floating point numbers are strings)".

      Add a method report_ambiguous_integer(o) to MigrationChecker and check if the semantic o is a LiteralInteger. Report if it does not have radix 10 (values in radix 10 are the same in string and integer converted to string form).

      Add a method report_ambiguous_float(o) to MigrationChecker and always report (it is somewhat difficult to find the source form and compare if the float to string is different than the original string). (Stretch goal: get the locator and extract the source, compare the float converted to a string with to_s and report if different. And if implementing the stretch goal adjust the message text to show the different values).

      Call the methods report_ambiguous_xxx from the checker4_0.rb. if the MigrationChecker is in effect. There is currently not checker methods for LiteralInteger, and LiteralFloat and these needs to be added - i.e.

      def check_LiteralInteger(o)
      def check_LiteralFloat(o)

      (Add method stubs to the MigrationChecker in the puppet repository and the concrete methods to the implementation in the module created in PUP-4149).


        Issue Links



              Unassigned Unassigned
              henrik.lindberg Henrik Lindberg
              0 Vote for this issue
              1 Start watching this issue



                Zendesk Support