mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
parent
9a42d14a1e
commit
44290a6a5d
4 changed files with 39 additions and 1 deletions
|
@ -60,6 +60,24 @@ module Ameba::AST
|
|||
" end",
|
||||
])
|
||||
end
|
||||
|
||||
it "does not report source of node which has incorrect location" do
|
||||
s = %q(
|
||||
module MyModule
|
||||
macro conditional_error_for_inline_callbacks
|
||||
\{%
|
||||
raise ""
|
||||
%}
|
||||
end
|
||||
|
||||
macro before_save(x = nil)
|
||||
end
|
||||
end
|
||||
)
|
||||
node = as_nodes(s).nil_literal_nodes.first
|
||||
source = subject.node_source node, s.split("\n")
|
||||
source.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#flow_command?" do
|
||||
|
|
|
@ -95,6 +95,22 @@ module Ameba
|
|||
end
|
||||
)
|
||||
|
||||
it "does not report emtpy expression in macro" do
|
||||
s = Source.new %q(
|
||||
module MyModule
|
||||
macro conditional_error_for_inline_callbacks
|
||||
\{%
|
||||
raise ""
|
||||
%}
|
||||
end
|
||||
|
||||
macro before_save(x = nil)
|
||||
end
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it "reports rule, location and message" do
|
||||
s = Source.new %(
|
||||
if ()
|
||||
|
|
|
@ -151,6 +151,7 @@ module Ameba
|
|||
|
||||
class TestNodeVisitor < Crystal::Visitor
|
||||
NODES = [
|
||||
Crystal::NilLiteral,
|
||||
Crystal::Var,
|
||||
Crystal::Assign,
|
||||
Crystal::OpAssign,
|
||||
|
|
|
@ -40,7 +40,8 @@ module Ameba::AST::Util
|
|||
node_lines = code_lines[line..end_line]
|
||||
first_line, last_line = node_lines[0]?, node_lines[-1]?
|
||||
|
||||
return unless first_line && last_line
|
||||
return if first_line.nil? || last_line.nil?
|
||||
return if first_line.size < column # compiler reports incorrection location
|
||||
|
||||
node_lines[0] = first_line.sub(0...column, "")
|
||||
|
||||
|
@ -48,6 +49,8 @@ module Ameba::AST::Util
|
|||
end_column = end_column - column
|
||||
last_line = node_lines[0]
|
||||
end
|
||||
|
||||
return if last_line.size < end_column + 1
|
||||
node_lines[-1] = last_line.sub(end_column + 1...last_line.size, "")
|
||||
|
||||
node_lines
|
||||
|
|
Loading…
Reference in a new issue