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/RedundantAllowNil crashes with interpolations #6914

Closed
koerneml opened this issue Apr 9, 2019 · 1 comment · Fixed by #6916
Closed

Rails/RedundantAllowNil crashes with interpolations #6914

koerneml opened this issue Apr 9, 2019 · 1 comment · Fixed by #6916
Labels

Comments

@koerneml
Copy link

koerneml commented Apr 9, 2019

This seems to be related to #6882. RuboCop stumbles on dynamic validations, in this case with string interpolations

Expected behavior

RuboCop finishes without errors

Actual behavior

1 error occurred:
An error occurred while Rails/RedundantAllowNil cop was inspecting /path/to/my/class.rb:4:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.67.2 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-linux-gnu)

Steps to reproduce the problem

This minimal class should reproduce the problem.

class Foo < ActiveRecord::Base
  validates :details, "path_to_dynamic_validation/#{with_interpolation}": true
end

RuboCop version

0.67.2 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-linux-gnu)
@Blue-Pix
Copy link
Contributor

Blue-Pix commented Apr 9, 2019

I reproduced the problem with following code.

class Foo < ActiveRecord::Base
  BAR = "sample"
  validates :name, "#{self::BAR}": true
end
class SampleValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    if value.size > 3
      record.errors.add(attribute, 'too long')
    end
  end
end

This is stacktrace.

An error occurred while Rails/RedundantAllowNil cop was inspecting /myapp/app/models/foo.rb:3:2.
undefined method `value' for "s(:dsym,\n  s(:begin,\n    s(:const,\n      s(:self), :BAR)))":RuboCop::AST::Node

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.

3 participants