Skip to content

Commit

Permalink
Change find_similar_name to a module_function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bquorning authored and bbatsov committed May 10, 2020
1 parent 77b59de commit fd3ba1f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Lint
# # good
# x += 1
class RedundantCopDisableDirective < Cop
include NameSimilarity
include RangeHelp

COP_NAME = 'Lint/RedundantCopDisableDirective'
Expand Down Expand Up @@ -235,7 +234,7 @@ def describe(cop)
elsif all_cop_names.include?(cop)
"`#{cop}`"
else
similar = find_similar_name(cop, all_cop_names)
similar = NameSimilarity.find_similar_name(cop, all_cop_names)
if similar
"`#{cop}` (did you mean `#{similar}`?)"
else
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/useless_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Lint
# do_something(some_var)
# end
class UselessAssignment < Cop
include NameSimilarity
MSG = 'Useless assignment to variable - `%<variable>s`.'

def join_force?(force_class)
Expand Down Expand Up @@ -95,7 +94,8 @@ def operator_assignment_message(scope, assignment)

def similar_name_message(variable)
variable_like_names = collect_variable_like_names(variable.scope)
similar_name = find_similar_name(variable.name, variable_like_names)
similar_name = NameSimilarity.find_similar_name(variable.name,
variable_like_names)
" Did you mean `#{similar_name}`?" if similar_name
end

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/name_similarity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module RuboCop
# Common functionality for finding names that are similar to a given name.
module NameSimilarity
module_function

MINIMUM_SIMILARITY_TO_SUGGEST = 0.9

def find_similar_name(target_name, names)
Expand Down

0 comments on commit fd3ba1f

Please sign in to comment.