Skip to content

Commit

Permalink
Remove dependency on jaro_winkler
Browse files Browse the repository at this point in the history
Removing `StringUtil` as well, by adding a
`NameSimilarity.find_similar_names` method.
  • Loading branch information
bquorning committed May 10, 2020
1 parent 84ee8db commit 332e66b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 84 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -41,6 +41,7 @@
* [#7390](https://github.com/rubocop-hq/rubocop/issues/7390): **(Breaking)** Enabling a cop overrides disabling its department. ([@jonas054][])
* [#7936](https://github.com/rubocop-hq/rubocop/issues/7936): Mark `Lint/BooleanSymbol` as unsafe. ([@laurmurclar][])
* [#7948](https://github.com/rubocop-hq/rubocop/pull/7948): Mark unsafe for `Style/OptionalArguments`. ([@koic][])
* [#7931](https://github.com/rubocop-hq/rubocop/pull/7931): Remove dependency on the `jaro_winkler` gem, instead depending on `did_you_mean`. This may be a breaking change for RuboCop libraries calling `NameSimilarity#find_similar_name`. ([@bquorning][])

## 0.82.0 (2020-04-16)

Expand Down
1 change: 0 additions & 1 deletion lib/rubocop.rb
Expand Up @@ -14,7 +14,6 @@
require_relative 'rubocop/path_util'
require_relative 'rubocop/file_finder'
require_relative 'rubocop/platform'
require_relative 'rubocop/string_util'
require_relative 'rubocop/name_similarity'
require_relative 'rubocop/node_pattern'
require_relative 'rubocop/string_interpreter'
Expand Down
10 changes: 7 additions & 3 deletions lib/rubocop/name_similarity.rb
Expand Up @@ -5,16 +5,20 @@ module RuboCop
module NameSimilarity
module_function

MINIMUM_SIMILARITY_TO_SUGGEST = 0.9

def find_similar_name(target_name, names)
similar_names = find_similar_names(target_name, names)

similar_names.first
end

def find_similar_names(target_name, names)
names = names.dup
names.delete(target_name)

spell_checker = DidYouMean::SpellChecker.new(dictionary: names)
similar_names = spell_checker.correct(target_name)

similar_names.first
similar_names
end
end
end
5 changes: 1 addition & 4 deletions lib/rubocop/options.rb
Expand Up @@ -248,10 +248,7 @@ def validate_cop_list(names)
def format_message_from(name, cop_names)
message = 'Unrecognized cop or department: %<name>s.'
message_with_candidate = "%<message>s\nDid you mean? %<candidate>s"
corrections = cop_names.select do |cn|
score = StringUtil.similarity(cn, name)
score >= NameSimilarity::MINIMUM_SIMILARITY_TO_SUGGEST
end.sort
corrections = NameSimilarity.find_similar_names(name, cop_names)

if corrections.empty?
format(message, name: name)
Expand Down
14 changes: 0 additions & 14 deletions lib/rubocop/string_util.rb

This file was deleted.

1 change: 0 additions & 1 deletion rubocop.gemspec
Expand Up @@ -33,7 +33,6 @@ Gem::Specification.new do |s|
'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop/issues'
}

s.add_runtime_dependency('jaro_winkler', '~> 1.5.1')
s.add_runtime_dependency('parallel', '~> 1.10')
s.add_runtime_dependency('parser', '>= 2.7.0.1')
s.add_runtime_dependency('rainbow', '>= 2.2.2', '< 4.0')
Expand Down
61 changes: 0 additions & 61 deletions spec/rubocop/string_util_spec.rb

This file was deleted.

0 comments on commit 332e66b

Please sign in to comment.