diff --git a/haml_lint/linter/documentation_links.rb b/haml_lint/linter/documentation_links.rb index 0cabae40c4b5a6187022a038b1557c4e376bf249..9d80344dd20239f1c072a941aa223c5ab071aeb7 100644 --- a/haml_lint/linter/documentation_links.rb +++ b/haml_lint/linter/documentation_links.rb @@ -9,11 +9,12 @@ class Linter class DocumentationLinks < Linter include ::HamlLint::LinterRegistry include ::Gitlab::Utils::Markdown + extend ::RuboCop::AST::NodePattern::Macros DOCS_DIRECTORY = File.join(File.expand_path('../..', __dir__), 'doc') - HELP_PATH_LINK_PATTERN = <<~PATTERN - (send nil? {:help_page_url :help_page_path} $...) + def_node_matcher :help_link, <<~PATTERN + (send _ {:help_page_url :help_page_path} $...) PATTERN MARKDOWN_HEADER = %r{\A\#{1,6}\s+(?<header>.+)\Z}.freeze @@ -59,7 +60,7 @@ def validate_node(node, match) end def extract_link_and_anchor(ast_tree) - link_match, attributes_match = ::RuboCop::NodePattern.new(HELP_PATH_LINK_PATTERN).match(ast_tree) + link_match, attributes_match = help_link(ast_tree) { link: fetch_link(link_match), anchor: fetch_anchor(attributes_match) }.compact end diff --git a/spec/haml_lint/linter/documentation_links_spec.rb b/spec/haml_lint/linter/documentation_links_spec.rb index 380df49cde3549f5496f37c0af3a2ca01f13a99e..d47127d966124ada9e24ca0c9097800b799219df 100644 --- a/spec/haml_lint/linter/documentation_links_spec.rb +++ b/spec/haml_lint/linter/documentation_links_spec.rb @@ -6,7 +6,7 @@ require_relative '../../../haml_lint/linter/documentation_links' -RSpec.describe HamlLint::Linter::DocumentationLinks do +RSpec.describe HamlLint::Linter::DocumentationLinks, feature_category: :tooling do include_context 'linter' shared_examples 'link validation rules' do |link_pattern| @@ -95,11 +95,8 @@ end end - context 'help_page_path' do - it_behaves_like 'link validation rules', 'help_page_path' - end - - context 'help_page_url' do - it_behaves_like 'link validation rules', 'help_page_url' - end + it_behaves_like 'link validation rules', 'help_page_path' + it_behaves_like 'link validation rules', 'help_page_url' + it_behaves_like 'link validation rules', 'Rails.application.routes.url_helpers.help_page_url' + it_behaves_like 'link validation rules', 'Gitlab::Routing.url_helpers.help_page_url' end