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/EmptyLinesAroundAttributeAccessor fails with error when variable with name attr is used #7991

Closed
kewlar opened this issue May 18, 2020 · 0 comments · Fixed by #7992
Closed
Labels

Comments

@kewlar
Copy link

kewlar commented May 18, 2020

Rubocop Layout/EmptyLinesAroundAttributeAccessor inspection fails with an exception when it meets a variable named attr, as in:

class Foo
  def foo
    attr.foo
  end
end

Expected behavior

The code should be fine:

Inspecting 1 file
.

1 file inspected, no offenses detected

Actual behavior

Rubocop errors out:

An error occurred while Layout/EmptyLinesAroundAttributeAccessor cop was inspecting /Users/me/dev/spikes/rubocop-test/test.rb:3:4.
undefined method `send_type?' for :foo:Symbol
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb:63:in `attribute_accessor?'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb:39:in `on_send'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:136:in `with_cop_error_handling'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:55:in `each'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:32:in `block (2 levels) in <class:Commissioner>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:114:in `block in on_send'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:111:in `each'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:111:in `each_with_index'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:111:in `on_send'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:107:in `on_def'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:99:in `on_class'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/commissioner.rb:44:in `investigate'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/team.rb:124:in `investigate'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/team.rb:112:in `offenses'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:301:in `inspect_file'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:249:in `block in do_inspection_loop'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:281:in `block in iterate_until_no_changes'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `loop'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `iterate_until_no_changes'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:245:in `do_inspection_loop'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:148:in `file_offense_cache'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:122:in `file_offenses'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:113:in `process_file'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:92:in `block in each_inspected_file'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `reduce'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each_inspected_file'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:78:in `inspect_files'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:39:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli/command.rb:10:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli/environment.rb:17:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:41:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/exe/rubocop:13:in `block in <top (required)>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.83.0/exe/rubocop:12:in `<top (required)>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli.rb:476:in `exec'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/cli.rb:24:in `start'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/Users/me/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
/Users/me/.rbenv/versions/2.7.1/bin/bundle:23:in `load'
/Users/me/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Layout/EmptyLinesAroundAttributeAccessor cop was inspecting /Users/me/dev/spikes/rubocop-test/test.rb:3:4.

NOTE for master branch: When testing on master branch, the error is undefined method 'alias_type?' for :foo:Symbol instead of undefined method 'send_type?' for :foo:Symbol

Steps to reproduce the problem

Create test.rb with the following content:

class Foo
  def foo
    attr.foo
  end
end

Run Rubocop inspection on it:

rubocop --only Layout/EmptyLinesAroundAttributeAccessor test.rb

RuboCop version

Tested on Rubocop 0.83.0, and master@8376d3dc5a6e

$ bundle exec rubocop -V
0.83.0 (using Parser 2.7.1.2, running on ruby 2.7.1 x86_64-darwin18)

When testing on master branch, the error is undefined method 'alias_type?' for :foo:Symbol instead of undefined method 'send_type?' for :foo:Symbol

@koic koic added the bug label May 18, 2020
koic added a commit to koic/rubocop that referenced this issue May 18, 2020
…Accessor`

Fixes rubocop#7991.

This PR fixes an error for `Layout/EmptyLinesAroundAttributeAccessor`
when attribute method is method chained.
bbatsov pushed a commit that referenced this issue May 19, 2020
Fixes #7991.

This PR fixes an error for `Layout/EmptyLinesAroundAttributeAccessor`
when attribute method is method chained.
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