fix(lint): flag digit-leading ids used by toArray and ScrollTrigger selectors (#4908)

* fix(lint): flag digit-leading ids used by toArray and ScrollTrigger selectors

Co-authored-by: Miguel Ángel <miguel.sierra@heygen.com>

* refactor(lint): drop the selector sink comment

* fix(lint): ignore hyphenated and $-prefixed keys that end in pin or trigger

* fix(lint): match scroller, pinnedContainer and pinSpacer selector keys
This commit is contained in:
Miguel Ángel
2026-10-02 18:25:22 +00:00
committed by GitHub
parent 821e8c8ad0
commit fc53908742
2 changed files with 70 additions and 1 deletions
+69
View File
@@ -83,6 +83,75 @@ describe("core rules", () => {
["a CSS rule targets it", "#123-frame { opacity: 0; }", "", "error"],
["a GSAP string targets it", "", 'gsap.to("#123-frame", { x: 1 });', "error"],
["querySelector targets it", "", 'document.querySelector(".a #123-frame");', "error"],
["gsap.utils.toArray targets it", "", 'gsap.utils.toArray("#123-frame");', "error"],
[
"a scrollTrigger trigger targets it",
"",
'gsap.to(".box", { x: 10, scrollTrigger: { trigger: "#123-frame" } });',
"error",
],
[
"ScrollTrigger.create triggers on it",
"",
'ScrollTrigger.create({ trigger: "#123-frame", pin: true });',
"error",
],
[
"a ScrollTrigger pin targets it",
"",
'ScrollTrigger.create({ trigger: ".a", pin: "#123-frame" });',
"error",
],
[
"a ScrollTrigger endTrigger targets it",
"",
'ScrollTrigger.create({ trigger: ".a", endTrigger: "#123-frame" });',
"error",
],
[
"the scrollTrigger shorthand targets it",
"",
'gsap.to(".box", { scrollTrigger: "#123-frame" });',
"error",
],
[
"a ScrollTrigger scroller targets it",
"",
'ScrollTrigger.create({ trigger: ".a", scroller: "#123-frame" });',
"error",
],
[
"a ScrollTrigger pinnedContainer targets it",
"",
'ScrollTrigger.create({ trigger: ".a", pinnedContainer: "#123-frame" });',
"error",
],
[
"a ScrollTrigger pinSpacer targets it",
"",
'ScrollTrigger.create({ trigger: ".a", pinSpacer: "#123-frame" });',
"error",
],
[
"a quoted ScrollTrigger key targets it",
"",
'ScrollTrigger.create({ "trigger": "#123-frame" });',
"error",
],
[
"a $-prefixed key ending in pin holds it",
"",
'const meta = { $pin: "#123-frame" };',
"warning",
],
["a key ending in pin holds it", "", 'const meta = { spin: "#123-frame" };', "warning"],
["a non-selector key holds it", "", 'const meta = { label: "#123-frame" };', "warning"],
[
"a hyphenated key ending in pin holds it",
"",
'const meta = { "data-pin": "#123-frame" };',
"warning",
],
["only url(#id) references it", ".a { mask: url(#123-frame); }", "", "warning"],
["only a longer id is selected", "#123-frame-2 { opacity: 0; }", "", "warning"],
["getElementById looks it up", "", 'document.getElementById("123-frame");', "warning"],
+1 -1
View File
@@ -97,7 +97,7 @@ function addUnescapedDigitIds(selector: string, ids: Set<string>): void {
}
const SELECTOR_CALL_PATTERN =
/\.(?:querySelector(?:All)?|closest|matches|to|from|fromTo|set)\s*\(\s*(["'`])((?:\\.|(?!\1)[^\\])*)\1/g;
/(?:\.(?:querySelector(?:All)?|closest|matches|to|from|fromTo|set|toArray)\s*\(|(?<![\w$-])(?:trigger|endTrigger|pin|scrollTrigger|scroller|pinnedContainer|pinSpacer)["']?\s*:)\s*(["'`])((?:\\.|(?!\1)[^\\])*)\1/g;
function digitIdsTargetedBySelectors(
styles: LintContext["styles"],