Sha256: 9de7401e3fa3a71a2eb2db9468ef5bdb5207f1e5ede1e50df4a41d8251d44eac
Contents?: true
Size: 898 Bytes
Versions: 32
Compression:
Stored size: 898 Bytes
Contents
# frozen_string_literal: true module RuboCop # Common functionality for finding names that are similar to a given name. # @api private module NameSimilarity module_function 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) # DidYouMean::SpellChecker is not available in all versions of Ruby, and # even on versions where it *is* available (>= 2.3), it is not always # required correctly. So we do a feature check first. # See: https://github.com/rubocop-hq/rubocop/issues/7979 return [] unless defined?(DidYouMean::SpellChecker) names = names.dup names.delete(target_name) spell_checker = DidYouMean::SpellChecker.new(dictionary: names) spell_checker.correct(target_name) end end end
Version data entries
32 entries across 32 versions & 3 rubygems