Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2021-05-08 03:10:38 +00:00
parent 6214ac71ff
commit 3be5f2409a
2 changed files with 18 additions and 7 deletions

View File

@ -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+(?<header>.+)\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

View File

@ -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