Skip to content
代码片段 群组 项目
未验证 提交 f0722956 编辑于 作者: Peter Leitzen's avatar Peter Leitzen
浏览文件

Linter/DocumentationLinks: Flag help links with receivers

Match the following use cases too:

= Rails.application.routes.url_helpers.help_page_path("invalid/path")

This commit also improves the speed of this lint rule by caching the
node pattern.
上级 0f7c9055
No related branches found
No related tags found
1 合并请求!1355Draft: Reset password by phone with geetest captcha
......@@ -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
......
......@@ -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
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册