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

Layout/BlockEndNewline: Error when encountering multiline lambdas #10877

Closed
jchilders opened this issue Aug 6, 2022 · 0 comments · Fixed by #10878
Closed

Layout/BlockEndNewline: Error when encountering multiline lambdas #10877

jchilders opened this issue Aug 6, 2022 · 0 comments · Fixed by #10878
Labels

Comments

@jchilders
Copy link

An error occurs when running rubocop --auto-correct when attempting to parse class methods with multiline lambdas. The error message is of the form:

An error occurred while Layout/BlockEndNewline cop was inspecting <file>:<row>:<col>

Expected behavior

The Layout/BlockEndNewline cop is able to inspect, register an offense, and correct multiline lambdas without error.

Actual behavior

An error occurs. Partial rubocop --debug output:

An error occurred while Layout/BlockEndNewline cop was inspecting <file>:167:47.
undefined method `heredoc?' for s(:hash,
  s(:pair,
    s(:sym, :created_at),
    s(:sym, :desc))):RuboCop::AST::HashNode
...
An error occurred while Layout/BlockEndNewline cop was inspecting <file>:167:47.
...
Mention the following information in the issue report:
1.33.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 3.0.4 arm64-darwin21)

Steps to reproduce the problem

  1. Create my_class.rb
  2. Add the following to its body:
class MyClass
  thing :widget, -> {
    baz(key: val) }
end
  1. rubocop --auto-correct my_class.rb
  2. An error occurs

RuboCop version

$ rubocop -V
1.33.0 (using Parser 3.1.2.0, rubocop-ast 1.19.1, running on ruby 3.0.4 arm64-darwin21)
  - rubocop-performance 1.14.2
  - rubocop-rails 2.15.2

Please see the attached a patch file to the RuboCop::Cop::Layout::BlockEndNewline spec which includes a failing test case:

Patch file for block_end_newline_spec.rb

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