-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 new Rails/RedundantReceiverInWithOptions
cop
#5185
Add new Rails/RedundantReceiverInWithOptions
cop
#5185
Conversation
module RuboCop | ||
module Cop | ||
module Rails | ||
# This cop checks for unneeded receiver in `with_options`. |
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.
Usually in English the word redundant
would be used instead of unneeded
.
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 for the review. Code comment, cop name, offense message, commit message and so on in this PR were all replaced with redundant
.
61bc085
to
0a88805
Compare
Rails/UnneededReceiverInWithOptions
copRails/RedundantReceiverInWithOptions
cop
0a88805
to
b898c09
Compare
## Feature This cop checks for redundant receiver in `with_options`. Receiver is implicit from Rails 4.2 or higher. ### Bad case ```ruby class Account < ApplicationRecord with_options dependent: :destroy do |assoc| assoc.has_many :customers assoc.has_many :products assoc.has_many :invoices assoc.has_many :expenses end end ``` ### Good case ```ruby class Account < ApplicationRecord with_options dependent: :destroy do has_many :customers has_many :products has_many :invoices has_many :expenses end end ``` ### How to use ```console % cat app/models/account.rb # frozen_string_literal: true class Account < ApplicationRecord with_options dependent: :destroy do |assoc| assoc.has_many :customers assoc.has_many :products assoc.has_many :invoices assoc.has_many :expenses end end ``` ```console % rubocop /tmp/app/models/account.rb --only Rails/RedundantReceiverInWithOptions Inspecting 1 file C Offenses: /tmp/app/models/account.rb:5:5: C: Rails/RedundantReceiverInWithOptions: Redundant receiver in with_options. assoc.has_many :customers ^^^^^ /tmp/app/models/account.rb:6:5: C: Rails/RedundantReceiverInWithOptions: Redundant receiver in with_options. assoc.has_many :products ^^^^^ /tmp/app/models/account.rb:7:5: C: Rails/RedundantReceiverInWithOptions: Redundant receiver in with_options. assoc.has_many :invoices ^^^^^ /tmp/app/models/account.rb:8:5: C: Rails/RedundantReceiverInWithOptions: Redundant receiver in with_options. assoc.has_many :expenses ^^^^^ 1 file inspected, 4 offenses detected ``` ## Other Information API documentation http://api.rubyonrails.org/?q=with_options
b898c09
to
0beb6d2
Compare
👍 |
Feature
This cop checks for redundant receiver in
with_options
.Receiver is implicit from Rails 4.2 or higher.
Bad case
Good case
How to use
Other Information
API documentation
http://api.rubyonrails.org/?q=with_options
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).