From 82a4afa571cf85bd6a7f10c5106a1bbbea2948f7 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 3 Dec 2025 11:06:18 +0000 Subject: [PATCH] Enable erb_lint hard coded string linter The implementation uses a customised linter, to add `·` to the list of punctuation that doesn't need translating. We can remove our customised linter when this list becomes a config option, see https://github.com/Shopify/erb_lint/pull/397 --- .erb_lint.yml | 9 +++++ .erb_linters/custom_hard_coded_string.rb | 50 ++++++++++++++++++++++++ app/views/share_panes/show.html.erb | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .erb_linters/custom_hard_coded_string.rb diff --git a/.erb_lint.yml b/.erb_lint.yml index dc9b39c5c..a81c2dc4e 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -3,6 +3,13 @@ linters: AllowedScriptType: enabled: true disallow_inline_scripts: true + HardCodedString: + enabled: false # We're using a custom version of this, see below + # Add our own linter, refs https://github.com/Shopify/erb_lint/pull/397 + CustomHardCodedString: + enabled: true + exclude: + - 'app/views/shared/_markdown_help.html.erb' Rubocop: enabled: true rubocop_config: @@ -26,5 +33,7 @@ linters: enabled: false SpaceInHtmlTag: enabled: true + NoUnusedDisable: + enabled: true exclude: - '**/vendor/**' diff --git a/.erb_linters/custom_hard_coded_string.rb b/.erb_linters/custom_hard_coded_string.rb new file mode 100644 index 000000000..a9d666527 --- /dev/null +++ b/.erb_linters/custom_hard_coded_string.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require "better_html/tree/tag" +require "active_support/core_ext/string/inflections" + +module ERBLint + module Linters + # A customised version of the HardCodedString linter, adding `·` as not needing translation + # Checks for hardcoded strings. Useful if you want to ensure a string can be translated using i18n. + class CustomHardCodedString < HardCodedString + include LinterRegistry + + NO_TRANSLATION_NEEDED = Set.new([ + " ", + "&", + "<", + ">", + """, + "©", + "®", + "™", + "…", + "—", + "•", + "“", + "”", + "‘", + "’", + "←", + "→", + "↓", + "↑", + " ", + " ", + " ", + "×", + "«", + "»", + "·" + ]) + + private + + def check_string?(str) + string = str.gsub(/\s*/, "") + string.length > 1 && !NO_TRANSLATION_NEEDED.include?(string) + end + end + end +end diff --git a/app/views/share_panes/show.html.erb b/app/views/share_panes/show.html.erb index f4912b152..86e4c0a39 100644 --- a/app/views/share_panes/show.html.erb +++ b/app/views/share_panes/show.html.erb @@ -54,7 +54,7 @@ <%= label_tag "mapnik_scale", t(".scale"), :class => "col-auto col-form-label" %>
- 1 : + 1 : <%# erb_lint:disable CustomHardCodedString %> <%= text_field_tag "mapnik_scale", nil, :class => "form-control", :autocomplete => "off" %>
-- 2.39.5