Skip to content
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

FlatMap breaks syntax when autocorrecting chained methods on separate lines #344

Closed
wteuber opened this issue Mar 1, 2023 · 0 comments · Fixed by #345
Closed

FlatMap breaks syntax when autocorrecting chained methods on separate lines #344

wteuber opened this issue Mar 1, 2023 · 0 comments · Fixed by #345
Labels
bug Something isn't working

Comments

@wteuber
Copy link
Contributor

wteuber commented Mar 1, 2023

Expected behavior

array_of_hashes
  .flat_map(&:to_a)
  .each_with_object({}) { |(k, v), h| (h[k] ||= []) << v }
$ ruby -c file.rb
Syntax OK

Actual behavior

array_of_hashes
  .flat_map(&:to_a)

  .each_with_object({}) { |(k, v), h| (h[k] ||= []) << v }
$ ruby -c file.rb
file.rb: file.rb:4: syntax error, unexpected '.' (SyntaxError)
  .each_with_object({}) { |(k, v...
  ^

Steps to reproduce the problem

file.rb:

array_of_hashes
  .map(&:to_a)
  .flatten(1)
  .each_with_object({}) { |(k, v), h| (h[k] ||= []) << v }
rubocop --autocorrect-all --only Performance/FlatMap file.rb

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-performance, rubocop-rails, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.45.1 (using Parser 3.2.1.0, rubocop-ast 1.26.0, running on ruby 3.2.0) [arm64-darwin21.5.0]
  - rubocop-minitest 0.28.0
  - rubocop-performance 1.16.0
  - rubocop-rails 2.17.4
  - rubocop-sorbet 0.6.8
@koic koic added the bug Something isn't working label Mar 1, 2023
@wteuber wteuber changed the title FlatMap breaks syntax when autocorrecting changed methods on separate lines FlatMap breaks syntax when autocorrecting chained methods on separate lines Mar 2, 2023
@koic koic closed this as completed in #345 Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants