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

SyntaxError after autocorrecting long line with a block and appended string #11663

Closed
tom-kuca opened this issue Mar 5, 2023 · 0 comments
Closed
Labels

Comments

@tom-kuca
Copy link

tom-kuca commented Mar 5, 2023

Given the input file

Logger.error "\n\n\nBacktrace:\n\s\s" + e.backtrace.select { |line| line.start_with?(LIBRARY_PATH) }.join("\n\s\s") + "\n\n"

the command

exe/rubocop --config /dev/null --only Style/BlockDelimiters,Layout/LineLength task.rb -a

autocorrects the file to

Logger.error "\n\n\nBacktrace:\n\s\s" + e.backtrace.select do |line|
 line.start_with?(LIBRARY_PATH) end.join("\n\s\s") + "\n\n"

There is a syntax error:

$ ruby task.rb                                                                            
/tmp/task.rb:2: syntax error, unexpected '+', expecting end-of-input
...RARY_PATH) end.join("\n\s\s") + "\n\n"

No error is reported on the original file.

Expected behavior

Expected behavior is a syntactically correct ruby file after autocorrect.

Version

❯ exe/rubocop -V --config /dev/null
1.47.0 (using Parser 3.2.1.0, rubocop-ast 1.27.0, running on ruby 3.0.2) [x86_64-linux]
@koic koic added the bug label Mar 6, 2023
koic added a commit to koic/rubocop that referenced this issue Mar 6, 2023
…miters`

Fixes rubocop#11663.

This PR fixes an incorrect autocorrect for `Style/BlockDelimiters`
when multi-line blocks to `{` and `}` with arithmetic operation method chain.
@bbatsov bbatsov closed this as completed in f982aa8 Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants