From be82f3b0d2a1966089738849106d99bee4d3df19 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 11 May 2020 09:03:24 +0900 Subject: [PATCH] Use `DidYouMean` instead of `NameSimilarity` for spell checker Follow up to https://github.com/rubocop-hq/rubocop/pull/7931. --- lib/rubocop/cop/rails/unknown_env.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/rubocop/cop/rails/unknown_env.rb b/lib/rubocop/cop/rails/unknown_env.rb index 8bc3e6dd76..cc55c2dc78 100644 --- a/lib/rubocop/cop/rails/unknown_env.rb +++ b/lib/rubocop/cop/rails/unknown_env.rb @@ -15,8 +15,6 @@ module Rails # Rails.env.production? # Rails.env == 'production' class UnknownEnv < Cop - include NameSimilarity - MSG = 'Unknown environment `%s`.' MSG_SIMILAR = 'Unknown environment `%s`. ' \ 'Did you mean `%s`?' @@ -57,11 +55,14 @@ def collect_variable_like_names(_scope) def message(name) name = name.to_s.chomp('?') - similar = find_similar_name(name, []) - if similar - format(MSG_SIMILAR, name: name, similar: similar) - else + + spell_checker = DidYouMean::SpellChecker.new(dictionary: environments) + similar_names = spell_checker.correct(name) + + if similar_names.empty? format(MSG, name: name) + else + format(MSG_SIMILAR, name: name, similar: similar_names.join(', ')) end end