Skip to content

Commit

Permalink
Fixed correction duplicates in VariableNameChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
makketagg committed May 21, 2022
1 parent 80c74fe commit c3fc412
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def initialize(exception)
def corrections
@corrections ||= SpellChecker
.new(dictionary: (RB_RESERVED_WORDS + lvar_names + method_names + ivar_names + cvar_names))
.correct(name) - NAMES_TO_EXCLUDE[@name]
.correct(name).uniq - NAMES_TO_EXCLUDE[@name]
end
end
end
12 changes: 12 additions & 0 deletions test/spell_checking/test_variable_name_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,16 @@ def test_exclude_typical_incorrect_suggestions
error = assert_raise(NameError){ foo }
assert_empty error.corrections
end

def test_exclude_duplicates_with_same_name
error = assert_raise(NameError) do
eval(<<~RUBY, binding, __FILE__, __LINE__)
bar = 1
def bar;end
zar
RUBY
end

assert_correction [:bar], error.corrections
end
end

0 comments on commit c3fc412

Please sign in to comment.