From 3be5f2409a03faccb554483ff01509d5f630f10a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Sat, 8 May 2021 03:10:38 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- haml_lint/linter/documentation_links.rb | 19 ++++++++++++------- .../linter/documentation_links_spec.rb | 6 ++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/haml_lint/linter/documentation_links.rb b/haml_lint/linter/documentation_links.rb index a36b095bc11..8c696b26b13 100644 --- a/haml_lint/linter/documentation_links.rb +++ b/haml_lint/linter/documentation_links.rb @@ -13,7 +13,7 @@ module HamlLint DOCS_DIRECTORY = File.join(File.expand_path('../..', __dir__), 'doc') HELP_PATH_LINK_PATTERN = <<~PATTERN - `(send nil? {:help_page_url :help_page_path} $...) + (send nil? {:help_page_url :help_page_path} $...) PATTERN MARKDOWN_HEADER = %r{\A\#{1,6}\s+(?
.+)\Z}.freeze @@ -33,8 +33,17 @@ module HamlLint private def check(node) - match = extract_link_and_anchor(node) + ast_tree = fetch_ast_tree(node) + return unless ast_tree + + ast_tree.descendants.each do |child_node| + match = extract_link_and_anchor(child_node) + validate_node(node, match) + end + end + + def validate_node(node, match) return if match.empty? path_to_file = detect_path_to_file(match[:link]) @@ -49,11 +58,7 @@ module HamlLint end end - def extract_link_and_anchor(node) - ast_tree = fetch_ast_tree(node) - - return {} unless ast_tree - + def extract_link_and_anchor(ast_tree) link_match, attributes_match = ::RuboCop::NodePattern.new(HELP_PATH_LINK_PATTERN).match(ast_tree) { link: fetch_link(link_match), anchor: fetch_anchor(attributes_match) }.compact diff --git a/spec/haml_lint/linter/documentation_links_spec.rb b/spec/haml_lint/linter/documentation_links_spec.rb index 5de455b6e8c..22c406de57a 100644 --- a/spec/haml_lint/linter/documentation_links_spec.rb +++ b/spec/haml_lint/linter/documentation_links_spec.rb @@ -80,6 +80,12 @@ RSpec.describe HamlLint::Linter::DocumentationLinks do it { is_expected.to report_lint } end + + context 'when the second link is invalid' do + let(:haml) { ".data-form{ data: { url: #{link_pattern}('README.md'), wrong_url: #{link_pattern}('wrong.md') } }" } + + it { is_expected.to report_lint } + end end context 'help_page_path' do