Skip to content
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 Ruby 2.7 keyword parameter deprecation warning #1597

Merged
merged 1 commit into from Jan 27, 2021

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Sep 28, 2020

This fixes the warning:

lib/rouge/formatter.rb:46: warning: Using the last argument as
keyword parameters is deprecated; maybe ** should be added to the call

More details:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

lib/rouge/formatter.rb Outdated Show resolved Hide resolved
@@ -42,8 +42,8 @@ def self.disable_escape!
end

# Format a token stream. Delegates to {#format}.
def self.format(tokens, *a, &b)
new(*a).format(tokens, &b)
def self.format(tokens, *args, **kwargs, &b)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what pattern is this. It does seem like opts is actually a Hash in some cases?

html_inline.rb:      def initialize(theme)
html_legacy.rb:      def initialize(opts={})
html_line_table.rb:      def initialize(formatter, opts={})
html_linewise.rb:      def initialize(formatter, opts={})
html_pygments.rb:      def initialize(inner, css_class='codehilite')
html_table.rb:      def initialize(inner, opts={})
null.rb:      def initialize(*)
terminal256.rb:      def initialize(theme = Themes::ThankfulEyes.new)
terminal256.rb:        def initialize(style)
terminal256.rb:        def initialize(*) end
tex.rb:      def initialize(opts={})

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the heads-up!

The arguments passed to .format should be the same ones passed to the initializer of the class - which is left completely free and is not always an options hash. Unlike lexers, formatters are solidified in code - and don't need fancy CGI-like parsing. In any case, this method should probably just blindly pass through everything - positional, keywords, and block arguments - to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jneen Good to hear from you! Ok, I kept going back and forth because I wasn't sure what the actual intent. Thanks for the response! I hope you are well.

This fixes the warning:

```
lib/rouge/formatter.rb:46: warning: Using the last argument as
keyword parameters is deprecated; maybe ** should be added to the call
```

More details:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

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

@jneen Looks good to me. Are you happy for this to be merged?

@pyrmont pyrmont self-assigned this Oct 13, 2020
@pyrmont pyrmont added the maintainer-action The PR has been reviewed but action by a maintainer is required label Oct 13, 2020
@pyrmont pyrmont removed their assignment Dec 9, 2020
@tancnle
Copy link
Collaborator

tancnle commented Dec 22, 2020

@jneen Gentle nudge 😸. Is it possible to have this merged? 🙏

@dblessing
Copy link
Collaborator

Seems like this has had plenty of eyes and no concerns so far. I'm merging. Thanks @stanhu

@dblessing dblessing merged commit 1e246d1 into rouge-ruby:master Jan 27, 2021
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
This fixes the warning:

```
lib/rouge/formatter.rb:46: warning: Using the last argument as
keyword parameters is deprecated; maybe ** should be added to the call
```

More details:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer-action The PR has been reviewed but action by a maintainer is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants