Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/error_highlight/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def prism_spot_constant_path_operator_write
# ^^^
def prism_spot_def_for_name
location = @node.name_loc
location = location.join(@node.operator_loc) if @node.operator_loc
location = @node.operator_loc.join(location) if @node.operator_loc
prism_location(location)
end

Expand Down
56 changes: 56 additions & 0 deletions test/test_error_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,62 @@ def test_spot_with_node
assert_equal expected_spot, actual_spot
end

module SingletonMethodWithSpacing
LINENO = __LINE__ + 1
def self . baz(x:)
x
end
end

def test_singleton_method_with_spacing_missing_keyword
lineno = __LINE__
assert_error_message(ArgumentError, <<~END) do
missing keyword: :x (ArgumentError)

caller: #{ __FILE__ }:#{ lineno + 16 }
| SingletonMethodWithSpacing.baz
^^^^
callee: #{ __FILE__ }:#{ SingletonMethodWithSpacing::LINENO }
#{
MethodDefLocationSupported ?
"| def self . baz(x:)
^^^^^" :
"(cannot highlight method definition; try Ruby 4.0 or later)"
}
END

SingletonMethodWithSpacing.baz
end
end

module SingletonMethodMultipleKwargs
LINENO = __LINE__ + 1
def self.run(shop_id:, param1:)
shop_id + param1
end
end

def test_singleton_method_multiple_missing_keywords
lineno = __LINE__
assert_error_message(ArgumentError, <<~END) do
missing keywords: :shop_id, :param1 (ArgumentError)

caller: #{ __FILE__ }:#{ lineno + 16 }
| SingletonMethodMultipleKwargs.run
^^^^
callee: #{ __FILE__ }:#{ SingletonMethodMultipleKwargs::LINENO }
#{
MethodDefLocationSupported ?
"| def self.run(shop_id:, param1:)
^^^^" :
"(cannot highlight method definition; try Ruby 4.0 or later)"
}
END

SingletonMethodMultipleKwargs.run
end
end

private

def find_node_by_id(node, node_id)
Expand Down