Sha256: d6a294a78e40c9142bf66ee2aa46a06047d79cd11e50e613139dc01f6edea241

Contents?: true

Size: 895 Bytes

Versions: 227

Compression:

Stored size: 895 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/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

227 entries across 218 versions & 21 rubygems

Version Path
rubocop-1.54.0 lib/rubocop/name_similarity.rb
rubocop-1.53.1 lib/rubocop/name_similarity.rb
rubocop-1.53.0 lib/rubocop/name_similarity.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/name_similarity.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/name_similarity.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/name_similarity.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/name_similarity.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/name_similarity.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/name_similarity.rb
rubocop-1.52.1 lib/rubocop/name_similarity.rb
rubocop-1.52.0 lib/rubocop/name_similarity.rb
rubocop-1.51.0 lib/rubocop/name_similarity.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/rubocop-1.50.2/lib/rubocop/name_similarity.rb
rubocop-1.50.2 lib/rubocop/name_similarity.rb
rubocop-1.50.1 lib/rubocop/name_similarity.rb
rubocop-1.50.0 lib/rubocop/name_similarity.rb
rubocop-1.49.0 lib/rubocop/name_similarity.rb
call_your_name-0.1.0 vendor/bundle/ruby/3.1.0/gems/rubocop-1.48.1/lib/rubocop/name_similarity.rb
rubocop-1.48.1 lib/rubocop/name_similarity.rb
rubocop-1.48.0 lib/rubocop/name_similarity.rb