-
Notifications
You must be signed in to change notification settings - Fork 19
Fix Ensure check methods can't modify tokens array
and add Ruby 3.4 testing
#233
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
Conversation
2257895
to
ec82d69
Compare
After a bit more testing, it looks like |
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
ec82d69
to
ff0337e
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
Any progress here? I think more and more people are stumbling over this issue 🙂 |
hello, when is please planned next release of puppet-lint? |
I raised a support ticket for this: #01446430 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ensure check methods can't modify tokens array
Ensure check methods can't modify tokens array
and add Ruby 3.4 testing
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.
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.
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 incheckplugin
.Fixes #225