-
-
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 EnforcePrefix option to Rails/Delegate #4452
Add EnforcePrefix option to Rails/Delegate #4452
Conversation
0d357d5
to
058ff2d
Compare
@bbatsov I'm sure you're busy, but if you have a chance to take a look it’d be greatly appreciated! |
This is a great addition to the cop, and the code looks good. My only concern is that the option name might be a bit ambiguous. At first it sounds like it forces you to use Maybe |
CHANGELOG.md
Outdated
@@ -9,6 +9,7 @@ | |||
### Changes | |||
|
|||
* [#4444](https://github.com/bbatsov/rubocop/pull/4444): Make `Style/Encoding` cop enabled by default. ([@deivid-rodriguez][]) | |||
* [#4452](https://github.com/bbatsov/rubocop/pull/4452): Add option to Rails/Delegate for enforcing the prefixed method name case. ([@klesse413][]) |
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.
The name of the cop should be in backticks here.
lib/rubocop/cop/rails/delegate.rb
Outdated
# # good | ||
# private | ||
# def bar | ||
# foo.bar | ||
# end | ||
# | ||
# # EnforcePrefix: true | ||
# # bad |
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.
I wouldn't nest this additionally, as it doesn't look well in the generated documentation.
lib/rubocop/cop/rails/delegate.rb
Outdated
# This cop looks for delegations that could have been created | ||
# automatically with the `delegate` method. | ||
# | ||
# The EnforcePrefix option (defaulted to true) means that |
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.
I'd put in backticks the name of the option and true
.
lib/rubocop/cop/rails/delegate.rb
Outdated
# delegate :bar, to: :foo, prefix: true | ||
# | ||
# # EnforcePrefix: false | ||
# # good |
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.
Same here.
But what's the value of having this cop for you then? Prefixing unprefixed delegations? |
058ff2d
to
2096d40
Compare
… whether to enforce the prefix: true delegate case
2096d40
to
9566e1b
Compare
@Drenmi I like the @bbatsov The idea is that we would still like to use the cop to get a violation when using def bar
foo.bar
end since we would prefer to use delegate :bar, to: :foo but we don't want to get a violation when using def foo_bar
foo.bar
end so we'd like to be able to turn off enforcing that case |
I thought as much. 👍 |
Hi! I'm proposing a change to the Rails/Delegate cop that adds an option (EnforcePrefix) to give users the ability to choose whether or not to enforce the
prefix: true
case when delegating.At Betterment, we prefer to use
over
because the second way makes it difficult to find where a method is defined (a search of the codebase would come up empty). I've defaulted the EnforcePrefix option to true, leaving current functionality as is, but this way the option is there to turn it off for projects that prefer to.
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.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).