-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
The Rails/ContentTag should only target the deprecated tag
helper
#260
Comments
tag
helper which is being deprecatedtag
helper
Rubocop enforces #tag instead of #content_tag even though they are not the same right now, with crucial differences. More info: rubocop/rubocop-rails#260
This is actually a false positive as mentioned in rubocop/rubocop-rails#260, so let's disable it. I think `content_tag(:div)` is more readable than `tag.div`. There's a discussion to be had, but we can just allow both.
Hello, I've been looking into this, as in my team we are currently discussing whether to use 1. Scale of the performance problemIn the benchmarks @czj shared, it is important to note the results are in milliseconds for 50,000 calls. That gives us 1.3µs (microsecond or 0.0000013s) of difference on average, between a call to This is indeed a performance difference, which adds up when looking at a complete page render, but I think it is necessary to put things in perspective: how many calls to 2. Impact of
|
@tabuchi0919 You are the author of |
Thank you for mentioning, and I will try this issue this weekend.
So, I want to add options.
Any ideas or suggestions would be welcome. |
@tabuchi0919 Thank you for taking this! I think that APIs that are unclear whether they are deprecated can be allowed by default. Also, auto-correction for non-deprecated APIs should not cause performance regression. |
[Fix #260] Fix target of `Rails/ContentTag`
With this new version, I have issues with rubocop running on a pure ruby (no HTML or whatsoever) file that plays with act_as_taggable (code contains some
Bugs on these 2 lines: |
The cop is buggy before rubocop-rails 2.12.0 [1][2], but to get that we'd need a newer theforeman-rubocop, which generates more offenses than I am willing to fix today. Disable the cop like it was disabled in foreman_ansible too [3]. [1] rubocop/rubocop-rails#260 [2] rubocop/rubocop-rails#526 [3] theforeman/foreman_ansible#357
The cop is buggy before rubocop-rails 2.12.0 [1][2], but to get that we'd need a newer theforeman-rubocop, which generates more offenses than I am willing to fix today. Disable the cop like it was disabled in foreman_ansible too [3]. [1] rubocop/rubocop-rails#260 [2] rubocop/rubocop-rails#526 [3] theforeman/foreman_ansible#357
The cop is buggy before rubocop-rails 2.12.0 [1][2], but to get that we'd need a newer theforeman-rubocop, which generates more offenses than I am willing to fix today. Disable the cop like it was disabled in foreman_ansible too [3]. [1] rubocop/rubocop-rails#260 [2] rubocop/rubocop-rails#526 [3] theforeman/foreman_ansible#357 (cherry picked from commit 98c9fee)
Hello.
I'm quite uncertain about the deprecation of the
content_tag
helper method targeted by the new Rails/ContentTag cop in #242 as it seems to me, reading Rails source code, that only the legacytag
method is deprecated.The difference between
tag
andcontent_tag
helper methodsWhen reading the Rails documentation I see that the legacy
tag
syntax use with arguments is deprecated and will be removed. It is called like so :It returns a tag that is by default not open, and XHTML compliant because it ends with a
/>
at the end.When you look at the source of the method, you see why
tag
is deprecated and will be replaced:This method builds its HTML string by itself and checks for name nullity to piggy back on
tag_builder
The
content_tag
helper method on the other hand generates an HTML 5 compliant output with a closing tag at the end.The source code shows it utilises
tag_builder
all the time and outputs good HTML code:Solution
I'm proposing changing this cop to only warn of usage of the the tag helper method with arguments like :
And not when used with the argument-less syntax.
Why I think it matters
Usage of
tag.something
is way slower than usingcontent_tag(:something)
as you can see with this simple benchmark :You can reproduce it by dropping this code inside any view :
Avoiding suggesting to switch to an almost 2 times slower method would save a ton of CPU time in thousands of Rails applications. The framework is not particularly focused on pure speed, so every little bit of performance improvements helps, I think.
Why
tag.something
is slowThe new
tag
helper reliesmethod_missing
ontag_builder
which is very slow. compared to passing a string.https://github.com/rails/rails/blob/a5cda0407fffe4214db3c40487d9d6394b391bc1/actionview/lib/action_view/helpers/tag_helper.rb#L119
The text was updated successfully, but these errors were encountered: