Skip to content
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

How to handle ActiveSupport's starts_with? and ends_with? in Performance/DoubleStartEndWith #3893

Closed
rrosenblum opened this issue Jan 11, 2017 · 3 comments · Fixed by #3935
Closed

Comments

@rrosenblum
Copy link
Contributor

I recently discovered that ActiveSupport adds in starts_with? and ends_with? as aliases to start_with? and end_with?. I would like to add support for these methods, but I am not sure what the best way to accomplish this is.

One idea is to add a configuration to Performance/DoubleStartEndWith to enable checks for starts_with? and ends_with?.

Another idea is to add a Rails specific cop to handle this check separately from the Performance cop.

What is the preferred way to implement this check?

RuboCop version

Any version that includes Performance/DoubleStartEndWith

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 12, 2017

I'd go with configuration.

On a related note - it would be nice to have a Rails cop checking for usages of the aliases added by ActiveSupport - some people like to use only them, some people like to use only the names in the core library.

@rrosenblum
Copy link
Contributor Author

I'd go with configuration.

Thank you. I was leaning towards using a configuration. I figured I would ask before I started implementing this to avoid having to potentially code it twice.

it would be nice to have a Rails cop checking for usages of the aliases

Agreed, this could be a useful cop. It would be really nice if we could come up with a generic solution that could swap out any method with some other method that are defined in configuration. I am not sure how possible a generic solution is because of different method signatures and needed to check for a method called on nothing vs on a variable.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 18, 2017

Agreed, this could be a useful cop. It would be really nice if we could come up with a generic solution that could swap out any method with some other method that are defined in configuration. I am not sure how possible a generic solution is because of different method signatures and needed to check for a method called on nothing vs on a variable.

Guess it will just need more extensive configuration - not just method names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants