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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rouge/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.

new(*args, **kwargs).format(tokens, &b)
end

def initialize(opts={})
Expand Down