diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 511aa29de5891a7d326f2edb7f4d972ab549aa61..a08ab491470f7e3202b3cd5b1f8408bcc1e4ed83 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -1,7 +1,161 @@ # This configuration was generated by # `haml-lint --auto-gen-config` -# on 2022-10-19 13:09:51 +0200 using Haml-Lint version 0.40.1. +# on 2023-10-11 14:54:51 +0200 using Haml-Lint version 0.40.1. # The point is for the user to remove these configuration records # one by one as the lints are removed from the code base. # Note that changes in the inspected code, or installation of new -# versions of Haml-Lint, may require this file to be generated again. \ No newline at end of file +# versions of Haml-Lint, may require this file to be generated again. + +linters: + + # Offense count: 201 + DocumentationLinks: + exclude: + - "app/views/admin/application_settings/_account_and_limit.html.haml" + - "app/views/admin/application_settings/_ci_cd.html.haml" + - "app/views/admin/application_settings/_diagramsnet.html.haml" + - "app/views/admin/application_settings/_email.html.haml" + - "app/views/admin/application_settings/_error_tracking.html.haml" + - "app/views/admin/application_settings/_floc.html.haml" + - "app/views/admin/application_settings/_gitlab_shell_operation_limits.html.haml" + - "app/views/admin/application_settings/_gitpod.html.haml" + - "app/views/admin/application_settings/_kroki.html.haml" + - "app/views/admin/application_settings/_localization.html.haml" + - "app/views/admin/application_settings/_outbound.html.haml" + - "app/views/admin/application_settings/_plantuml.html.haml" + - "app/views/admin/application_settings/_projects_api_limits.html.haml" + - "app/views/admin/application_settings/_repository_check.html.haml" + - "app/views/admin/application_settings/_repository_storage.html.haml" + - "app/views/admin/application_settings/_runner_registrars_form.html.haml" + - "app/views/admin/application_settings/_signin.html.haml" + - "app/views/admin/application_settings/_sourcegraph.html.haml" + - "app/views/admin/application_settings/_spam.html.haml" + - "app/views/admin/application_settings/_terms.html.haml" + - "app/views/admin/application_settings/general.html.haml" + - "app/views/admin/application_settings/metrics_and_profiling.html.haml" + - "app/views/admin/application_settings/network.html.haml" + - "app/views/admin/application_settings/preferences.html.haml" + - "app/views/admin/application_settings/reporting.html.haml" + - "app/views/admin/application_settings/repository.html.haml" + - "app/views/admin/dashboard/index.html.haml" + - "app/views/admin/dev_ops_report/_score.html.haml" + - "app/views/clusters/clusters/_advanced_settings.html.haml" + - "app/views/clusters/clusters/_deprecation_alert.html.haml" + - "app/views/clusters/clusters/_multiple_clusters_message.html.haml" + - "app/views/clusters/clusters/_namespace.html.haml" + - "app/views/clusters/clusters/_provider_details_form.html.haml" + - "app/views/clusters/clusters/cloud_providers/_cloud_provider_selector.html.haml" + - "app/views/clusters/clusters/show.html.haml" + - "app/views/clusters/clusters/user/_form.html.haml" + - "app/views/groups/_import_group_from_another_instance_panel.html.haml" + - "app/views/groups/_import_group_from_file_panel.html.haml" + - "app/views/groups/settings/ci_cd/_auto_devops_form.html.haml" + - "app/views/notify/github_gists_import_errors_email.html.haml" + - "app/views/notify/pages_domain_auto_ssl_failed_email.html.haml" + - "app/views/notify/pages_domain_auto_ssl_failed_email.text.haml" + - "app/views/notify/pages_domain_disabled_email.html.haml" + - "app/views/notify/pages_domain_enabled_email.html.haml" + - "app/views/notify/pages_domain_verification_failed_email.html.haml" + - "app/views/notify/pages_domain_verification_succeeded_email.html.haml" + - "app/views/profiles/gpg_keys/index.html.haml" + - "app/views/profiles/keys/_key.html.haml" + - "app/views/profiles/keys/index.html.haml" + - "app/views/profiles/personal_access_tokens/index.html.haml" + - "app/views/profiles/show.html.haml" + - "app/views/profiles/two_factor_auths/show.html.haml" + - "app/views/projects/blob/_pipeline_tour_success.html.haml" + - "app/views/projects/blob/viewers/_route_map.html.haml" + - "app/views/projects/blob/viewers/_route_map_loading.html.haml" + - "app/views/projects/branch_defaults/_branch_names_fields.html.haml" + - "app/views/projects/branch_defaults/_default_branch_fields.html.haml" + - "app/views/projects/cleanup/_show.html.haml" + - "app/views/projects/commit/_signature_badge.html.haml" + - "app/views/projects/environments/index.html.haml" + - "app/views/projects/feature_flags/new.html.haml" + - "app/views/projects/feature_flags_user_lists/edit.html.haml" + - "app/views/projects/feature_flags_user_lists/new.html.haml" + - "app/views/projects/issues/_new_branch.html.haml" + - "app/views/projects/merge_requests/_page.html.haml" + - "app/views/projects/mirrors/_branch_filter.html.haml" + - "app/views/projects/mirrors/_mirror_repos.html.haml" + - "app/views/projects/mirrors/_mirror_repos_push.html.haml" + - "app/views/projects/pages_domains/_certificate.html.haml" + - "app/views/projects/pages_domains/_dns.html.haml" + - "app/views/projects/pages_domains/_helper_text.html.haml" + - "app/views/projects/runners/_group_runners.html.haml" + - "app/views/projects/settings/ci_cd/_autodevops_form.html.haml" + - "app/views/projects/settings/merge_requests/_merge_request_merge_commit_template.html.haml" + - "app/views/projects/settings/merge_requests/_merge_request_merge_method_settings.html.haml" + - "app/views/projects/settings/merge_requests/_merge_request_merge_suggestions_settings.html.haml" + - "app/views/projects/settings/merge_requests/_merge_request_squash_commit_template.html.haml" + - "app/views/projects/settings/merge_requests/_merge_request_squash_options_settings.html.haml" + - "app/views/projects/settings/operations/_alert_management.html.haml" + - "app/views/projects/usage_quotas/index.html.haml" + - "app/views/shared/_auto_devops_callout.html.haml" + - "app/views/shared/_auto_devops_implicitly_enabled_banner.html.haml" + - "app/views/shared/_custom_attributes.html.haml" + - "app/views/shared/_registration_features_discovery_message.html.haml" + - "app/views/shared/_service_ping_consent.html.haml" + - "app/views/shared/deploy_tokens/_form.html.haml" + - "app/views/shared/deploy_tokens/_new_deploy_token.html.haml" + - "app/views/shared/deploy_tokens/_table.html.haml" + - "app/views/shared/empty_states/_snippets.html.haml" + - "app/views/shared/integrations/gitlab_slack_application/_help.html.haml" + - "app/views/shared/integrations/gitlab_slack_application/_slack_integration_form.html.haml" + - "app/views/shared/integrations/mattermost_slash_commands/_help.html.haml" + - "app/views/shared/integrations/slack_slash_commands/_help.html.haml" + - "app/views/shared/issuable/form/_type_selector.html.haml" + - "app/views/shared/runners/_shared_runners_description.html.haml" + - "app/views/shared/web_hooks/_form.html.haml" + - "ee/app/views/admin/application_settings/_custom_templates_form.html.haml" + - "ee/app/views/admin/application_settings/_ee_network_settings.haml" + - "ee/app/views/admin/application_settings/_elasticsearch_form.html.haml" + - "ee/app/views/admin/application_settings/_ldap_access_setting.html.haml" + - "ee/app/views/admin/application_settings/_microsoft_application.haml" + - "ee/app/views/admin/application_settings/_saml_group_locks_setting.html.haml" + - "ee/app/views/admin/application_settings/_templates.html.haml" + - "ee/app/views/admin/dashboard/_elastic_and_geo.html.haml" + - "ee/app/views/admin/geo/shared/_hashed_storage_alerts.html.haml" + - "ee/app/views/admin/push_rules/_merge_request_approvals.html.haml" + - "ee/app/views/admin/push_rules/_merge_request_approvals_fields.html.haml" + - "ee/app/views/compliance_management/compliance_framework/_project_settings.html.haml" + - "ee/app/views/groups/_analytics_dashboards.html.haml" + - "ee/app/views/groups/_compliance_frameworks.html.haml" + - "ee/app/views/groups/_custom_project_templates_setting.html.haml" + - "ee/app/views/groups/_insights.html.haml" + - "ee/app/views/groups/_templates_setting.html.haml" + - "ee/app/views/groups/saml_providers/_info.html.haml" + - "ee/app/views/groups/security/policies/index.html.haml" + - "ee/app/views/groups/settings/_ip_restriction.html.haml" + - "ee/app/views/groups/settings/domain_verification/_certificate.html.haml" + - "ee/app/views/groups/settings/domain_verification/_dns.html.haml" + - "ee/app/views/groups/settings/domain_verification/_helper_text.html.haml" + - "ee/app/views/groups/settings/domain_verification/index.html.haml" + - "ee/app/views/notify/import_requirements_csv_email.html.haml" + - "ee/app/views/profiles/preferences/_code_suggestions_settings_self_assignment.html.haml" + - "ee/app/views/projects/merge_requests/_code_owner_approval_rules.html.haml" + - "ee/app/views/projects/mirrors/_branch_filter.html.haml" + - "ee/app/views/projects/mirrors/_mirror_repos_form.html.haml" + - "ee/app/views/projects/protected_environments/_group_environments_list.html.haml" + - "ee/app/views/projects/security/policies/index.html.haml" + - "ee/app/views/projects/settings/ci_cd/_auto_rollback.html.haml" + - "ee/app/views/projects/settings/ci_cd/_pipeline_subscriptions.html.haml" + - "ee/app/views/projects/settings/ci_cd/_protected_environments.html.haml" + - "ee/app/views/projects/settings/merge_requests/_merge_pipelines_settings.html.haml" + - "ee/app/views/projects/settings/merge_requests/_merge_request_approvals_settings.html.haml" + - "ee/app/views/projects/settings/merge_requests/_merge_trains_settings.html.haml" + - "ee/app/views/projects/settings/merge_requests/_suggested_reviewers_settings.html.haml" + - "ee/app/views/projects/settings/merge_requests/_target_branch_rules_settings.html.haml" + - "ee/app/views/search/results/_error.html.haml" + - "ee/app/views/shared/_ci_cd_only_link.html.haml" + - "ee/app/views/shared/_mirror_trigger_builds_setting.html.haml" + - "ee/app/views/shared/_new_user_signups_cap_reached_alert.html.haml" + - "ee/app/views/shared/empty_states/_geo_replication.html.haml" + - "ee/app/views/shared/issuable/form/_merge_request_blocks.html.haml" + - "ee/app/views/shared/labels/_create_label_help_text.html.haml" + - "ee/app/views/shared/promotions/_promote_advanced_search.html.haml" + - "ee/app/views/shared/promotions/_promote_burndown_charts.html.haml" + - "ee/app/views/shared/promotions/_promote_group_webhooks.html.haml" + - "ee/app/views/shared/promotions/_promote_mobile_devops.html.haml" + - "ee/app/views/shared/promotions/_promote_mr_features.html.haml" + - "ee/app/views/shared/promotions/_promote_repository_features.html.haml" diff --git a/haml_lint/linter/documentation_links.rb b/haml_lint/linter/documentation_links.rb index 3c99c295e2df2a673f6531fbbed990000a7325c9..9fff207a81c32c0219ce56687580d047243f4eb8 100644 --- a/haml_lint/linter/documentation_links.rb +++ b/haml_lint/linter/documentation_links.rb @@ -47,7 +47,9 @@ def check(node) def validate_node(node, match) return if match.empty? - path_to_file = detect_path_to_file(match[:link]) + link = match[:link] + + path_to_file = detect_path_to_file(link) unless File.file?(path_to_file) record_lint(node, "help_page_path points to the unknown location: #{path_to_file}") @@ -57,6 +59,8 @@ def validate_node(node, match) unless correct_anchor?(path_to_file, match[:anchor]) record_lint(node, "anchor (#{match[:anchor]}) is missing in: #{path_to_file}") end + + record_lint(node, "remove .md extension from the link: #{link}") if link.end_with?('.md') end def extract_link_and_anchor(ast_tree) diff --git a/spec/haml_lint/linter/documentation_links_spec.rb b/spec/haml_lint/linter/documentation_links_spec.rb index d47127d966124ada9e24ca0c9097800b799219df..ee34751de7261822df361bcc251ce505f8f7df1c 100644 --- a/spec/haml_lint/linter/documentation_links_spec.rb +++ b/spec/haml_lint/linter/documentation_links_spec.rb @@ -11,49 +11,49 @@ shared_examples 'link validation rules' do |link_pattern| context 'when link_to points to the existing file path' do - let(:haml) { "= link_to 'Description', #{link_pattern}('index.md')" } + let(:haml) { "= link_to 'Description', #{link_pattern}('index')" } it { is_expected.not_to report_lint } end context 'when link_to points to the existing file with valid anchor' do - let(:haml) { "= link_to 'Description', #{link_pattern}('index.md', anchor: 'user-account'), target: '_blank'" } + let(:haml) { "= link_to 'Description', #{link_pattern}('index', anchor: 'user-account'), target: '_blank'" } it { is_expected.not_to report_lint } end - context 'when link_to points to the existing file path without .md extension' do - let(:haml) { "= link_to 'Description', #{link_pattern}('index')" } + context 'when link_to points to the existing file path with .md extension' do + let(:haml) { "= link_to 'Description', #{link_pattern}('index.md')" } - it { is_expected.not_to report_lint } + it { is_expected.to report_lint } end context 'when anchor is not correct' do - let(:haml) { "= link_to 'Description', #{link_pattern}('index.md', anchor: 'wrong')" } + let(:haml) { "= link_to 'Description', #{link_pattern}('index', anchor: 'wrong')" } it { is_expected.to report_lint } context "when #{link_pattern} has multiple options" do - let(:haml) { "= link_to 'Description', #{link_pattern}('index.md', key: :value, anchor: 'wrong')" } + let(:haml) { "= link_to 'Description', #{link_pattern}('index', key: :value, anchor: 'wrong')" } it { is_expected.to report_lint } end end context 'when file path is wrong' do - let(:haml) { "= link_to 'Description', #{link_pattern}('wrong.md'), target: '_blank'" } + let(:haml) { "= link_to 'Description', #{link_pattern}('wrong'), 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" } + let(:haml) { "= link_to 'Description', #{link_pattern}('wrong') do" } it { is_expected.to report_lint } end end context 'when link with wrong file path is assigned to a variable' do - let(:haml) { "- my_link = link_to 'Description', #{link_pattern}('wrong.md')" } + let(:haml) { "- my_link = link_to 'Description', #{link_pattern}('wrong')" } it { is_expected.to report_lint } end @@ -65,13 +65,13 @@ end context 'when anchor belongs to a different element' do - let(:haml) { "= link_to 'Description', #{link_pattern}('index.md'), target: (anchor: 'blank')" } + let(:haml) { "= link_to 'Description', #{link_pattern}('index'), target: (anchor: 'blank')" } it { is_expected.not_to report_lint } end context "when a simple #{link_pattern}" do - let(:haml) { "- url = #{link_pattern}('wrong.md')" } + let(:haml) { "- url = #{link_pattern}('wrong')" } it { is_expected.to report_lint } end @@ -83,13 +83,13 @@ end context 'when link is a part of the tag' do - let(:haml) { ".data-form{ data: { url: #{link_pattern}('wrong.md') } }" } + let(:haml) { ".data-form{ data: { url: #{link_pattern}('wrong') } }" } it { is_expected.to report_lint } end context 'when the second link is invalid' do - let(:haml) { ".data-form{ data: { url: #{link_pattern}('index.md'), wrong_url: #{link_pattern}('wrong.md') } }" } + let(:haml) { ".data-form{ data: { url: #{link_pattern}('index'), wrong_url: #{link_pattern}('wrong') } }" } it { is_expected.to report_lint } end