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 Style/HashNewKeywordArguments
cop
#11507
base: master
Are you sure you want to change the base?
Add Style/HashNewKeywordArguments
cop
#11507
Conversation
I am a little concerned about whether |
be8c31e
to
89163a4
Compare
def keyword_arguments?(argument) | ||
argument.hash_type? && !argument.source.lstrip.start_with?('{') | ||
end |
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.
Is there any other good way to inspect keyword arguments?
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 seems that kwargs
is rounded to hash
in rubocop-ast.
https://github.com/rubocop/rubocop-ast/blob/57bc6792ed83dfb2890ed1ce1eebc2580fd83aa2/lib/rubocop/ast/builder.rb#L64
I don't know if this is better, but would it be better to define a KwargsNode
to replace it?
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.
Since the emit_kwargs
option is not enabled in RuboCop's parser, I don't think the kwargs
type is actually passed there, but changing this option might have too much impact.
Interesting. However, it is too early to judge the direction of this cop force yet. So, it should be decided after https://bugs.ruby-lang.org/issues/19236 is settled. Let's come back to this PR once https://bugs.ruby-lang.org/issues/19236 is closed. |
Let's mark this PR as WIP in the mean time. |
I have heard that future versions of Ruby are likely to deprecate the ability to pass default values with keyword arguments to
Hash.new
.So I thought it would be a good idea to prepare a Cop that detects such usage and autocorrects it while it is still available. Since the signature is originally
Hash.new(default_value = nil)
, there should be no problem deprecating the keyword arguments.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.