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

Warn about deprecated element methods #649

Closed
wants to merge 1 commit into from

Conversation

stephannv
Copy link
Contributor

Fix first item from #632

Comment on lines +26 to +36
def capture_stderr(&block)
captured_stream = StringIO.new
original_stream = $stderr
$stderr = captured_stream

block.call

captured_stream.string.strip
ensure
$stderr = original_stream
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this as a module because I think it can be useful for other deprecation tests in the future.

@@ -35,6 +35,10 @@ def register_element(method_name, tag: nil, deprecated: false)
# frozen_string_literal: true

def #{method_name}(**attributes, &block)
if #{deprecated}
Kernel.warn("`#{method_name}` and `_#{method_name}` are deprecated and will be unsupported in Phlex 2.0. This HTML element is no longer recommended. Check out MDN web docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/#{tag}.")
Copy link
Contributor Author

@stephannv stephannv Feb 2, 2024

Choose a reason for hiding this comment

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

  1. I couldn't get called method name here (eg. param or _param), using __method__ or __callee__ returns register_element here or register_void_element on line 82.

  2. I'm not sure if it makes sense to add link to MDN docs, but it explains why the method is being deprecated and redirects the user to more detailed context.

describe "Elements deprecation" do
deprecated_methods = %i[param]

deprecated_methods.each do |method_name|
Copy link
Contributor Author

@stephannv stephannv Feb 2, 2024

Choose a reason for hiding this comment

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

I'm not sure if it is worth testing non deprecated elements. It would be something like:

[
  Phlex::HTML::StandardElements.registered_elements,
  Phlex::HTML::VoidElements.registered_elements
].each do |element_group|
  element_group.each do |method_name, tag|
    if deprecated_methods.include?(method_name)
      # tests for method_name and _method_name
      ... warns about deprecation
    else
      # tests for method_name and _method_name
      ... doesn't warn about deprecation
    end
  end
end

@joeldrapper
Copy link
Collaborator

Sorry @stephannv, I wanted to go with a simpler solution to this where the message was just passed to the deprecated: argument. See #658

I really appreciate the effort you put into this PR, but it didn’t feel right for what this is, especially as this is probably the only time we'll have to deprecate elements.

@stephannv
Copy link
Contributor Author

No problem @joeldrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants