Skip to content

Commit c3fc412

Browse files
committed
Fixed correction duplicates in VariableNameChecker
1 parent 80c74fe commit c3fc412

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def initialize(exception)
7979
def corrections
8080
@corrections ||= SpellChecker
8181
.new(dictionary: (RB_RESERVED_WORDS + lvar_names + method_names + ivar_names + cvar_names))
82-
.correct(name) - NAMES_TO_EXCLUDE[@name]
82+
.correct(name).uniq - NAMES_TO_EXCLUDE[@name]
8383
end
8484
end
8585
end

test/spell_checking/test_variable_name_check.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,16 @@ def test_exclude_typical_incorrect_suggestions
137137
error = assert_raise(NameError){ foo }
138138
assert_empty error.corrections
139139
end
140+
141+
def test_exclude_duplicates_with_same_name
142+
error = assert_raise(NameError) do
143+
eval(<<~RUBY, binding, __FILE__, __LINE__)
144+
bar = 1
145+
def bar;end
146+
zar
147+
RUBY
148+
end
149+
150+
assert_correction [:bar], error.corrections
151+
end
140152
end

0 commit comments

Comments
 (0)