Skip to content

Commit

Permalink
Use DidYouMean instead of NameSimilarity for spell checker
Browse files Browse the repository at this point in the history
Follow up to rubocop/rubocop#7931.
  • Loading branch information
koic committed May 11, 2020
1 parent 891c6aa commit be82f3b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/rubocop/cop/rails/unknown_env.rb
Expand Up @@ -15,8 +15,6 @@ module Rails
# Rails.env.production?
# Rails.env == 'production'
class UnknownEnv < Cop
include NameSimilarity

MSG = 'Unknown environment `%<name>s`.'
MSG_SIMILAR = 'Unknown environment `%<name>s`. ' \
'Did you mean `%<similar>s`?'
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit be82f3b

Please sign in to comment.