Skip to content

fix(spans): TS/JS/PHP functions start on their declaration line (#3543, #3555) - #3585

Merged
squid-protocol merged 1 commit into
mainfrom
claude/festive-fermat-kojuy7
Sep 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
claude/festive-fermat-kojuy7

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #3543. Fixes #3555.

Two independent causes put a function's start_line before its declaration in TypeScript, JavaScript and PHP. Downstream, start_line feeds the DB, SARIF, doc adjacency and the wrapper channel's alignment check.

#3543: the func_start match opens on the previous line. TS/JS func_start opens with [ \t\n]*. PHP's consumes one boundary character, usually the previous line's \n. _slice_by_braces took match.start() as the unit start, so the span opened on:

  • the class {,
  • the previous member's },,
  • a docblock's */,
  • or several lines up, when PRISM had blanked a doc comment above it.

_slice_by_braces now moves start_idx just past the last newline of the match's leading whitespace run. Indentation stays in the block. A match that doesn't open with a newline is untouched, which covers every language the audit showed at 0%. The idea matches the existing scheme/lisp #2933 skip.

#3555: PRISM collapsed a PHP heredoc/nowdoc to "". That dropped the literal's newlines, so every line after a heredoc was numbered early; wordpress functions.php lost 10. The shield now keeps "" plus the literal's newlines, and its statement ;.

The two fixes ship together because PHP only reaches 0 with both.

Measured: span_anchor_audit.py on language-crucible

language misanchored before after
typescript 18.1% (527 / 2913) 0.0%
php 21.9% (377 / 1718) 0.0%
javascript 0.4% (3 / 823) 0.0%
every other language 0.0% 0.0%

tests/span_anchor_baseline.json is regenerated, so the gate now holds these at 0.

Type of change

  • Bug fix
  • New feature / language support
  • Parsing or engine logic (gitgalaxy/core/detector.py, language_standards.py, prism.py, or a per-language rule)
  • Docs, tooling, or CI only
  • Other (describe above)

CI checklist

  • audit_check components: ruff-audit and dead-key are clean. Local ruff format --check and mypy flags are the same on unmodified main (local tool versions).
  • python -m pytest tests/ passes: 11,107 passed. test_security_auditor.py was skipped locally for lack of numpy.
  • crucible_check.py --update --yes: both fixtures reblessed on top of current main. Scope is below.
  • tree_sitter_accuracy_audit.py --ci --all: all OK, 30 languages.
  • tri_comparison_chart.py --all --ci: javascript fails locally identically on unmodified main (ctags isn't installed here); CI runs it.

Golden-master scope

Zero-dependency fixture: 120 differences. 17 are coordinate or composition-fit ripple. The other 103 are all TS/JS/PHP units or their aggregates. That count includes the .php file in the SQL corpus folder and the .ts file in the javascript folder.

  • Start Line moves down onto the declaration.
  • End Line moves with it: it was early by the same amount. For example, react BabelPlugin.ts: enter 35–82 → 36–83 and exit 83–99 → 84–100, both now matching the source.
  • The documentation exposure, "Is Documented" and archetype mix that depend on where a unit starts follow. Globally: Compute Cores 3859 → 3899, Parameter Forwarders 5350 → 5299, and similar small shifts.

Verification

$ pytest tests/core_engine/test_function_start_line_anchor_3543.py tests/core_engine/test_prism_php_heredoc_lines_3555.py -q
10 passed   (2 of the new #3543 cases fail without the detector change)
$ LANGUAGE_CRUCIBLE_PATH=../language-crucible python tests/tools/span_anchor_audit.py --ci
span_anchor_audit: OK -- 50 language(s) measured
$ python tests/tools/tree_sitter_accuracy_audit.py --ci --all
all OK (30 languages)

🤖 Generated with Claude Code

https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q


Generated by Claude Code

…3543, #3555)

Two causes put a unit's start_line before its declaration:

- #3543: TS/JS func_start opens with `[ \t\n]*` and PHP's consumes one
  boundary character (usually the previous line's newline), so the match
  -- and start_idx -- began on the line before: the class `{`, the prior
  member's `},`, a docblock's `*/`, or several lines up when PRISM had
  blanked a doc comment. _slice_by_braces now anchors the unit just past
  the last newline of the match's leading whitespace run.
- #3555: PRISM shielded a PHP heredoc/nowdoc as a bare `""`, dropping its
  newlines, so every line after one was numbered early. The shield now
  keeps the literal's newlines (and its statement `;`).

span_anchor_audit (language-crucible), misanchored units:
  typescript 18.1% -> 0.0%, php 21.9% -> 0.0%, javascript 0.4% -> 0.0%;
  every other language unchanged at 0%. Baseline regenerated.

Golden masters reblessed: start/end lines in ts/js/php units (end lines
were early by the same amount), the doc-adjacency and archetype mix that
follow them, and coordinate ripple.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YAtpBfGGyBGGovitSVaM5Q
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit b964f9c into main Sep 25, 2026
34 checks passed
@squid-protocol
squid-protocol deleted the claude/festive-fermat-kojuy7 branch September 25, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants