-
-
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
[Fix #260] Fix target of Rails/ContentTag
#526
Conversation
config/default.yml
Outdated
@@ -181,8 +181,9 @@ Rails/BulkChangeTable: | |||
- db/migrate/*.rb | |||
|
|||
Rails/ContentTag: | |||
Description: 'Use `tag` instead of `content_tag`.' | |||
Description: 'Use `tag.something(` instead of `tag(:something`.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it's strange to write only the opening parenthesis.
Description: 'Use `tag.something(` instead of `tag(:something`.' | |
Description: 'Use `tag.something` instead of `tag(:something)`.' |
lib/rubocop/cop/rails/content_tag.rb
Outdated
# NOTE: Allow `content_tag` when the first argument is a variable because | ||
# `content_tag(name)` is simpler rather than `tag.public_send(name)`. | ||
# NOTE: Allow `tag` when the first argument is a variable because | ||
# `tag(name)` is simpler rather than `tag.public_send(name)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the following mention?
# `tag(name)` is simpler rather than `tag.public_send(name)`. | |
# `tag(name)` is simpler rather than `tag.public_send(name)`. | |
# And this cop will be renamed to something like `LegacyTag` in the future. (e.g. RuboCop Rails 2.0) |
lib/rubocop/cop/rails/content_tag.rb
Outdated
# content_tag(:p, 'Hello world!') | ||
# content_tag(:br) | ||
# tag(:p) | ||
# tag(:br, {class: 'classname'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you omit the redundant parentheses?
# tag(:br, {class: 'classname'}) | |
# tag(:br, class: 'classname') |
lib/rubocop/cop/rails/content_tag.rb
Outdated
# content_tag(name, 'Hello world!') | ||
# tag.p | ||
# tag.br(class: 'classname') | ||
# tag(name, {class: 'classname'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# tag(name, {class: 'classname'}) | |
# tag(name, class: 'classname') |
lib/rubocop/cop/rails/content_tag.rb
Outdated
class ContentTag < Base | ||
include RangeHelp | ||
extend AutoCorrector | ||
extend TargetRailsVersion | ||
|
||
minimum_target_rails_version 5.1 | ||
|
||
MSG = 'Use `tag` instead of `content_tag`.' | ||
RESTRICT_ON_SEND = %i[content_tag].freeze | ||
MSG = 'Use `tag.something(` instead of `tag(:something`.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSG = 'Use `tag.something(` instead of `tag(:something`.' | |
MSG = 'Use `tag.something` instead of `tag(:something)`.' |
Can you add the changelog entry and add |
RUBY | ||
end | ||
|
||
it 'does not register an offense when `content_tag` is called with no arguments' do | ||
it 'does not register an offense when first argument is string starts with underscore' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it 'does not register an offense when first argument is string starts with underscore' do | |
it 'does not register an offense when first argument is a string which starts with an underscore' do |
@koic |
Nice! Can you squash your commits into one? |
Tweak for review comments Add a changelog entry Modify VersionChanged instead of VersionAdded Co-authored-by: Koichi ITO <[email protected]> Fix CHANGELOG.md Co-authored-by: Koichi ITO <[email protected]> Generate doc
@koic |
Thanks! |
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)
Fix #260
This PR fixes target of
Rails/ContentTag
cop.The reason is that it is unclear wheather
content_tag
is deprecated, and auto-correction may cause performance regression.Following test cases are added.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.