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 block and heredoc #10832

Closed
tom-kuca opened this issue Jul 24, 2022 · 0 comments · Fixed by #10835
Closed

SyntaxError after autocorrecting long line with block and heredoc #10832

tom-kuca opened this issue Jul 24, 2022 · 0 comments · Fixed by #10835
Labels

Comments

@tom-kuca
Copy link

Given the input file

class User
  has_many :friends, -> { joins(<<-SQL).select('users.first_name, users.last_name, users.phone').distinct }, through: :users
     INNER JOIN "clan_indicies" USING(user_id, clan_id)
  SQL
end

the command

rubocop /tmp/test.rb --only  Layout/LineLength,Layout/BlockEndNewline -a

autocorrects the file to

class User
  has_many :friends, -> {
 joins(<<-SQL).select('users.first_name, users.last_name, users.phone').distinct
}                     , through: :users
     INNER JOIN "clan_indicies" USING(user_id, clan_id)
  SQL
end

There is a now syntax error, the line } , through: :users is part of the heredoc string. Ruby reports /tmp/test.rb:7: syntax error, unexpected `end', expecting '}'.

Expected behavior

Expected behavior is a syntactically correct ruby file after autocorrect. Probably no change at all, I don't see any obvious change that would not break the syntax.

Version

❯ rubocop -V
1.32.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 2.7.4 x86_64-linux)
@koic koic added the bug label Jul 25, 2022
koic added a commit to koic/rubocop that referenced this issue Jul 25, 2022
…Newline`

Fixes rubocop#10832.

This PR fixes an incorrect autocorrect for `Layout/BlockEndNewline` when
multiline block `}` is not on its own line and using heredoc argument.
bbatsov pushed a commit that referenced this issue Jul 27, 2022
Fixes #10832.

This PR fixes an incorrect autocorrect for `Layout/BlockEndNewline` when
multiline block `}` is not on its own line and using heredoc argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants