-
Notifications
You must be signed in to change notification settings - Fork 743
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
properly deprecate the options hash #1187
Conversation
end | ||
|
||
return enum_for(:lex, string, opts) unless block_given? |
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.
This was the culprit for the warning.
I have updated the branch to not raise an error. However I must unconditionally warn, as it is not appropriate to swallow such errors as we have been. Your users can fix the warning by updating AsciiDoctor. I know this is not ideal for your project, @mojavelinux, but we do have other users and I would like to prevent this situation in the future. |
I can compromise on the warning. Since it's only going to happen for the PHP language (as the code in Asciidoctor stands), it's contained enough to be manageable until the new versions of Asciidoctor roll out. |
f3985b5
to
b88ca67
Compare
warn 'The use of opts with Lexer.lex is deprecated' if $VERBOSE | ||
def lex(string, opts=nil, &b) | ||
if opts | ||
if (opts.keys - [:continue]).size > 0 |
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.
You can also use Array#empty?
here:
if (opts.keys - [:continue]).size > 0 | |
unless (opts.keys - [:continue]).empty? |
@jneen Since there's a chance that |
@ashmaroli I don't think it will matter in terms of actual usage given how rare someone calling @jneen This looks fine to merge to me. Are you OK with me squashing and merging? |
Can we merge this? The current released version is very broken. Note: def lex(string, opts={}, &b)
unless opts.nil?
warn 'The use of opts with Lexer.lex is deprecated' if $VERBOSE
end the |
I'm in support of it. |
@ashmaroli while i appreciate your concern, I believe the urgency of warning at the appropriate times is a much greater concern than a possible slight performance degradation for users who have written custom lexers that use |
(for all other users, it is only a single nil check) |
87f8079
to
93191e9
Compare
Closes #1186
The warnings were being generated because of the one-step recursion in
enum_for
passing an empty options hash. Thank you @mojavelinux for spotting this.As it is now, in the common happy-path case in which no options are passed, we pay only the price of a single nil check. Otherwise, we detect the
:continue
option, which unconditionally outputs a warning. Empty hashes are only a warning with-w
, though this will become an ArgumentError in the next major version. We also properly raise an ArgumentError if invalid options are passed.