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 #3937] Add new Rails/StartEndWith cop #3991
Conversation
We should actually have a single cop checking for all similar |
Do you have any specific one in mind? Or how could we enumerate all such singular / plural forms in aliases? |
Here's a listing of all the methods - http://guides.rubyonrails.org/active_support_core_extensions.html |
There's indeed several other examples: Otherwise there's also:
I'm not sure if all of them should belong to the same cop (which would then be |
Aren't some of these aliases designed for grammatical purposes more so than as a replacement? In my mind this should work similar to what is being done in |
They were, but this is pointless in a programming language. Matz himself mentioned this a while back when asked what he thinks about those. |
So we would rather head towards a cop People will still have a choice to enable or disable it anyway. But yeah, it would be "all or nothing". |
@bbatsov I renamed the cop to I'm only checking for A detail here: I'm not supporting autocorrect from |
CHANGELOG.md
Outdated
@@ -16,6 +16,7 @@ | |||
* [#4018](https://github.com/bbatsov/rubocop/pull/4018): Add autocorrect `Lint/EmptyEnsure` cop. ([@pocke][]) | |||
* [#4028](https://github.com/bbatsov/rubocop/pull/4028): Add new `Style/IndentHeredoc` cop. ([@pocke][]) | |||
* Add new `Style/InverseMethods` cop. ([@rrosenblum][]) | |||
# [#3937](https://github.com/bbatsov/rubocop/issues/3937): Add new `Rails/ActiveSupportAliases` cop. ([@tdeo][]) |
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.
You have a typo here - # should be *.
config/enabled.yml
Outdated
Description: >- | ||
Avoid ActiveSupport aliases of standard ruby methods: | ||
`String#starts_with?`, `String#ends_with?`, | ||
`Array#append`, `Array#prepend` |
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.
This sentence should end with a .
.
module Cop | ||
module Rails | ||
# This cop checks that ActiveSupport aliases to core ruby methods | ||
# are not used |
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.
Add .
here.
# 'some_string'.end_with?('suffix') | ||
# [1, 2, 'a'] << 'b' | ||
# [1, 2, 'a'].unshift('b') | ||
# # 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.
Add a blank line between the code examples.
You can simply replace I've added a few small remarks to the code. Btw, ideally this cop should be configurable to both enforce consistent non-usage of the aliases and their consistent usage. I'll merge the cop even in its current form, but I guess some people won't be happy about the lack of config options. |
I still can't figure a good way for autocorrecting array.append(3)
array.append 3
array
.append 3 |
Well, let's leave this out of the cop's scope for now. |
And about different styles, I don't see any issue adding the option for consistent non-usage, but I think some people will still be unhappy having to write |
Fine by me. Just squash and rebase and I'll merge this. |
This cop checks for use of ActiveSupport aliases to core ruby methods: String#starts_with?, String#ends_with?, Array#append, Array#prepend
This cop checks for consistent use of
starts_with?
andends_with?
stringmethods or consistent use of
start_with?
andend_with?
No option to mix consistent use of
starts_with?
andend_with?
or the opposite.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).