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 stumbles upon validation #6882
Comments
Identified the culprit after running
|
Fixes rubocop#6882. This PR fixes the following error for `Rails/RedundantAllowNil` when not using both `allow_nil` and `allow_blank`. ```ruby % cat app/models/user.rb class User < ApplicationRecord validates :email, presence: true end ``` ```console % rubocop app/models/user.rb --only Rails/RedundantAllowNil -d For /private/tmp/6882: configuration from /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/config/default.yml Inspecting 1 file Scanning /private/tmp/6882/app/models/user.rb An error occurred while Rails/RedundantAllowNil cop was inspecting /private/tmp/6882/app/models/user.rb:2:2. undefined method `children' for nil:NilClass /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/lib/rubocop/cop/rails/redundant_allow_nil.rb:42:in `on_send' (snip) 1 file inspected, no offenses detected 1 error occurred: An error occurred while Rails/RedundantAllowNil cop was inspecting /private/tmp/6882/app/models/user.rb:2: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.1 (using Parser 2.6.2.0, running on ruby 2.6.1 x86_64-darwin17) ```
Thanks for the feedback. I opened a PR #6886. |
Fixes #6882. This PR fixes the following error for `Rails/RedundantAllowNil` when not using both `allow_nil` and `allow_blank`. ```ruby % cat app/models/user.rb class User < ApplicationRecord validates :email, presence: true end ``` ```console % rubocop app/models/user.rb --only Rails/RedundantAllowNil -d For /private/tmp/6882: configuration from /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/config/default.yml Inspecting 1 file Scanning /private/tmp/6882/app/models/user.rb An error occurred while Rails/RedundantAllowNil cop was inspecting /private/tmp/6882/app/models/user.rb:2:2. undefined method `children' for nil:NilClass /Users/koic/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-0.67.1/lib/rubocop/cop/rails/redundant_allow_nil.rb:42:in `on_send' (snip) 1 file inspected, no offenses detected 1 error occurred: An error occurred while Rails/RedundantAllowNil cop was inspecting /private/tmp/6882/app/models/user.rb:2: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.1 (using Parser 2.6.2.0, running on ruby 2.6.1 x86_64-darwin17) ```
I just got the same error in my Rails project :D |
Same, still getting it on 0.67.1.
|
Sorry, just noticed the changelog mentions the fix isn't released yet but the PR is on master. |
You're right. I completely misread the release page. I should probably go to bed. lol But thanks for pointing it out, I've disabled the cop for now to get rid of the error, |
Hi there. We RuboCop core team released RuboCop 0.67.2. |
@koic you're amazing, thank you! |
Thanks! |
It seems that some of the issue still persists in 0.67.2 in this case, it was a |
@koerneml Could you open a new issue based on the issue template? |
Actual behavior
Newly added
Rails/RedundantAllowNil
errors out after encounteringvalidates
keywordSteps to reproduce the problem
The file in question
app/models/user.rb
:RuboCop version
The text was updated successfully, but these errors were encountered: