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

Rubocop 0.58.0 errors on Rails/BulkChangeTable cop #6089

Closed
morgoth opened this issue Jul 9, 2018 · 0 comments
Closed

Rubocop 0.58.0 errors on Rails/BulkChangeTable cop #6089

morgoth opened this issue Jul 9, 2018 · 0 comments
Labels

Comments

@morgoth
Copy link

morgoth commented Jul 9, 2018

Actual behavior

Rubocop throws error during inspect on migration file:

1 error occurred:
An error occurred while Rails/BulkChangeTable cop was inspecting /home/wojtek/Projects/path/to/project

Content of the file is:

class AddMeasurementSystemToUsers < ActiveRecord::Migration
  def change
    %w[users deleted_users].each do |table|
      add_column table, :measurement_system, :integer, null: false, default: 1 # default = metric
    end
  end
end

RuboCop version

$ rubocop -V
0.58.0 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-linux)
@koic koic added the bug label Jul 9, 2018
wata727 added a commit to wata727/rubocop that referenced this issue Jul 9, 2018
…le name

Fixes rubocop#6089

The following error is occurred when using variables as table name:

```
NoMethodError:
       undefined method `value' for s(:lvar, :table):RuboCop::AST::Node
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:258:in `process'
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:144:in `block in on_def'
     # ./lib/rubocop/ast/node.rb:185:in `block in each_child_node'
     # ./lib/rubocop/ast/node.rb:183:in `each'
     # ./lib/rubocop/ast/node.rb:183:in `each_child_node'
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:142:in `on_def'
     # ./lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:105:in `with_cop_error_handling'
     # ./lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:55:in `each'
     # ./lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
     # ./lib/rubocop/ast/traversal.rb:12:in `walk'
     # ./lib/rubocop/cop/commissioner.rb:45:in `investigate'
     # ./lib/rubocop/rspec/cop_helper.rb:71:in `_investigate'
     # ./lib/rubocop/rspec/cop_helper.rb:25:in `inspect_source'
     # ./lib/rubocop/rspec/expect_offense.rb:61:in `expect_no_offenses'
     # ./spec/rubocop/cop/rails/bulk_change_table_spec.rb:358:in `block (3 levels) in <top (required)>'
```

This problem occurs because the table name is not a literal node.
It is very difficult to interpolate variables, so in that case
this cop ignores such nodes.
bbatsov pushed a commit that referenced this issue Jul 10, 2018
…#6090)

Fixes #6089

The following error is occurred when using variables as table name:

```
NoMethodError:
       undefined method `value' for s(:lvar, :table):RuboCop::AST::Node
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:258:in `process'
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:144:in `block in on_def'
     # ./lib/rubocop/ast/node.rb:185:in `block in each_child_node'
     # ./lib/rubocop/ast/node.rb:183:in `each'
     # ./lib/rubocop/ast/node.rb:183:in `each_child_node'
     # ./lib/rubocop/cop/rails/bulk_change_table.rb:142:in `on_def'
     # ./lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:105:in `with_cop_error_handling'
     # ./lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:55:in `each'
     # ./lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
     # ./lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
     # ./lib/rubocop/ast/traversal.rb:12:in `walk'
     # ./lib/rubocop/cop/commissioner.rb:45:in `investigate'
     # ./lib/rubocop/rspec/cop_helper.rb:71:in `_investigate'
     # ./lib/rubocop/rspec/cop_helper.rb:25:in `inspect_source'
     # ./lib/rubocop/rspec/expect_offense.rb:61:in `expect_no_offenses'
     # ./spec/rubocop/cop/rails/bulk_change_table_spec.rb:358:in `block (3 levels) in <top (required)>'
```

This problem occurs because the table name is not a literal node.
It is very difficult to interpolate variables, so in that case
this cop ignores such nodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants