From 752bf8ec9510da060b6a9e7b823fca24fac14fe1 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Fri, 12 Jun 2020 09:16:31 +0200 Subject: [PATCH] [Fixes #7979] SpellChecker may not be available In https://github.com/rubocop-hq/rubocop/issues/7979 it was reported that DidYouMean::SpellChecker may not always be available. We can work around it by doing a feature check before using the SpellChecker class. --- CHANGELOG.md | 1 + lib/rubocop/name_similarity.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index facf7914145..8678a0c9a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#8115](https://github.com/rubocop-hq/rubocop/issues/8115): Fix false negative for `Lint::FormatParameterMismatch` when argument contains formatting. ([@andrykonchin][]) * [#8124](https://github.com/rubocop-hq/rubocop/issues/8124): Fix a false positive for `Lint/FormatParameterMismatch` when using named parameters with escaped `%`. ([@koic][]) +* [#7979](https://github.com/rubocop-hq/rubocop/issues/7979): Fix "uninitialized constant DidYouMean::SpellChecker" exception. ([@bquorning][]) ## 0.85.1 (2020-06-07) diff --git a/lib/rubocop/name_similarity.rb b/lib/rubocop/name_similarity.rb index 917d87bd2f8..8cf0b9a1161 100644 --- a/lib/rubocop/name_similarity.rb +++ b/lib/rubocop/name_similarity.rb @@ -12,6 +12,12 @@ def find_similar_name(target_name, names) 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)