-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Fix RSpec/ExampleLength errors for heredoc #1667
Comments
Thank you for your report! I could not reproduce this. Can you also provide the .rubocop.yml settings? |
Hey Yudai, thanks. Yep, here's the full dump from Debug Dumpbundle exec rubocop -d spec/lib/sod/graph/node_spec.rb
For /Users/bkuhlmann/Engineering/OSS/sod: configuration from /Users/bkuhlmann/Engineering/OSS/sod/.rubocop.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/all.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/ruby.yml
Default configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/capybara.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-capybara-2.18.0/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-capybara-2.18.0/lib/../config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/factory_bot.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-factory_bot-2.23.1/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-factory_bot-2.23.1/lib/../config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/packaging.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-packaging-0.5.2/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-packaging-0.5.2/config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/performance.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-performance-1.18.0/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-performance-1.18.0/config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/thread.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.1/config/default.yml
configuration from #{path}
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/rake.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rake-0.6.0/config/default.yml
Inheriting configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/caliber-0.36.0/config/rspec.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rspec-2.22.0/config/default.yml
configuration from /Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rspec-2.22.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/bkuhlmann/Engineering/OSS/sod/spec/lib/sod/graph/node_spec.rb
An error occurred while RSpec/ExampleLength cop was inspecting /Users/bkuhlmann/Engineering/OSS/sod/spec/lib/sod/graph/node_spec.rb:275:4.
undefined method `last_line' for nil:NilClass
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parser-3.2.2.3/lib/parser/source/map.rb:118:in `last_line'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node.rb:266:in `last_line'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/metrics/utils/code_length_calculator.rb:199:in `block in source_from_node_with_heredoc'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:111:in `block in visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:112:in `block in visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:112:in `block in visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:108:in `visit_descendants'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node/mixin/descendence.rb:63:in `each_descendant'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/metrics/utils/code_length_calculator.rb:192:in `source_from_node_with_heredoc'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/metrics/utils/code_length_calculator.rb:77:in `code_length'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/metrics/utils/code_length_calculator.rb:25:in `calculate'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/mixin/code_length.rb:36:in `check_code_length'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/example_length.rb:59:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:105:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:69:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cop/team.rb:98:in `investigate'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:345:in `block in inspect_file'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:344:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:344:in `flat_map'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:344:in `inspect_file'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:314:in `loop'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:154:in `process_file'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:134:in `each'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:134:in `reduce'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/runner.rb:73:in `run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli.rb:118:in `run_command'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli.rb:51:in `block in run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/lib/rubocop/cli.rb:43:in `run'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/exe/rubocop:19:in `block in <top (required)>'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/Users/bkuhlmann/.cache/frum/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.54.0/exe/rubocop:19:in `<top (required)>'
/Users/bkuhlmann/Engineering/OSS/sod/bin/rubocop:6:in `load'
/Users/bkuhlmann/Engineering/OSS/sod/bin/rubocop:6:in `<main>'
.
1 file inspected, no offenses detected
1 error occurred:
An error occurred while RSpec/ExampleLength cop was inspecting /Users/bkuhlmann/Engineering/OSS/sod/spec/lib/sod/graph/node_spec.rb:275:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.54.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [arm64-darwin22.4.0]
Finished in 0.6041079999413341 seconds Additionally, here's my RuboCop configuration. By the way, the Ruby configuration is one of multiple configurations as provided by my Caliber gem so if you need the full list, you can find it here in case that helps too. |
I've got such errors alongside with core RuboCop's My cases of |
Mentioned issue is fixed in RuboCop. I've checked via I think we can close this issue because it's kind of third-party and wait for a new (patch?) release of RuboCop. |
@AlexWayfer Thank you for confirming this. |
Yudai: Confirmed. Using the patched version of RuboCop (i.e. using RuboCop via the I'm going to close this issue. Looking forward to the next patch release! |
ℹ️ Closing. Will wait for patch release. |
I just was lucky to receive an error from core RuboCop in one of dozens my repos. 😅 |
RuboCop 1.54.1 with the fix has been released. |
Overview
Hello. 👋 With the recent upgrade to RuboCop 1.54.0, I'm experiencing errors with heredoc usage within spec examples. This appears to effect any spec that uses heredoc. The errors I'm getting are:
Steps to Recreate
Here's a few examples, I've seen where this is cropping up:
Simply using a heredoc within the body of your
it
block will cause this error:Alternatively, using a heredoc as your proof will also cause this failure:
Environment
Ruby: ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [arm64-darwin22.4.0]
RuboCop
The text was updated successfully, but these errors were encountered: