Skip to content

Conversation

alexjfisher
Copy link

@alexjfisher alexjfisher commented Feb 8, 2025

The functionality originally released in rodjek#296 was probably broken at the time, possibly made worse by later rubocop 'fixes' and also incompatible with ruby 3.4.

We now look at the stack trace only from the tokens wrapper method in checkplugin.

Fixes #225

@alexjfisher alexjfisher requested review from a team and bastelfreak as code owners February 8, 2025 18:15
@alexjfisher alexjfisher force-pushed the fix_duplicated_tokens branch from 2257895 to ec82d69 Compare February 8, 2025 18:17
@alexjfisher alexjfisher marked this pull request as draft February 8, 2025 22:13
@alexjfisher
Copy link
Author

After a bit more testing, it looks like label behaves differently across ruby versions...

@alexjfisher
Copy link
Author

@bastelfreak
Copy link
Collaborator

lol

The functionality originally released in rodjek#296
was probably broken at the time, possibly made worse by later rubocop
'fixes' and also incompatible with ruby 3.4.

We now look at the stack trace only from the `tokens` wrapper method in
`checkplugin`.

Fixes puppetlabs#225
Copy link

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the short term this is correct, but it may be worth looking ahead to what the API should be.

@tokens
end
def tokens(duplicate: false)
duplicate ? @tokens.dup : @tokens
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a crazy thought: rather than duplicating, would it make sense to freeze it? https://rubyapi.org/o/array#method-i-freeze says it will not do anything if already frozen, so should be cheap and you can't modify it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There wasn't much information I could find about to why this was originally introduced, but other methods (such as fix) definitely do need to be able to modify the array.

end

def fix
tokens << :fix_token
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is supposed to be a valid API because there's also the add_token to actually modify it.

def check
# Since we're calling `tokens` from a `check` method, we should get our own Array object.
# If we add an extra token to it, PuppetLint::Data.tokens should remain unchanged.
tokens << :extra_token
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When returning a frozen array it will raise a FrozenError. Perhaps we should catch that and raise a deprecation warning?

@der-eismann
Copy link

Any progress here? I think more and more people are stumbling over this issue 🙂

@michal9223
Copy link

hello, when is please planned next release of puppet-lint?
will this fix be added there?
thanks a lot

@bastelfreak
Copy link
Collaborator

I raised a support ticket for this: #01446430

Copy link

@LukasAud LukasAud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LukasAud LukasAud merged commit 8c78d36 into puppetlabs:main Sep 25, 2025
9 of 10 checks passed
@LukasAud LukasAud added bugfix feature New feature or request and removed bugfix labels Sep 25, 2025
@LukasAud LukasAud changed the title Fix Ensure check methods can't modify tokens array Fix Ensure check methods can't modify tokens array and add Ruby 3.4 testing Sep 25, 2025
@LukasAud LukasAud mentioned this pull request Sep 25, 2025
5 tasks
bastelfreak added a commit to bastelfreak/voxpupuli-puppet-lint-plugins that referenced this pull request Sep 25, 2025
This pulls in three bigger changes in puppet-lint:
* Avoid using the manifest lexer on YAML [#239](puppetlabs/puppet-lint#239) (tokenrove)
* Add abstract data types to lexer type tokens list [#240](puppetlabs/puppet-lint#240) (kenyon)
* Fix Ensure check methods can't modify tokens array and add Ruby 3.4 testing [#233](puppetlabs/puppet-lint#233) (alexjfisher)

In a previous PR, voxpupuli#64, we switched to Ruby 3.2 as a minimal Ruby version.
The new puppet-lint release did a Ruby version bump.
We don't want to end up in a situation where different users have
different ruby versions, which leads to different puppet-lint versions,
which leads to different linting of your puppet code.

Because of that, we cannot allow puppet-lint 4 & 5, but have to pint to
5.1 (5.0 doesn't support Ruby 3.4).

All puppet-lint plugins were also updated for puppet-lint 5.1, which
also required major releases.
bastelfreak added a commit to bastelfreak/voxpupuli-puppet-lint-plugins that referenced this pull request Sep 25, 2025
This pulls in three bigger changes in puppet-lint:
* Avoid using the manifest lexer on YAML [#239](puppetlabs/puppet-lint#239) (tokenrove)
* Add abstract data types to lexer type tokens list [#240](puppetlabs/puppet-lint#240) (kenyon)
* Fix Ensure check methods can't modify tokens array and add Ruby 3.4 testing [#233](puppetlabs/puppet-lint#233) (alexjfisher)

In a previous PR, voxpupuli#64, we switched to Ruby 3.2 as a minimal Ruby version.
The new puppet-lint release did a Ruby version bump.
We don't want to end up in a situation where different users have
different ruby versions, which leads to different puppet-lint versions,
which leads to different linting of your puppet code.

Because of that, we cannot allow puppet-lint 4 & 5, but have to pint to
5.1 (5.0 doesn't support Ruby 3.4).

All puppet-lint plugins were also updated for puppet-lint 5.1, which
also required major releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoMethodError: undefined method '[]' for nil with ruby3.4.0dev

7 participants