Commit 7922badf authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Fix edge case for DocumentationLinks linter

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/358703

**Problem**

Code that ends with a `do` block definition is ignored by parser. The
linter can skip some of broken links because of that.

**Solution**

Add a workaround for this case.
parent fc53b78d
......@@ -12,7 +12,7 @@
= link_to _('New milestone'), new_group_milestone_path(@group), class: "btn gl-button btn-confirm", data: { qa_selector: "new_group_milestone_link" }
- if @milestones.blank?
= render 'shared/empty_states/milestones_tab', learn_more_path: help_page_path('user/group/milestones') do
= render 'shared/empty_states/milestones_tab', learn_more_path: help_page_path('user/project/milestones/index') do
- if can?(current_user, :admin_milestone, @group)
.text-center
= link_to _('New milestone'), new_group_milestone_path(@group), class: "btn gl-button btn-confirm", data: { qa_selector: "new_group_milestone_link" }
......@@ -26,7 +26,7 @@
= render 'milestone', milestone: milestone
= paginate @milestones, theme: "gitlab"
- else
= render 'shared/empty_states/milestones', learn_more_path: help_page_path('user/group/milestones') do
= render 'shared/empty_states/milestones', learn_more_path: help_page_path('user/project/milestones/index') do
- if can?(current_user, :admin_milestone, @group)
.text-center
= link_to _('New milestone'), new_group_milestone_path(@group), class: "btn gl-button btn-confirm", data: { qa_selector: "new_group_milestone_link" }
......@@ -68,7 +68,15 @@ module HamlLint
# Sometimes links are provided via data attributes in html tag
return node.parsed_attributes.syntax_tree if node.type == :tag
node.parsed_script.syntax_tree
parse_script(node).syntax_tree
end
def parse_script(node)
# It's a workaround for cases for scripts ending with "do"
# For some reason they don't parse correctly
code = node.script.delete_suffix(' do')
HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(code))
end
def detect_path_to_file(link)
......
......@@ -43,6 +43,12 @@ RSpec.describe HamlLint::Linter::DocumentationLinks do
let(:haml) { "= link_to 'Description', #{link_pattern}('wrong.md'), target: '_blank'" }
it { is_expected.to report_lint }
context 'when haml ends with block definition' do
let(:haml) { "= link_to 'Description', #{link_pattern}('wrong.md') do" }
it { is_expected.to report_lint }
end
end
context 'when link with wrong file path is assigned to a variable' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment