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

Use did_you_mean instead of jaro_winkler #7931

Merged
merged 4 commits into from May 10, 2020

Conversation

bquorning
Copy link
Contributor

@bquorning bquorning commented May 4, 2020

The did_you_mean gem has been a part of Ruby since v2.3, so if we can use that instead of the jaro_winkler gem our users will have 1 less dependency.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

rubocop.gemspec Outdated Show resolved Hide resolved
@bquorning bquorning marked this pull request as ready for review May 5, 2020 09:52
@bquorning
Copy link
Contributor Author

rubocop-rails uses NameSimilarity: https://github.com/rubocop-hq/rubocop-rails/blob/891c6aad8a6ac03b89a2f2bfe403554021c9dde0/lib/rubocop/cop/rails/unknown_env.rb#L18

So although this PR only changes internal API, it is actually a breaking change. Hmm, any suggestions on how to fix that?

@koic
Copy link
Member

koic commented May 6, 2020

The API is possibly used by third party cop that rubocop-hq org does not managed.
On the other hand, I think that it is not a major change. If the changelog mentions this change, I think it's okay. And I've looked at rubocop-rails repo, probably don't need **(Breaking)** mark.

@rrosenblum
Copy link
Contributor

This isn't the typical kind of breaking change that impacts the end user. It is a breaking change that potentially impacts other libraries that add onto RuboCop. It will be important to note that this is a breaking change for them. This could impact an end user if a RuboCop extension allows for too high of a version of RuboCop to be included. I'm not sure of the best way to handle this.

@bquorning
Copy link
Contributor Author

One possible way of handling it would be to leave the current implementation intact, with a deprecation warning.

Then add this new implementation of #find_similar_name under another name. Or with the same name, but adding keyword arguments?

-def find_similar_name(target_name, scope)
+def find_similar_name(target_name = nil, names = nil, name: nil, candidates: nil)
+  warn "deprecated" if target_name && names && name.nil? && candidates.nil?

…something along those lines.

@bbatsov
Copy link
Collaborator

bbatsov commented May 10, 2020

@bquorning I don't this we need to overdo this. As @koic said the impact of the change is going to be small (if any). I'd rather us removed this before the 1.0 release. Just update the changelog and we're good to go.

By explicitly passing the collection of "possible names" when calling
`NameSimilarity.find_similar_name`, the calling class doesn't need to
implement a `.collect_variable_like_names` method.
Change `NameSimilarity#find_similar_name` into
`NameSimilarity.find_similar_name`, since it no longer needs to call
back to a method in the same context.
Simplify `NameSimilarity#find_similar_name` by using the built-in
`did_you_mean` gem instead of `StringUtil.similarity`.
Removing `StringUtil` as well, by adding a
`NameSimilarity.find_similar_names` method.
@bquorning
Copy link
Contributor Author

Just update the changelog and we're good to go.

Done

@bbatsov bbatsov merged commit 063b4a8 into rubocop:master May 10, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented May 10, 2020

Thanks!

koic added a commit to rubocop/rubocop-rails that referenced this pull request May 11, 2020
@koic
Copy link
Member

koic commented May 11, 2020

FYI, the edge RuboCop Rails has been independence from RuboCop::NameSimilarity API.
rubocop/rubocop-rails@be82f3b

@bquorning bquorning deleted the did-you-mean branch May 11, 2020 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants