Skip to content

Commit dbd8c2c

Browse files
committed
Fix prism_spot_def_for_name for singletons
1 parent 09a13a0 commit dbd8c2c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lib/error_highlight/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def prism_spot_constant_path_operator_write
913913
# ^^^
914914
def prism_spot_def_for_name
915915
location = @node.name_loc
916-
location = location.join(@node.operator_loc) if @node.operator_loc
916+
location = @node.operator_loc.join(location) if @node.operator_loc
917917
prism_location(location)
918918
end
919919

test/test_error_highlight.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,60 @@ def test_spot_with_node
17331733
assert_equal expected_spot, actual_spot
17341734
end
17351735

1736+
module SingletonMethodWithSpacing
1737+
def self . baz(x:)
1738+
x
1739+
end
1740+
end
1741+
1742+
def test_singleton_method_with_spacing_missing_keyword
1743+
lineno = __LINE__
1744+
assert_error_message(ArgumentError, <<~END) do
1745+
missing keyword: :x (ArgumentError)
1746+
1747+
caller: #{ __FILE__ }:#{ lineno + 16 }
1748+
| SingletonMethodWithSpacing.baz
1749+
^^^^
1750+
callee: #{ __FILE__ }:#{ lineno - 6 }
1751+
#{
1752+
MethodDefLocationSupported ?
1753+
"| def self . baz(x:)
1754+
^^^^^" :
1755+
"(cannot highlight method definition; try Ruby 4.0 or later)"
1756+
}
1757+
END
1758+
1759+
SingletonMethodWithSpacing.baz
1760+
end
1761+
end
1762+
1763+
module SingletonMethodMultipleKwargs
1764+
def self.run(shop_id:, param1:)
1765+
shop_id + param1
1766+
end
1767+
end
1768+
1769+
def test_singleton_method_multiple_missing_keywords
1770+
lineno = __LINE__
1771+
assert_error_message(ArgumentError, <<~END) do
1772+
missing keywords: :shop_id, :param1 (ArgumentError)
1773+
1774+
caller: #{ __FILE__ }:#{ lineno + 16 }
1775+
| SingletonMethodMultipleKwargs.run
1776+
^^^^
1777+
callee: #{ __FILE__ }:#{ lineno - 6 }
1778+
#{
1779+
MethodDefLocationSupported ?
1780+
"| def self.run(shop_id:, param1:)
1781+
^^^^" :
1782+
"(cannot highlight method definition; try Ruby 4.0 or later)"
1783+
}
1784+
END
1785+
1786+
SingletonMethodMultipleKwargs.run
1787+
end
1788+
end
1789+
17361790
private
17371791

17381792
def find_node_by_id(node, node_id)

0 commit comments

Comments
 (0)