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

Rails/RenderInline: undefined method `value' #300

Closed
elv1ss opened this issue Jul 21, 2020 · 0 comments · Fixed by #303
Closed

Rails/RenderInline: undefined method `value' #300

elv1ss opened this issue Jul 21, 2020 · 0 comments · Fixed by #303
Labels
bug Something isn't working

Comments

@elv1ss
Copy link

elv1ss commented Jul 21, 2020

Expected behavior

RoboCop should ignore key-value pairs where the key is represented as a variable.

Actual behavior

The error undefined method 'value' for s(:lvar, :serializer):RuboCop::AST::Node occurs when Rails/RenderInline cop check render json: ... line with hash where the key is represented as a variable.

Steps to reproduce the problem

Run RuboCop on the following:

class DemoController
  def index
    render_for(@resources)
  end

  def show
    render_for(@resource)
  end

  private

  def render_for(resource, includes: '**')
    serializer = resource.respond_to?(:each) ? :each_serializer : :serializer
    render json: resource, serializer => ResourceSerializer, include: includes
  end
end

RuboCop version

bundle exec rubocop -V
0.88.0 (using Parser 2.7.1.4, rubocop-ast 0.2.0, running on ruby 2.6.6 x86_64-darwin18)

Possible fix

I think this can be fixed by adding respond_to check to includes_inline_key? method, but I'm not sure.

def includes_inline_key?(node)
  node.keys.find { |key| key.respond_to?(:value) && key.value.to_sym == :inline }
end
@koic koic added the bug Something isn't working label Jul 21, 2020
tejasbubane added a commit to tejasbubane/rubocop-rails that referenced this issue Jul 21, 2020
tejasbubane added a commit to tejasbubane/rubocop-rails that referenced this issue Jul 21, 2020
tejasbubane added a commit to tejasbubane/rubocop-rails that referenced this issue Jul 24, 2020
tejasbubane added a commit to tejasbubane/rubocop-rails that referenced this issue Jul 24, 2020
@koic koic closed this as completed in #303 Jul 24, 2020
koic added a commit that referenced this issue Jul 24, 2020
[Fix #300] Fix `Rails/RenderInline` error on variable key in render options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants