From 88c232fd2002a1913968efd4828eeafa90f45167 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 18 Nov 2026 22:01:31 +0000 Subject: [PATCH] fix(kvb-code-clean): a call in a ternary branch is no method definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit METHOD_AFTER let a return-type annotation run past the ternary's ': hidden,' into the next member's '(pattern) =>', so defaults.py read assignments in arrow bodies inside call arguments as parameter defaults (core penpot _shared.test.js lines 85, 94, 102). The annotation now holds no bare colon outside parentheses, so typed methods such as 'm(a = 1): (x: number) => void {' still count. Over 932 JS, TS and C# files in core and skills, 4 hits drop, all of this kind, and none appear. 🎯 Fix: 97 % 💥 Break: 2 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 95 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- skills/kvb-code-clean/scripts/defaults.py | 2 +- tests/test_defaults.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/skills/kvb-code-clean/scripts/defaults.py b/skills/kvb-code-clean/scripts/defaults.py index db7e25b..486b421 100755 --- a/skills/kvb-code-clean/scripts/defaults.py +++ b/skills/kvb-code-clean/scripts/defaults.py @@ -120,7 +120,7 @@ JINJA_DEFAULT = re.compile(r"\|\s*(?:default|d)\s*\(") ENV_LOOKUP = re.compile(r"lookup\(\s*['\"]env['\"]") FUNCTION_BEFORE = re.compile(r"\bfunction\b[\s*]*[\w$]*\s*(?:<[^<>()]*>)?\s*\Z") METHOD_BEFORE = re.compile(r"(?()]*>)?\s*\Z") -METHOD_AFTER = re.compile(r"\s*(?::[^;{}]*)?(?:\{|=>|where\b)") +METHOD_AFTER = re.compile(r"\s*(?::(?:[^;{}:()]|\([^()]*\))*)?(?:\{|=>|where\b)") ARROW_AFTER = re.compile(r"\s*(?::[^=;{}()]*)?=>") DECLARE = re.compile(r"\b(?:const|let|var)\s+([{\[])") NULLISH = re.compile(r"\?\?=?") diff --git a/tests/test_defaults.py b/tests/test_defaults.py index 34c3e5b..ca41ace 100644 --- a/tests/test_defaults.py +++ b/tests/test_defaults.py @@ -223,6 +223,27 @@ class TestDefaults(unittest.TestCase): self.assertEqual(self._hits(), (0, [])) self.assertEqual(self._hits("--file", "extra.py"), (1, [("extra.py:1", "python", "g(x=1)", False, False)])) + def test_a_call_in_a_ternary_branch_is_no_method_and_a_typed_method_still_is(self): + self._write({ + "tern.js": ( + "const page = {\n" + " getByText: (text) =>\n" + ' text === "OpenID"\n' + " ? control(() => true, {\n" + " click: async () => {\n" + " state.url = `${ISSUER}/auth`;\n" + " },\n" + " })\n" + " : hidden,\n" + " getByLabel: (pattern) => pattern,\n" + "};\n" + ), + "typed.ts": "class A {\n m(a = 1): (x: number) => void { return; }\n}\n", + }) + self.assertEqual( + self._hits("--file", "tern.js", "--file", "typed.ts"), (1, [("typed.ts:2", "ts", "a = 1", False, False)]) + ) + def test_text_output_marks_justified_and_candidate(self): self._write({"t.sh": "# the probe needs a fixed port\necho ${A:-b}\n", "t.ts": "x = y ?? 1;\n"}) result = self._run("--repo", str(self.repo), "--file", "t.sh", "--file", "t.ts")