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
15 changes: 15 additions & 0 deletions src/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ static bool find_earliest_control_keyword_walker(const pm_node_t* node, void* da
break;
}

case PM_LAMBDA_NODE: {
pm_lambda_node_t* lambda = (pm_lambda_node_t*) node;

bool has_do_opening = is_do_block(lambda->opening_loc);
bool has_brace_opening = is_brace_block(lambda->opening_loc);
bool has_valid_brace_closing = is_closing_brace(lambda->closing_loc);

if (has_do_opening || (has_brace_opening && !has_valid_brace_closing)) {
current_type = CONTROL_TYPE_BLOCK;
keyword_offset = (uint32_t) (node->location.start - context->source_start);
}

break;
}

case PM_NEXT_NODE:
case PM_BREAK_NODE:
case PM_RETURN_NODE: {
Expand Down
20 changes: 20 additions & 0 deletions src/analyze_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ bool search_block_nodes(const pm_node_t* node, void* data) {
if (has_opening && is_unclosed) { analyzed->block_node_count++; }
}

if (node->type == PM_LAMBDA_NODE) {
pm_lambda_node_t* lambda_node = (pm_lambda_node_t*) node;

bool has_opening = is_do_block(lambda_node->opening_loc) || is_brace_block(lambda_node->opening_loc);
bool is_unclosed = !has_valid_block_closing(lambda_node->opening_loc, lambda_node->closing_loc);

if (has_opening && is_unclosed) { analyzed->block_node_count++; }
}

pm_visit_child_nodes(node, search_block_nodes, analyzed);

return false;
Expand Down Expand Up @@ -494,6 +503,17 @@ bool search_unclosed_control_flows(const pm_node_t* node, void* data) {
break;
}

case PM_LAMBDA_NODE: {
const pm_lambda_node_t* lambda_node = (const pm_lambda_node_t*) node;
bool has_opening = is_do_block(lambda_node->opening_loc) || is_brace_block(lambda_node->opening_loc);

if (has_opening && !has_valid_block_closing(lambda_node->opening_loc, lambda_node->closing_loc)) {
analyzed->unclosed_control_flow_count++;
}

break;
}

default: break;
}

Expand Down
88 changes: 88 additions & 0 deletions test/analyze/block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,93 @@ class BlockTest < Minitest::Spec
<% end %>
HTML
end

test "stabby lambda with do block" do
assert_parsed_snapshot(<<~HTML)
<% content = -> do %>
Content
<% end %>
HTML
end

test "stabby lambda with do block and params" do
assert_parsed_snapshot(<<~HTML)
<% content = ->(x) do %>
Content
<% end %>
HTML
end

test "lambda keyword with do block" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda do %>
Content
<% end %>
HTML
end

test "lambda keyword with do block and params" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda do |x| %>
Content
<% end %>
HTML
end

test "inline stabby lambda with do/end in single tag" do
assert_parsed_snapshot(<<~HTML)
<% content = -> do; end %>
HTML
end

test "inline lambda keyword with do/end in single tag" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda do; end %>
HTML
end

test "stabby lambda with brace block" do
assert_parsed_snapshot(<<~HTML)
<% content = -> { %>
Content
<% } %>
HTML
end

test "lambda keyword with brace block" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda { %>
Content
<% } %>
HTML
end

test "unclosed stabby lambda with do block" do
assert_parsed_snapshot(<<~HTML)
<% content = -> do %>
Content
HTML
end

test "unclosed stabby lambda with brace block" do
assert_parsed_snapshot(<<~HTML)
<% content = -> { %>
Content
HTML
end

test "unclosed lambda keyword with do block" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda do %>
Content
HTML
end

test "unclosed lambda keyword with brace block" do
assert_parsed_snapshot(<<~HTML)
<% content = lambda { %>
Content
HTML
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading