-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Add Rails/UnusedIgnoredColumns cop #494
Add Rails/UnusedIgnoredColumns cop #494
Conversation
e9c8ae3
to
e4ab457
Compare
e4ab457
to
91da1b4
Compare
class UnusedIgnoredColumns < Base | ||
include ActiveRecordHelper | ||
|
||
MSG = 'Remove `%<column_name>s` from `ignored_columns` because the column does not exist.' |
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.
Can you use RESTRICT_ON_SEND = %i[ignored_columns=].freeze
?
end | ||
RUBY | ||
end | ||
end |
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.
Can you add the test case?
self.ignored_columns = [:real_name, :account]
|
||
MSG = 'Remove `%<column_name>s` from `ignored_columns` because the column does not exist.' | ||
|
||
def_node_matcher :ignored_columns?, <<~PATTERN |
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.
?
looks unnecessary because a captured value is returned.
def_node_matcher :ignored_columns?, <<~PATTERN | |
def_node_matcher :ignored_columns, <<~PATTERN |
Thanks for your review! I'll check them this weekend |
* Use RESTRICT_ON_SEND constant * Drop `?` for the matcher because it returns non-boolean value * Add test case
I updated this pull request with your comment. 4cd98d4 Thanks! |
Thanks! |
This pull request adds a new Rails/UnusedIgnoredColumns cop.
The cop detects columns that
ignored_clumns
contains but RDBMS doesn't contain.Background
ignored_columns
is necessary to remove a column. For example:The
ignored_columns
should be removed after the migration, but sometimes we forget to remove theignored_columns
.You can avoid forgetting to remove it by this cop.
I think this cop doesn't need an entry in the Rails Style Guide because it is just a small bug.
This pull request doesn't contain the autocorrect feature to keep the PR small for the first step. We can implement the autocorrect feature for the next step.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.