We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When each_with_object is used with multiplex assignment:
each_with_object
def make_field_name_map(model) model.attribute_names.each_with_object({}) { |name, hash| hash[name] = hash[name.humanize] = hash[model.human_attribute_name(name)] = name.to_sym } end
No offences.
Rubocop detects Rails/WithIndex offence:
Rails/WithIndex
test.rb:2:3: C: Rails/IndexWith: Prefer index_with over each_with_object. model.attribute_names.each_with_object({}) { |name, hash| ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Autocorrect breaks code:
def make_field_name_map(model) model.attribute_names.index_with { |name| hash[name.humanize] = hash[model.human_attribute_name(name)] = name.to_sym } end
$ be rubocop -V 0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.6.6 x86_64-linux) $ grep rails Gemfile.lock rubocop-rails (2.8.0)
The text was updated successfully, but these errors were encountered:
d8c62f5
Merge pull request #353 from eugeneius/index_by_index_with_hash_reuse
de09957
[Fix #338][Fix #350] Fix a false positive for Rails/IndexBy and Rails/IndexWith
No branches or pull requests
When
each_with_object
is used with multiplex assignment:Expected behavior
No offences.
Actual behavior
Rubocop detects
Rails/WithIndex
offence:Autocorrect breaks code:
RuboCop version
The text was updated successfully, but these errors were encountered: