-
-
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
Add support for custom formats in Rails/ToSWithArgument
#1133
Conversation
end | ||
|
||
def custom_format_types | ||
Set.new(cop_config.fetch('FormatTypes', []).map(&:to_sym)) |
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.
How does the name CustomFormatTypes
sound?
Can you add documentation text and example for the option?" |
badcd55
to
ccc7b15
Compare
Thank you for your review. |
Hm, upon reconsideration, instead of adding a new parameter like Are there any potential false positives that concern you with this approach? NOTE: Integer argument will produce false positives. e.g., ( |
I can't think of any examples, but overriding Customized formatting is an undocumented behavior, and for most users there will be no need to set We've already taken advantage of this autocorrection to complete an update to Rails 7.0, and just wanted to open the door for users faced similar issues. If you think it's a case that RuboCop shouldn't support it, feel free to close this PR :) |
Yeah,
def rails_extended_to_s?(node)
- node.first_argument&.sym_type? && EXTENDED_FORMAT_TYPES.include?(node.first_argument.value)
+ node.first_argument&.sym_type?
end If there's a lot of feedback about false positives in Rails application context, it might be reasonable to add |
Makes sense. Nonetheless, if I know in advance the type of arguments, I would like to pass format types to make auto correction more efficient. I understand that there are concerns about adding a new config, so I'm going to withdraw this PR for now. Thank you for your review and consideration. |
Can we reconsider this and/or add more documentation around this? I recently ran into this within a large code base and didn't realize it used the As for the escape hatch, I liked the solution @wata727 created. |
This PR adds support for custom formats in
Rails/ToSWithArgument
cop.Currently this cop only supports formats defined by Rails due to #869 changes, but some users may have added their own formats, such as:
Even in such cases, it would be convenient if autocorrection by this cop could be used. You can add any format to
FormatTypes
as below.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.