Skip to content

Commit

Permalink
Merge pull request #176 from makketagg/fix/variable-name-corrections-…
Browse files Browse the repository at this point in the history
…duplicates

Fixed correction duplicates in VaribaleNameChecker
  • Loading branch information
hsbt authored Sep 1, 2022
2 parents 9dce63d + c3fc412 commit c629aef
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 c629aef

Please sign in to comment.