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

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/name_similarity.rb
rubocop-1.10.0 lib/rubocop/name_similarity.rb
rubocop-1.9.1 lib/rubocop/name_similarity.rb
rubocop-1.9.0 lib/rubocop/name_similarity.rb
rubocop-1.8.1 lib/rubocop/name_similarity.rb
rubocop-1.8.0 lib/rubocop/name_similarity.rb
rubocop-1.7.0 lib/rubocop/name_similarity.rb
rubocop-1.6.1 lib/rubocop/name_similarity.rb
rubocop-1.6.0 lib/rubocop/name_similarity.rb
rubocop-1.5.2 lib/rubocop/name_similarity.rb
rubocop-1.5.1 lib/rubocop/name_similarity.rb
rubocop-1.5.0 lib/rubocop/name_similarity.rb
rubocop-1.4.2 lib/rubocop/name_similarity.rb
rubocop-1.4.1 lib/rubocop/name_similarity.rb
rubocop-1.4.0 lib/rubocop/name_similarity.rb