td-ai-tools 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/shopify-lint/SKILL.md +2 -2
- package/skills/shopify-lint/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/skills/shopify-lint/scripts/__pycache__/shopify_lint.cpython-312.pyc +0 -0
- package/skills/shopify-lint/scripts/shopify_lint.py +39 -8
- package/skills/shopify-lint/tests/__pycache__/test_shopify_lint.cpython-312.pyc +0 -0
- package/skills/shopify-lint/tests/test_shopify_lint.py +68 -13
- package/skills/shopify-lint/theme-check-theory/README.md +7 -0
- package/skills/shopify-lint/theme-check-theory/src/checks/hardcoded-text.test.ts +32 -0
- package/skills/shopify-lint/theme-check-theory/src/checks/hardcoded-text.ts +8 -0
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@ python3 .agents/skills/shopify-lint/scripts/shopify_lint.py --path .
|
|
|
40
40
|
|
|
41
41
|
The script identifies files changed since the current branch's merge-base, adds staged, unstaged, and untracked files, then runs three linters over that set and merges their results into one report:
|
|
42
42
|
|
|
43
|
-
- **Theme Check** — `shopify theme check --output json`. The root `.theme-check.yml` directly requires the bundled `theme-check-theory` package from this skill directory. `DisallowedScriptOrStyleTag` reports inline executable `<script>` and all `<style>` tags in modified Liquid files while allowing external-source and JSON-data scripts. `HardcodedText` reports rendered hard-coded copy, except content inside Liquid `stylesheet`, `javascript`, and `schema` tags. The generated `.theme-check.yml` also pins the upstream `StaticStylesheetAndJavascriptTags` to `error`, so Liquid written inside a `{% stylesheet %}` or `{% javascript %}` block always fails the lint.
|
|
43
|
+
- **Theme Check** — `shopify theme check --output json`. The root `.theme-check.yml` directly requires the bundled `theme-check-theory` package from this skill directory. `DisallowedScriptOrStyleTag` reports inline executable `<script>` and all `<style>` tags in modified Liquid files while allowing external-source and JSON-data scripts. `HardcodedText` reports rendered hard-coded copy, except content inside Liquid `stylesheet`, `javascript`, and `schema` tags, and except text beginning with `--`, which is a CSS custom property name rather than copy. The generated `.theme-check.yml` also pins the upstream `StaticStylesheetAndJavascriptTags` to `error`, so Liquid written inside a `{% stylesheet %}` or `{% javascript %}` block always fails the lint.
|
|
44
44
|
- **JavaScript** — ESLint's recommended rules plus the bundled `eslint-plugin-theory`, over modified `.js` and `.mjs` files *and* the JavaScript inside `{% javascript %}` blocks of modified `.liquid` files.
|
|
45
45
|
- **CSS** — `stylelint-config-standard` through the bundled `stylelint-config-theory`, over modified `.css` files *and* the CSS inside `{% stylesheet %}` blocks of modified `.liquid` files.
|
|
46
46
|
|
|
@@ -48,7 +48,7 @@ Standalone JavaScript and CSS are linted only when the **filename** contains `td
|
|
|
48
48
|
|
|
49
49
|
The filter does **not** apply to Liquid: `{% javascript %}` and `{% stylesheet %}` blocks are linted in every modified `.liquid` file regardless of its name, because that code is Theory's either way. A `{% stylesheet 'scss' %}` block is skipped, because its body is Sass rather than CSS, as is any block commented out with `{% comment %}` or `{% raw %}`.
|
|
50
50
|
|
|
51
|
-
Offenses in a Liquid block are reported at their real line and column in the `.liquid` file. Check codes say where they came from: `PascalCase` is Theme Check, `theory/…` is a Theory JavaScript rule, `eslint/…` is an upstream ESLint rule, `stylelint/…` is an upstream Stylelint rule.
|
|
51
|
+
Offenses in a Liquid block are reported at their real line and column in the `.liquid` file. Positions are one-indexed in both the JSON and the text report, matching the `file:line:column` convention editors and compilers use — Theme Check's LSP-style zero-indexed rows and columns are rebased on the way in, and ESLint's and Stylelint's pass through as reported. Check codes say where they came from: `PascalCase` is Theme Check, `theory/…` is a Theory JavaScript rule, `eslint/…` is an upstream ESLint rule, `stylelint/…` is an upstream Stylelint rule.
|
|
52
52
|
|
|
53
53
|
`theory/guarded-custom-element-define` and `theory/no-unapproved-imports` are errors, as are genuine ESLint correctness failures; the convention rules (`theory/disconnected-callback-cleanup`, `theory/no-class-selectors`, `theory/centralize-selectors`, `theory/require-jsdoc`) are warnings. `theory/require-jsdoc` requires named classes and functions to have JSDoc comments, including typed `@param` and `@returns` tags. The severity distinction only affects `--fail-level`: the Stop hooks run at `--fail-level warning`, so warnings block handoff too. See `eslint-plugin-theory/README.md` for every rule and its blind spots.
|
|
54
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"4.1.10","results":[[":eslint-plugin-theory/src/rules/guarded-custom-element-define.test.ts",{"duration":0,"failed":true}]]}
|
|
1
|
+
{"version":"4.1.10","results":[[":eslint-plugin-theory/src/rules/guarded-custom-element-define.test.ts",{"duration":0,"failed":true}],[":stylelint-config-theory/src/liquid/mask.test.ts",{"duration":21.486761,"failed":false}],[":theme-check-theory/src/checks/hardcoded-text.test.ts",{"duration":79.642067,"failed":false}],[":stylelint-config-theory/src/integration.test.ts",{"duration":322.234405,"failed":false}],[":theme-check-theory/src/checks/unguarded-nullable-setting.test.ts",{"duration":126.54217099999994,"failed":false}],[":eslint-plugin-theory/src/rules/disconnected-callback-cleanup.test.ts",{"duration":0,"failed":true}],[":eslint-plugin-theory/src/integration.test.ts",{"duration":207.055841,"failed":false}],[":eslint-plugin-theory/src/liquid/mask.test.ts",{"duration":31.769655,"failed":false}],[":stylelint-config-theory/src/config.test.ts",{"duration":13.856021999999996,"failed":false}],[":theme-check-theory/src/checks/unused-section-settings.test.ts",{"duration":63.80623400000002,"failed":false}],[":theme-check-theory/src/checks/unguarded-metaobject.test.ts",{"duration":34.325909000000024,"failed":false}],[":eslint-plugin-theory/src/index.test.ts",{"duration":6.773288999999977,"failed":false}],[":theme-check-theory/src/checks/disallowed-script-or-style-tag.test.ts",{"duration":32.848730000000046,"failed":false}],[":theme-check-theory/src/checks/unguarded-metafield.test.ts",{"duration":37.897699999999986,"failed":false}],[":eslint-plugin-theory/src/rules/no-class-selectors.test.ts",{"duration":0,"failed":true}],[":eslint-plugin-theory/src/rules/no-unapproved-imports.test.ts",{"duration":0,"failed":true}],[":eslint-plugin-theory/src/rules/require-jsdoc.test.ts",{"duration":87.66796799999997,"failed":false}],[":eslint-plugin-theory/src/rules/centralize-selectors.test.ts",{"duration":0,"failed":true}],[":stylelint-config-theory/src/build.test.ts",{"duration":903.9329710000001,"failed":false}],[":theme-check-theory/src/index.test.ts",{"duration":2.380390000000034,"failed":false}],[":eslint-plugin-theory/src/processors/liquid.test.ts",{"duration":6.720345000000009,"failed":false}],[":eslint-plugin-theory/src/build.test.ts",{"duration":965.007413,"failed":false}]]}
|
|
Binary file
|
|
@@ -41,9 +41,21 @@ STYLELINT_SEVERITIES = ("error", "warning")
|
|
|
41
41
|
STYLELINT_PARSE_ERROR_RULE = "CssSyntaxError"
|
|
42
42
|
|
|
43
43
|
# Theme Check reports LSP-style zero-indexed positions; ESLint and Stylelint are
|
|
44
|
-
# both one-indexed.
|
|
44
|
+
# both one-indexed. Positions are reported one-indexed throughout — the
|
|
45
|
+
# `file:line:column` convention every editor and compiler uses — so Theme
|
|
46
|
+
# Check's rows and columns are each shifted up by one and the other two runners'
|
|
47
|
+
# pass through untouched.
|
|
45
48
|
LINE_BASE_OFFSET = 1
|
|
46
49
|
|
|
50
|
+
# Position fields carried on a Theme Check offense, rebased together so a single
|
|
51
|
+
# offense never mixes indexing bases.
|
|
52
|
+
THEME_CHECK_POSITION_KEYS = (
|
|
53
|
+
"start_row",
|
|
54
|
+
"start_column",
|
|
55
|
+
"end_row",
|
|
56
|
+
"end_column",
|
|
57
|
+
)
|
|
58
|
+
|
|
47
59
|
|
|
48
60
|
class ShopifyLintError(RuntimeError):
|
|
49
61
|
"""Raised when Git or Shopify CLI cannot produce filterable results."""
|
|
@@ -169,7 +181,26 @@ def run_theme_check(
|
|
|
169
181
|
|
|
170
182
|
if not isinstance(reports, list):
|
|
171
183
|
raise ShopifyLintError("Shopify Theme Check returned an unexpected JSON shape.")
|
|
172
|
-
return reports
|
|
184
|
+
return normalize_theme_check_reports(reports)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def normalize_theme_check_reports(
|
|
188
|
+
reports: list[dict[str, Any]],
|
|
189
|
+
) -> list[dict[str, Any]]:
|
|
190
|
+
"""Rebase Theme Check's zero-indexed positions onto the report's one-indexed ones."""
|
|
191
|
+
normalized = []
|
|
192
|
+
for report in reports:
|
|
193
|
+
offenses = []
|
|
194
|
+
for offense in report.get("offenses", []):
|
|
195
|
+
item = dict(offense)
|
|
196
|
+
for key in THEME_CHECK_POSITION_KEYS:
|
|
197
|
+
if key in item:
|
|
198
|
+
item[key] = int(item[key]) + LINE_BASE_OFFSET
|
|
199
|
+
offenses.append(item)
|
|
200
|
+
entry = dict(report)
|
|
201
|
+
entry["offenses"] = offenses
|
|
202
|
+
normalized.append(entry)
|
|
203
|
+
return normalized
|
|
173
204
|
|
|
174
205
|
|
|
175
206
|
def resolve_lint_target(
|
|
@@ -373,9 +404,9 @@ def normalize_stylelint_results(results: list[dict[str, Any]]) -> list[dict[str,
|
|
|
373
404
|
"check": stylelint_check_code(warning),
|
|
374
405
|
"severity": stylelint_severity(warning),
|
|
375
406
|
"message": str(warning.get("text", "")),
|
|
376
|
-
"start_row": max(int(warning.get("line", 1))
|
|
407
|
+
"start_row": max(int(warning.get("line", 1)), LINE_BASE_OFFSET),
|
|
377
408
|
"start_column": max(
|
|
378
|
-
int(warning.get("column", 1))
|
|
409
|
+
int(warning.get("column", 1)), LINE_BASE_OFFSET
|
|
379
410
|
),
|
|
380
411
|
}
|
|
381
412
|
)
|
|
@@ -420,9 +451,9 @@ def normalize_eslint_results(results: list[dict[str, Any]]) -> list[dict[str, An
|
|
|
420
451
|
"check": eslint_check_code(message),
|
|
421
452
|
"severity": eslint_severity(message),
|
|
422
453
|
"message": str(message.get("message", "")),
|
|
423
|
-
"start_row": max(int(message.get("line", 1))
|
|
454
|
+
"start_row": max(int(message.get("line", 1)), LINE_BASE_OFFSET),
|
|
424
455
|
"start_column": max(
|
|
425
|
-
int(message.get("column", 1))
|
|
456
|
+
int(message.get("column", 1)), LINE_BASE_OFFSET
|
|
426
457
|
),
|
|
427
458
|
}
|
|
428
459
|
)
|
|
@@ -510,8 +541,8 @@ def render_text(reports: list[dict[str, Any]], repo_root: Path) -> str:
|
|
|
510
541
|
offense_count += 1
|
|
511
542
|
severity = str(offense.get("severity", "unknown")).upper()
|
|
512
543
|
check = offense.get("check", "UnknownCheck")
|
|
513
|
-
row = offense.get("start_row",
|
|
514
|
-
column = offense.get("start_column",
|
|
544
|
+
row = offense.get("start_row", LINE_BASE_OFFSET)
|
|
545
|
+
column = offense.get("start_column", LINE_BASE_OFFSET)
|
|
515
546
|
message = offense.get("message", "")
|
|
516
547
|
lines.append(f" {severity} {check} {row}:{column} {message}".rstrip())
|
|
517
548
|
lines.append("")
|
|
Binary file
|
|
@@ -80,6 +80,35 @@ class ThemeCheckTests(unittest.TestCase):
|
|
|
80
80
|
check=False,
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
+
def test_rebases_theme_check_positions_onto_one_indexed_lines(self) -> None:
|
|
84
|
+
"""Theme Check emits LSP-style zero-indexed positions; the report is one-indexed."""
|
|
85
|
+
reports = [
|
|
86
|
+
{
|
|
87
|
+
"path": "/repo/sections/td-hero.liquid",
|
|
88
|
+
"offenses": [
|
|
89
|
+
{
|
|
90
|
+
"check": "HardcodedText",
|
|
91
|
+
"severity": "warning",
|
|
92
|
+
"start_row": 0,
|
|
93
|
+
"start_column": 4,
|
|
94
|
+
"end_row": 2,
|
|
95
|
+
"end_column": 9,
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
[report] = shopify_lint.normalize_theme_check_reports(reports)
|
|
102
|
+
offense = report["offenses"][0]
|
|
103
|
+
|
|
104
|
+
self.assertEqual(offense["start_row"], 1)
|
|
105
|
+
self.assertEqual(offense["end_row"], 3)
|
|
106
|
+
self.assertEqual(offense["start_column"], 5)
|
|
107
|
+
self.assertEqual(offense["end_column"], 10)
|
|
108
|
+
# The input is not mutated in place.
|
|
109
|
+
self.assertEqual(reports[0]["offenses"][0]["start_row"], 0)
|
|
110
|
+
self.assertEqual(reports[0]["offenses"][0]["start_column"], 4)
|
|
111
|
+
|
|
83
112
|
def test_filters_reports_to_changed_repo_relative_paths(self) -> None:
|
|
84
113
|
root = Path("/repo")
|
|
85
114
|
reports = [
|
|
@@ -360,7 +389,7 @@ class JsLintCommandTests(unittest.TestCase):
|
|
|
360
389
|
|
|
361
390
|
|
|
362
391
|
class EslintNormalizationTests(unittest.TestCase):
|
|
363
|
-
def
|
|
392
|
+
def test_maps_severity_rule_and_position(self) -> None:
|
|
364
393
|
results = [
|
|
365
394
|
{
|
|
366
395
|
"filePath": "/repo/assets/td-app.js",
|
|
@@ -395,15 +424,15 @@ class EslintNormalizationTests(unittest.TestCase):
|
|
|
395
424
|
"check": "eslint/no-undef",
|
|
396
425
|
"severity": "error",
|
|
397
426
|
"message": "'x' is not defined.",
|
|
398
|
-
"start_row":
|
|
399
|
-
"start_column":
|
|
427
|
+
"start_row": 4,
|
|
428
|
+
"start_column": 3,
|
|
400
429
|
},
|
|
401
430
|
{
|
|
402
431
|
"check": "theory/no-class-selectors",
|
|
403
432
|
"severity": "warning",
|
|
404
433
|
"message": "Use a data-td-* hook.",
|
|
405
|
-
"start_row":
|
|
406
|
-
"start_column":
|
|
434
|
+
"start_row": 9,
|
|
435
|
+
"start_column": 1,
|
|
407
436
|
},
|
|
408
437
|
],
|
|
409
438
|
}
|
|
@@ -684,7 +713,7 @@ class CssLintCommandTests(unittest.TestCase):
|
|
|
684
713
|
|
|
685
714
|
|
|
686
715
|
class StylelintNormalizationTests(unittest.TestCase):
|
|
687
|
-
def
|
|
716
|
+
def test_namespaces_rules_and_maps_positions(self) -> None:
|
|
688
717
|
results = [
|
|
689
718
|
{
|
|
690
719
|
"path": "/theme/assets/component-td-card.css",
|
|
@@ -705,8 +734,8 @@ class StylelintNormalizationTests(unittest.TestCase):
|
|
|
705
734
|
|
|
706
735
|
self.assertEqual(offense["check"], "stylelint/length-zero-no-unit")
|
|
707
736
|
self.assertEqual(offense["severity"], "warning")
|
|
708
|
-
self.assertEqual(offense["start_row"],
|
|
709
|
-
self.assertEqual(offense["start_column"],
|
|
737
|
+
self.assertEqual(offense["start_row"], 4)
|
|
738
|
+
self.assertEqual(offense["start_column"], 3)
|
|
710
739
|
|
|
711
740
|
def test_keeps_a_namespaced_plugin_rule_as_is(self) -> None:
|
|
712
741
|
results = [
|
|
@@ -932,6 +961,32 @@ class MergeReportTests(unittest.TestCase):
|
|
|
932
961
|
(SKILL_ROOT / "eslint-plugin-theory" / "dist").is_dir(),
|
|
933
962
|
"run scripts/setup.sh to build eslint-plugin-theory",
|
|
934
963
|
)
|
|
964
|
+
class RenderTextTests(unittest.TestCase):
|
|
965
|
+
"""The Stop hooks feed this text straight back to the agent."""
|
|
966
|
+
|
|
967
|
+
def test_prints_the_one_indexed_row_the_offense_carries(self) -> None:
|
|
968
|
+
reports = [
|
|
969
|
+
{
|
|
970
|
+
"path": "/repo/sections/td-hero.liquid",
|
|
971
|
+
"offenses": [
|
|
972
|
+
{
|
|
973
|
+
"check": "HardcodedText",
|
|
974
|
+
"severity": "warning",
|
|
975
|
+
"start_row": 12,
|
|
976
|
+
"start_column": 4,
|
|
977
|
+
"message": "Replace hard-coded text",
|
|
978
|
+
}
|
|
979
|
+
],
|
|
980
|
+
}
|
|
981
|
+
]
|
|
982
|
+
|
|
983
|
+
rendered = shopify_lint.render_text(reports, Path("/repo"))
|
|
984
|
+
|
|
985
|
+
self.assertIn(
|
|
986
|
+
" WARNING HardcodedText 12:4 Replace hard-coded text", rendered
|
|
987
|
+
)
|
|
988
|
+
|
|
989
|
+
|
|
935
990
|
class EndToEndJsTests(unittest.TestCase):
|
|
936
991
|
"""Proves the Liquid line-mapping contract against the real runner."""
|
|
937
992
|
|
|
@@ -951,7 +1006,7 @@ class EndToEndJsTests(unittest.TestCase):
|
|
|
951
1006
|
" {% endif %}",
|
|
952
1007
|
"{% endjavascript %}",
|
|
953
1008
|
]
|
|
954
|
-
expected_row = lines.index(" const dupe = { a: 1, a: 2 };")
|
|
1009
|
+
expected_row = lines.index(" const dupe = { a: 1, a: 2 };") + 1
|
|
955
1010
|
|
|
956
1011
|
with tempfile.TemporaryDirectory() as directory:
|
|
957
1012
|
root = Path(directory)
|
|
@@ -969,7 +1024,7 @@ class EndToEndJsTests(unittest.TestCase):
|
|
|
969
1024
|
]
|
|
970
1025
|
|
|
971
1026
|
self.assertEqual(len(dupe), 1)
|
|
972
|
-
# start_row is
|
|
1027
|
+
# start_row is one-indexed, matching the line numbers an editor shows.
|
|
973
1028
|
self.assertEqual(dupe[0]["start_row"], expected_row)
|
|
974
1029
|
self.assertEqual(dupe[0]["severity"], "error")
|
|
975
1030
|
|
|
@@ -994,7 +1049,7 @@ class EndToEndCssTests(unittest.TestCase):
|
|
|
994
1049
|
" .td-broken {}",
|
|
995
1050
|
"{% endstylesheet %}",
|
|
996
1051
|
]
|
|
997
|
-
expected_row = lines.index(" .td-broken {}")
|
|
1052
|
+
expected_row = lines.index(" .td-broken {}") + 1
|
|
998
1053
|
|
|
999
1054
|
with tempfile.TemporaryDirectory() as directory:
|
|
1000
1055
|
root = Path(directory)
|
|
@@ -1012,13 +1067,13 @@ class EndToEndCssTests(unittest.TestCase):
|
|
|
1012
1067
|
]
|
|
1013
1068
|
|
|
1014
1069
|
self.assertEqual(len(empty), 1)
|
|
1015
|
-
# start_row is
|
|
1070
|
+
# start_row is one-indexed, matching the line numbers an editor shows.
|
|
1016
1071
|
self.assertEqual(empty[0]["start_row"], expected_row)
|
|
1017
1072
|
self.assertEqual(empty[0]["severity"], "error")
|
|
1018
1073
|
# The masked interpolation is graded like any other value now: Liquid
|
|
1019
1074
|
# does not belong in a `{% stylesheet %}` block, and Theme Check reports
|
|
1020
1075
|
# it separately through `StaticStylesheetAndJavascriptTags`.
|
|
1021
|
-
interpolated_row = lines.index(" margin: {{ section.settings.gap }}px;")
|
|
1076
|
+
interpolated_row = lines.index(" margin: {{ section.settings.gap }}px;") + 1
|
|
1022
1077
|
self.assertEqual(
|
|
1023
1078
|
[
|
|
1024
1079
|
offense["check"]
|
|
@@ -39,6 +39,13 @@ checked. It ignores technical attributes such as classes and IDs, Liquid logic
|
|
|
39
39
|
strings, comments, punctuation-only fragments, and text made entirely of HTML
|
|
40
40
|
character references.
|
|
41
41
|
|
|
42
|
+
Text beginning with `--` is ignored as a CSS custom property name: Liquid
|
|
43
|
+
routinely assembles a custom property declaration before handing it to a
|
|
44
|
+
`style` attribute or a `{% style %}` block, neither of which this check reads.
|
|
45
|
+
Only the fragment carrying the `--` prefix is exempt, so the tail of an
|
|
46
|
+
interpolated declaration — the `px;` in
|
|
47
|
+
`{% capture s %}--td-gap: {{ gap }}px;{% endcapture %}` — is still reported.
|
|
48
|
+
|
|
42
49
|
Content inside `{% stylesheet %}`, `{% javascript %}`, and `{% schema %}` is
|
|
43
50
|
ignored. A quoted translation key passed through `t` or `translate` is also
|
|
44
51
|
accepted. Short alphabetic tokens and copyright years remain reportable because
|
|
@@ -209,6 +209,38 @@ describe('HardcodedText', () => {
|
|
|
209
209
|
expect(await runLiquidCheck(HardcodedText, source)).toEqual([]);
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
+
it('accepts CSS custom properties built in Liquid', async () => {
|
|
213
|
+
const source = `
|
|
214
|
+
{% capture card_style %}--td-card-gap: 12px;{% endcapture %}
|
|
215
|
+
{{ '--td-card-columns' }}
|
|
216
|
+
{% echo "--td-card-radius: 4px;" %}
|
|
217
|
+
{% render 'card', style_key: '--td-card-accent' %}
|
|
218
|
+
<div style="{{ card_style }}">{{ section.settings.heading }}</div>
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
expect(await runLiquidCheck(HardcodedText, source)).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('still reports the tail of an interpolated custom property', async () => {
|
|
225
|
+
// The parser splits the declaration around the output tag, and only the
|
|
226
|
+
// fragment that carries the `--` prefix is exempt. The trailing unit is a
|
|
227
|
+
// text node of its own with nothing marking it as CSS.
|
|
228
|
+
const source =
|
|
229
|
+
'{% capture style %}--td-gap: {{ section.settings.gap }}px;{% endcapture %}';
|
|
230
|
+
|
|
231
|
+
const offenses = await runLiquidCheck(HardcodedText, source);
|
|
232
|
+
|
|
233
|
+
expect(
|
|
234
|
+
offenses.map(({ start, end }) => source.slice(start.index, end.index)),
|
|
235
|
+
).toEqual(['px;']);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('still reports copy that only mentions a custom property later', async () => {
|
|
239
|
+
const source = '{% capture note %}Set --td-gap to widen the card{% endcapture %}';
|
|
240
|
+
|
|
241
|
+
expect(await runLiquidCheck(HardcodedText, source)).toHaveLength(1);
|
|
242
|
+
});
|
|
243
|
+
|
|
212
244
|
it('still reports rendered text inside other raw tags', async () => {
|
|
213
245
|
const source = '{% raw %}Hard coded raw output{% endraw %}';
|
|
214
246
|
|
|
@@ -43,6 +43,12 @@ const BUTTON_INPUT_TYPES = new Set(['button', 'reset', 'submit']);
|
|
|
43
43
|
const HTML_CHARACTER_REFERENCE =
|
|
44
44
|
/&(?:#\d+|#x[\da-f]+|[a-z][\da-z]+);/giu;
|
|
45
45
|
|
|
46
|
+
// A leading `--` is a CSS custom property name, never storefront copy. Liquid
|
|
47
|
+
// routinely assembles custom property declarations before handing them to a
|
|
48
|
+
// `style` attribute or a `{% style %}` block — places this check overlooks —
|
|
49
|
+
// so the fragment that builds them is exempt too.
|
|
50
|
+
const CSS_CUSTOM_PROPERTY = /^\s*--/u;
|
|
51
|
+
|
|
46
52
|
type ValuedAttribute = Extract<AttributeNode, { value: unknown }>;
|
|
47
53
|
|
|
48
54
|
function isValuedAttribute(node: LiquidHtmlNode): node is ValuedAttribute {
|
|
@@ -124,6 +130,8 @@ function isInlineSvgMarkup(ancestors: LiquidHtmlNode[]): boolean {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
function hasMeaningfulText(value: string): boolean {
|
|
133
|
+
if (CSS_CUSTOM_PROPERTY.test(value)) return false;
|
|
134
|
+
|
|
127
135
|
return /[\p{L}\p{N}]/u.test(
|
|
128
136
|
value.replace(HTML_CHARACTER_REFERENCE, ''),
|
|
129
137
|
);
|