-
-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Let's say we have this:
<%= tag.div class: something? ? "class-1" : "class-2" do %>
<%= content_tag :span, something.text %>
<% end %>Which would generate this through phlexing today:
class SomethingComponent < Phlex::HTML
include Phlex::Rails::Helpers::ContentTag
include Phlex::Rails::Helpers::Tag
attr_accessor :something
def initialize(something:)
@something = something
end
def template
tag.div class: something? ? "class-1" : "class-2" do
content_tag :span, something.text
end
end
private
def something?(*args, **kwargs)
# TODO: Implement me
end
endBut since this is a regular Ruby class now we could write any RuboCop rule (or maybe even a SyntaxTree mutation visitor) which statically analyses the code and auto-fixes it (we could even make the rules toggleable from the UI)
For example some rules could be:
- rewrite
tag.divasdiv { ... } - rewrite
content_tag :spantospan { ... } - rewrite all references of
somethinginsidedef templateto@somethingand remove theattr_accessorfor it - rewrite
class: something? ? "class-1" : "class-2"to**classes(something?: { then: "class-1", else: "class-2" }) - ...
We could even release these rules standalone as rubocop-phlex which people could use in their project independent of phlexing
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request