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

Parser error when using inline helper_method #23

Closed
ledermann opened this issue Mar 28, 2023 · 1 comment · Fixed by #24
Closed

Parser error when using inline helper_method #23

ledermann opened this issue Mar 28, 2023 · 1 comment · Fixed by #24

Comments

@ledermann
Copy link

Since v0.5.0, code using inline helper_method like this breaks the parser:

class StatsController < ApplicationController
  # .... 
  helper_method def calculator
    @calculator ||= Calculator.new(timeframe)
  end
end
bin/rubocop app/controllers/stats_controller.rb
Inspecting 1 file
An error occurred while ThreadSafety/InstanceVariableInClassMethod cop was inspecting /Users/ledermann/Projects/solectrus/solectrus/app/controllers/stats_controller.rb:4:4.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while ThreadSafety/InstanceVariableInClassMethod cop was inspecting /Users/ledermann/Projects/solectrus/solectrus/app/controllers/stats_controller.rb:4: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.48.1 (using Parser 3.2.1.1, rubocop-ast 1.28.0, running on ruby 3.2.1) [arm64-darwin22]


bin/rubocop app/controllers/stats_controller.rb -d
For /Users/ledermann/Projects/solectrus/solectrus: configuration from /Users/ledermann/Projects/solectrus/solectrus/.rubocop.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-performance-1.16.0/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-performance-1.16.0/config/default.yml
Default configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.18.0/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.18.0/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-capybara-2.17.1/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-capybara-2.17.1/lib/../config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-rspec-2.19.0/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-rspec-2.19.0/config/default.yml
configuration from /Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/config/default.yml
configuration from #{path}
Inheriting configuration from /Users/ledermann/Projects/solectrus/solectrus/node_modules/@prettier/plugin-ruby/rubocop.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/ledermann/Projects/solectrus/solectrus/app/controllers/stats_controller.rb
An error occurred while ThreadSafety/InstanceVariableInClassMethod cop was inspecting /Users/ledermann/Projects/solectrus/solectrus/app/controllers/stats_controller.rb:4:4.
undefined method `send_type?' for :helper_method:Symbol
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:186:in `module_function_bare_access_modifier?'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:150:in `block in in_def_module_function?'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:150:in `any?'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:150:in `in_def_module_function?'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:107:in `class_method_definition?'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-thread_safety-0.5.0/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb:82:in `on_ivar'
/Users/ledermann/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rubocop-1.48.1/lib/rubocop/cop/commissioner.rb:107:in `public_send'

After changing the code to this, parsing works fine without any error:

class StatsController < ApplicationController
  # ....
  def calculator
    @calculator ||= Calculator.new(timeframe)
  end

  helper_method :calculator
end
@mikegee
Copy link
Collaborator

mikegee commented Mar 29, 2023

0.5.1 has been released with @ytjmt's fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants