Sha256: ffecb60201ef70faa0ffabc9c9ae38f9a0957fb06c8ec9fe16ceb17ad67ae18c
Contents?: true
Size: 881 Bytes
Versions: 6
Compression:
Stored size: 881 Bytes
Contents
# frozen_string_literal: true module RuboCop # Common functionality for finding names that are similar to a given name. 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
6 entries across 6 versions & 2 rubygems