-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix Ensure check methods can't modify tokens array
#233
base: main
Are you sure you want to change the base?
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?
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