Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error on Pattern data type #833

Closed
fuero opened this issue Sep 12, 2018 · 2 comments · Fixed by #835
Closed

Syntax error on Pattern data type #833

fuero opened this issue Sep 12, 2018 · 2 comments · Fixed by #835
Labels

Comments

@fuero
Copy link

fuero commented Sep 12, 2018

Update: I guess it's connected to (?x), as this works fine if the pattern is put on a single line.

Puppet-Lint chokes on the following type alias:

type Profiles::Ensure::Package = Variant[
  Enum['present', 'installed', 'absent', 'purged', 'held', 'latest'],
  # Fedora/EL Version scheme (NE)VRA
  Pattern[/(?x)
  ^
    (?:\d+\.)+\d+           # Regular version number part (0.1.0.0.x)
    -\d+                    # Release
    (?:\.[A-Za-z0-9]+)?     # custom suffix e.g. .20180917gitabcdef1
    (?:\.el\d(?:\.\d+)?)?   # distro suffix e.g. el7, el7.2
  $
  /]
]

Running the validator works without complaint, as do the unit tests I wrote for this.

$ puppet parser validate --verbose types/ensure/package.pp
$

Puppet-Lint does complain:

$ puppet-lint types/ensure/package.pp
ERROR: Syntax error on line 5
Try running `puppet parser validate <file>`

Versions:

$ puppet-lint --version
puppet-lint 2.3.6
$ puppet --version
5.5.6
$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ lsb_release -a
LSB Version:	1.4
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a
@jcbollinger
Copy link
Contributor

jcbollinger commented Sep 17, 2018

I have observed the same issue. I'm using puppet-lint 2.3.6, as packaged (twice) in the Puppet Development Kit v1.7. I concur that the problem seems to be associated with patterns that extend across multiple lines, as is enabled by turning on the x flag. Joining the lines of each pattern into one has been a viable workaround for me.

I encountered it with type definitions, just as reported above. The affected types were accepted by several different revisions of Puppet 1.5.x, and they appear to have worked as intended, but puppet-lint rejected them altogether as containing syntax errors.

@jcbollinger
Copy link
Contributor

jcbollinger commented Sep 17, 2018

Looking at the code, puppet-lint appears universally to reject regular expressions containing newlines (not just in the declarations of Pattern types). It even has a unit test for that behavior. Ruby and therefore Puppet unconditionally accept newlines in patterns, however, whether the x option is in effect or not.

jcbollinger added a commit to jcbollinger/puppet-lint that referenced this issue Sep 17, 2018
Modified the lexer to make it recognize regular expressions that contain
newlines.  Replaced a unit test that checked for the opposite behavior,
and added a test for distinguishing between the division operator and
a regex delimiter.

Resolves rodjek#833
@rodjek rodjek added the bug label Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants