The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

Bug #10506

Naming rules are inconsistent

Added by Henrik Lindberg almost 3 years ago. Updated about 1 year ago.

Status:AcceptedStart date:11/03/2011
Priority:UrgentDue date:
Assignee:eric sorenson% Done:

0%

Category:language
Target version:3.x
Affected Puppet version: Branch:
Keywords:usability syntax

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com

This ticket may be automatically exported to the PUP project on JIRA using the button below:


Description

The rules for naming of classes is inconsistently applied to different language concepts.

  • It is allowed to name a class using NUMBER (e.g. ‘0’, ‘0.0’, ‘0477’, ‘0x1f’, ‘1.3e-2’).
  • A dollar variable is parsed with the regular expression %r{\$(::)?([-\w]+::)*[-\w]+} and can thus never refer to a variable in a class named with a ‘.’ (period) in the name. (Update: A hyphen in the variable is no longer allowed, in 3.x it is gone in the regexp, and in 2.7.20? it is possible to turn it on, but also getting a deprecation warning).
  • A NAME, CLASSREF, or CLASSNAME is parsed with%r{((::)?[a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*} and can also not contain a ‘.’ (period). Update, now that hyphens in variables are not allowed, it should also be disallowed in names.
  • Regular expression matching injects values into variables $0$n (although not directly clashing since a class is typically not referenced with a variable, it is still confusing to see say $0::1, when $0 is a regexp match)
  • Class defaults can be set using a class reference (each segment starts with upper case letter in a fully qualified name), this is strange when name is numeric (how do you write an upper case ‘1’?). Compare:

using words:

class one($a) { class two($b) {} }
One { a=>10 }
One::Two {b=>20}

using numbers:

class 1($a) { class 2($b) {} }
1 { a=>10 }
1::2 {b=>20}

The second example (naturally) results in:

Could not parse for environment production: All resource specifications require names at /private/tmp/test.pp:2 on node xxx
  • A separate issue is that assignment to $0$n may not take effect (the variable is still undefined) in some cases.
  • The documentation does not seem to mention the fact that classes may have numerical names (the stricter rules are shown in several places).

I suggest that: * Numerical names should be deprecated * Assignment to $0$n should be illegal (reserved for regular expression matches)

In contrast, if trying to fix this by adding ‘.’ (period) as valid in variables, a lot of string interpolation will break (in similar ways to how the altered string interpolation rules regarding ‘–’ (hyphen) breaks existing code). The interpolation issues could be resolved by deprecating the interpolation short form (i.e. interpolating without braces), but that may be considered a more serious imposition (even if recommended as best practice) – i.e. that "Hello $name" must be written "Hello ${name}".

It seems like 2.8 would be a good candidate for more stringent rules since dynamic scoping of variables will be deprecated and people do have to inspect their code and deal with naming/reference issues.

The rules in the documentation has been updated and now state that variables may be capitalized. Thus $Boo is allowed, but since a qualified name must have segments that start with lower case, this only applied to the last part of the name – i.e. $Foo::Bar is not accepted. When variables are used to define parameters, they may not be capitalized (since the rsource instance statement does not allow upper case attribute names. This is inconsistent and it would be best if capitalize variable names were not allowed.


Related issues

Related to Puppet - Bug #902: Qualified-variable names cannot contain hyphens (but clas... Duplicate
Related to Puppet - Bug #7523: Refactor the grammar to reduce duplication Closed 05/13/2011
Related to Puppet - Bug #5268: hyphen in class name messes with qualified variables Re-opened 11/11/2010
Related to Puppet - Bug #1274: class names cannot begin with a digit Closed
Related to Puppet - Bug #3129: Problem using a number as as class name Accepted 01/30/2010
Related to Puppet - Feature #17260: Optional deprecation warning for hyphens in names Closed
Related to Puppet - Bug #22442: puppet-3.2.4 future parser Puppet::Pops::Issues::ILLEGAL_... Closed
Duplicated by Puppet - Bug #16618: puppet allows numeric variable names that can not be used Duplicate 09/27/2012

History

#1 Updated by James Turnbull almost 3 years ago

  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Nigel Kersten

#2 Updated by Nigel Kersten over 2 years ago

  • Status changed from Needs Decision to Accepted
  • Assignee deleted (Nigel Kersten)
  • Priority changed from Normal to Urgent
  • Target version set to 3.x

#3 Updated by eric sorenson about 2 years ago

  • Assignee set to eric sorenson

Taking ownership of this as part of #5268 — Henrik, thank you for the analysis.

#4 Updated by Henrik Lindberg almost 2 years ago

  • Description updated (diff)

Updated description now that hyphens in variables are deprecated in 2.7.x and not allowed in 3.x.

#5 Updated by Erik Dalén over 1 year ago

Oddly you are allowed to name a class “class”, but then you can only include it if you quote it before passing to include function. According to documentation it should not be allowed to name a class to a reserved word such as “class”.

#6 Updated by Henrik Lindberg about 1 year ago

  • Description updated (diff)

Also available in: Atom PDF