mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/error_highlight] Keep it work if paren exists after receiver
b79d679bbd
This commit is contained in:
parent
4ab5281601
commit
242f024bcb
2 changed files with 171 additions and 11 deletions
|
@ -148,7 +148,7 @@ module ErrorHighlight
|
||||||
nd_recv, mid, nd_args = @node.children
|
nd_recv, mid, nd_args = @node.children
|
||||||
lineno = nd_recv.last_lineno
|
lineno = nd_recv.last_lineno
|
||||||
lines = @fetch[lineno, @node.last_lineno]
|
lines = @fetch[lineno, @node.last_lineno]
|
||||||
if mid == :[] && lines.match(/\G\s*(\[(?:\s*\])?)/, nd_recv.last_column)
|
if mid == :[] && lines.match(/\G[\s)]*(\[(?:\s*\])?)/, nd_recv.last_column)
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
@snippet = lines[/.*\n/]
|
@snippet = lines[/.*\n/]
|
||||||
@beg_lineno = @end_lineno = lineno
|
@beg_lineno = @end_lineno = lineno
|
||||||
|
@ -157,11 +157,11 @@ module ErrorHighlight
|
||||||
@end_column = $~.end(0)
|
@end_column = $~.end(0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if lines.match(/\G\s*?\[\s*\]/, nd_recv.last_column)
|
if lines.match(/\G[\s)]*?\[\s*\]/, nd_recv.last_column)
|
||||||
@end_column = $~.end(0)
|
@end_column = $~.end(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif lines.match(/\G\s*?(\&?\.)(\s*?)(#{ Regexp.quote(mid) }).*\n/, nd_recv.last_column)
|
elsif lines.match(/\G[\s)]*?(\&?\.)(\s*?)(#{ Regexp.quote(mid) }).*\n/, nd_recv.last_column)
|
||||||
lines = $` + $&
|
lines = $` + $&
|
||||||
@beg_column = $~.begin($2.include?("\n") ? 3 : 1)
|
@beg_column = $~.begin($2.include?("\n") ? 3 : 1)
|
||||||
@end_column = $~.end(3)
|
@end_column = $~.end(3)
|
||||||
|
@ -207,16 +207,16 @@ module ErrorHighlight
|
||||||
nd_recv, mid, nd_args = @node.children
|
nd_recv, mid, nd_args = @node.children
|
||||||
*nd_args, _nd_last_arg, _nil = nd_args.children
|
*nd_args, _nd_last_arg, _nil = nd_args.children
|
||||||
fetch_line(nd_recv.last_lineno)
|
fetch_line(nd_recv.last_lineno)
|
||||||
if mid == :[]= && @snippet.match(/\G\s*(\[)/, nd_recv.last_column)
|
if mid == :[]= && @snippet.match(/\G[\s)]*(\[)/, nd_recv.last_column)
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
args_last_column = $~.end(0)
|
args_last_column = $~.end(0)
|
||||||
if nd_args.last && nd_recv.last_lineno == nd_args.last.last_lineno
|
if nd_args.last && nd_recv.last_lineno == nd_args.last.last_lineno
|
||||||
args_last_column = nd_args.last.last_column
|
args_last_column = nd_args.last.last_column
|
||||||
end
|
end
|
||||||
if @snippet.match(/\s*\]\s*=/, args_last_column)
|
if @snippet.match(/[\s)]*\]\s*=/, args_last_column)
|
||||||
@end_column = $~.end(0)
|
@end_column = $~.end(0)
|
||||||
end
|
end
|
||||||
elsif @snippet.match(/\G\s*(\.\s*#{ Regexp.quote(mid.to_s.sub(/=\z/, "")) }\s*=)/, nd_recv.last_column)
|
elsif @snippet.match(/\G[\s)]*(\.\s*#{ Regexp.quote(mid.to_s.sub(/=\z/, "")) }\s*=)/, nd_recv.last_column)
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
@end_column = $~.end(1)
|
@end_column = $~.end(1)
|
||||||
end
|
end
|
||||||
|
@ -232,7 +232,7 @@ module ErrorHighlight
|
||||||
def spot_attrasgn_for_args
|
def spot_attrasgn_for_args
|
||||||
nd_recv, mid, nd_args = @node.children
|
nd_recv, mid, nd_args = @node.children
|
||||||
fetch_line(nd_recv.last_lineno)
|
fetch_line(nd_recv.last_lineno)
|
||||||
if mid == :[]= && @snippet.match(/\G\s*\[/, nd_recv.last_column)
|
if mid == :[]= && @snippet.match(/\G[\s)]*\[/, nd_recv.last_column)
|
||||||
@beg_column = $~.end(0)
|
@beg_column = $~.end(0)
|
||||||
if nd_recv.last_lineno == nd_args.last_lineno
|
if nd_recv.last_lineno == nd_args.last_lineno
|
||||||
@end_column = nd_args.last_column
|
@end_column = nd_args.last_column
|
||||||
|
@ -254,7 +254,7 @@ module ErrorHighlight
|
||||||
fetch_line(nd_recv.last_lineno)
|
fetch_line(nd_recv.last_lineno)
|
||||||
if nd_arg
|
if nd_arg
|
||||||
# binary operator
|
# binary operator
|
||||||
if @snippet.match(/\G\s*(#{ Regexp.quote(op) })/, nd_recv.last_column)
|
if @snippet.match(/\G[\s)]*(#{ Regexp.quote(op) })/, nd_recv.last_column)
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
@end_column = $~.end(1)
|
@end_column = $~.end(1)
|
||||||
end
|
end
|
||||||
|
@ -330,7 +330,7 @@ module ErrorHighlight
|
||||||
def spot_op_asgn1_for_name
|
def spot_op_asgn1_for_name
|
||||||
nd_recv, op, nd_args, _nd_rhs = @node.children
|
nd_recv, op, nd_args, _nd_rhs = @node.children
|
||||||
fetch_line(nd_recv.last_lineno)
|
fetch_line(nd_recv.last_lineno)
|
||||||
if @snippet.match(/\G\s*(\[)/, nd_recv.last_column)
|
if @snippet.match(/\G[\s)]*(\[)/, nd_recv.last_column)
|
||||||
bracket_beg_column = $~.begin(1)
|
bracket_beg_column = $~.begin(1)
|
||||||
args_last_column = $~.end(0)
|
args_last_column = $~.end(0)
|
||||||
if nd_args && nd_recv.last_lineno == nd_args.last_lineno
|
if nd_args && nd_recv.last_lineno == nd_args.last_lineno
|
||||||
|
@ -377,7 +377,7 @@ module ErrorHighlight
|
||||||
def spot_op_asgn2_for_name
|
def spot_op_asgn2_for_name
|
||||||
nd_recv, _qcall, attr, op, _nd_rhs = @node.children
|
nd_recv, _qcall, attr, op, _nd_rhs = @node.children
|
||||||
fetch_line(nd_recv.last_lineno)
|
fetch_line(nd_recv.last_lineno)
|
||||||
if @snippet.match(/\G\s*(\.)\s*#{ Regexp.quote(attr) }()\s*(#{ Regexp.quote(op) })(=)/, nd_recv.last_column)
|
if @snippet.match(/\G[\s)]*(\.)\s*#{ Regexp.quote(attr) }()\s*(#{ Regexp.quote(op) })(=)/, nd_recv.last_column)
|
||||||
case @name
|
case @name
|
||||||
when attr
|
when attr
|
||||||
@beg_column = $~.begin(1)
|
@beg_column = $~.begin(1)
|
||||||
|
|
|
@ -66,6 +66,18 @@ undefined method `foo' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_CALL_noarg_4
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `foo' for nil:NilClass
|
||||||
|
|
||||||
|
(nil).foo + 1
|
||||||
|
^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(nil).foo + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_CALL_arg_1
|
def test_CALL_arg_1
|
||||||
assert_error_message(NoMethodError, <<~END) do
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
undefined method `foo' for nil:NilClass
|
undefined method `foo' for nil:NilClass
|
||||||
|
@ -222,6 +234,18 @@ undefined method `[]' for #{ v.inspect }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_CALL_aref_5
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `[]' for nil:NilClass
|
||||||
|
|
||||||
|
(nil)[ ]
|
||||||
|
^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(nil)[ ]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_CALL_aset
|
def test_CALL_aset
|
||||||
assert_error_message(NoMethodError, <<~END) do
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
undefined method `[]=' for nil:NilClass
|
undefined method `[]=' for nil:NilClass
|
||||||
|
@ -313,6 +337,30 @@ undefined method `foo=' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ATTRASGN_4
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `[]=' for nil:NilClass
|
||||||
|
|
||||||
|
(nil)[0] = 42
|
||||||
|
^^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(nil)[0] = 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_ATTRASGN_5
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `foo=' for nil:NilClass
|
||||||
|
|
||||||
|
(nil).foo = 42
|
||||||
|
^^^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(nil).foo = 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OPCALL_binary_1
|
def test_OPCALL_binary_1
|
||||||
assert_error_message(NoMethodError, <<~END) do
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
undefined method `+' for nil:NilClass
|
undefined method `+' for nil:NilClass
|
||||||
|
@ -338,7 +386,19 @@ undefined method `+' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_OPCALL_unary
|
def test_OPCALL_binary_3
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `+' for nil:NilClass
|
||||||
|
|
||||||
|
(nil) + 42
|
||||||
|
^
|
||||||
|
END
|
||||||
|
|
||||||
|
(nil) + 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_OPCALL_unary_1
|
||||||
assert_error_message(NoMethodError, <<~END) do
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
undefined method `+@' for nil:NilClass
|
undefined method `+@' for nil:NilClass
|
||||||
|
|
||||||
|
@ -350,6 +410,18 @@ undefined method `+@' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OPCALL_unary_2
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `+@' for nil:NilClass
|
||||||
|
|
||||||
|
+(nil)
|
||||||
|
^
|
||||||
|
END
|
||||||
|
|
||||||
|
+(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_FCALL_1
|
def test_FCALL_1
|
||||||
assert_error_message(NoMethodError, <<~END) do
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
undefined method `foo' for nil:NilClass
|
undefined method `foo' for nil:NilClass
|
||||||
|
@ -429,6 +501,20 @@ undefined method `[]' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN1_aref_4
|
||||||
|
v = nil
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `[]' for nil:NilClass
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OP_ASGN1_op_1
|
def test_OP_ASGN1_op_1
|
||||||
v = Object.new
|
v = Object.new
|
||||||
def v.[](x); nil; end
|
def v.[](x); nil; end
|
||||||
|
@ -475,6 +561,21 @@ undefined method `+' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN1_op_4
|
||||||
|
v = Object.new
|
||||||
|
def v.[](x); nil; end
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `+' for nil:NilClass
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OP_ASGN1_aset_1
|
def test_OP_ASGN1_aset_1
|
||||||
v = Object.new
|
v = Object.new
|
||||||
def v.[](x); 1; end
|
def v.[](x); 1; end
|
||||||
|
@ -521,6 +622,21 @@ undefined method `[]=' for #{ v.inspect }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN1_aset_4
|
||||||
|
v = Object.new
|
||||||
|
def v.[](x); 1; end
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `[]=' for #{ v.inspect }
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
^^^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v)[0] += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OP_ASGN2_read_1
|
def test_OP_ASGN2_read_1
|
||||||
v = nil
|
v = nil
|
||||||
|
|
||||||
|
@ -550,6 +666,20 @@ undefined method `foo' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN2_read_3
|
||||||
|
v = nil
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `foo' for nil:NilClass
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OP_ASGN2_op_1
|
def test_OP_ASGN2_op_1
|
||||||
v = Object.new
|
v = Object.new
|
||||||
def v.foo; nil; end
|
def v.foo; nil; end
|
||||||
|
@ -581,6 +711,21 @@ undefined method `+' for nil:NilClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN2_op_3
|
||||||
|
v = Object.new
|
||||||
|
def v.foo; nil; end
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `+' for nil:NilClass
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_OP_ASGN2_write_1
|
def test_OP_ASGN2_write_1
|
||||||
v = Object.new
|
v = Object.new
|
||||||
def v.foo; 1; end
|
def v.foo; 1; end
|
||||||
|
@ -612,6 +757,21 @@ undefined method `foo=' for #{ v.inspect }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_OP_ASGN2_write_3
|
||||||
|
v = Object.new
|
||||||
|
def v.foo; 1; end
|
||||||
|
|
||||||
|
assert_error_message(NoMethodError, <<~END) do
|
||||||
|
undefined method `foo=' for #{ v.inspect }
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
^^^^^^^
|
||||||
|
END
|
||||||
|
|
||||||
|
(v).foo += 42
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_CONST
|
def test_CONST
|
||||||
assert_error_message(NameError, <<~END) do
|
assert_error_message(NameError, <<~END) do
|
||||||
uninitialized constant ErrorHighlightTest::NotDefined
|
uninitialized constant ErrorHighlightTest::NotDefined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue