-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Fix a false positive for Rails/NotNullColumn
when adding a :virtual
column
#892
Conversation
pairs = add_not_null_column?(node) | ||
check_pairs(pairs) | ||
add_not_null_column?(node) do |type, pairs| | ||
return if type.source.include?('virtual') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include?
is a partial match, so I'm worried about false positives. What about below?
return if type.source.include?('virtual') | |
return if type.source == ':virtual' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to specify column types as a string (while not as popular as symbol) or a symbol, so I tried to match both. Do you think we can skip it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, It's a corner case, but I think String#include?
is not suitable because it matches all strings containing virtual
. This patch will need to add a test case for column types as a string and updating an appropriate logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added explicit check and a test case.
54bba14
to
d723ab8
Compare
pairs = add_not_null_column?(node) | ||
check_pairs(pairs) | ||
add_not_null_column?(node) do |type, pairs| | ||
return if type.source == ':virtual' || type.source == "'virtual'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type.value
should be used instead of type.source
to detect double quoted "virtual"
.
return if type.source == ':virtual' || type.source == "'virtual'" | |
return if type.value == :virtual || type.value == 'virtual' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 Thanks! Fixed.
d723ab8
to
d60ff74
Compare
Thanks! |
Thank you! |
Fixes #887.
From documentation: