puppetlabs / puppetlabs/puppet-strings

Default value expressions are returned incorrectly

Open
#240 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bugfix
Dominant language
Ruby
Stars
90
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Describe the Bug

Complex parameter default expressions (specifically those involving an AST branch node) are returned incorrectly.

For example:

class test($param = 1 + 1) { ... }

The default value for $param is returned as +.

Expected Behavior

The default value should be returned as 1 + 1.

Additional Context

This seems to happen because ParameterizedStatement parser uses a SourcePosAdapter from Puppet to extract the text for the AST object. However, the extract_text method it calls only extracts the text for the AST branch itself, not for the entire tree rooted in that branch. The SourcePosAdapter calls @object.locator.extract_text, but there is an extract_tree_text method available on the locator which seems to do the right thing.

https://github.com/puppetlabs/puppet-strings/blob/main/lib/puppet-strings/yard/parsers/puppet/statement.rb#L89-L90
https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/adapters.rb#L63
https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/locator.rb#L55

I would file a PR but I'm not deep enough into puppet-strings to understand its relationship to Puppet and the compatibility issues involved with the SourcePosAdapter to know the appropriate place to make this change.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read lib/puppet-strings/yard/parsers/puppet/statement.rb at lines 89-90, then compare Puppet's SourcePosAdapter and locator methods referenced in the issue. Trace how the default expression in class test($param = 1 + 1) is extracted; done means the returned value includes the full 1 + 1 expression without breaking Puppet compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.