Skip to content

fix(rules): report exposed and raw H1 counts separately in core/h1 - #1643

Closed
WilliamK112 wants to merge 10 commits into
squirrelscan:mainfrom
WilliamK112:codex/h1-exposed-count-1636
Closed

WilliamK112 wants to merge 10 commits into
squirrelscan:mainfrom
WilliamK112:codex/h1-exposed-count-1636

Conversation

@WilliamK112

@WilliamK112 WilliamK112 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • core/h1 sorts a page's H1s by static visibility with the shared createStaticVisibility reader (hidden, inline display:none / visibility:hidden, a closed <dialog>, decidable <style> rules) when the page has more than one. aria-hidden is deliberately not read: it hides a heading from assistive technology, not from the page
  • the raw count stays on the check as rawCount, with exposedCount and hiddenCount (and unconfirmedCount when relevant) beside it
  • outcomes when a page has several H1s:
    • all exposed, or all hidden → Multiple H1 tags found (N), unchanged
    • two or more exposed plus some hidden → Multiple H1 tags found (2 exposed, 3 in the HTML; …), value = exposed count
    • one exposed, the rest hidden → still a warning, since crawlers that do not render the page read every H1 (maintainer call): Multiple H1 tags found (1 exposed, 3 in the HTML; …), value = raw count, or H1 tag is empty when that H1 is empty
    • a duplicate that exists only if a style squirrel cannot settle does not hide an H1 → h1-unconfirmed warn, per the UNCONFIRMED_CHECK_SUFFIX convention
  • whenever hidden or unconfirmed H1s are involved, the message says visibility is read from markup, inline styles and <style> blocks, and that an HTTP-only audit cannot resolve visibility set by external stylesheets or scripts
  • single-H1 and no-H1 pages take the existing path unchanged
  • documented on the rule page and in the unreleased changelog

Closes #1636

Acceptance criteria

  • The raw H1 count stays available as a diagnostic value on the check (details.rawCount)
  • The exposed H1 count (excluding hidden and inline display:none) is reported separately (details.exposedCount)
  • /hidden-h1 (one exposed, two hidden) does not message as three visible headings
  • /visible-h1 (three exposed) still warns as multiple H1s, message unchanged
  • The message states that HTTP-only rendering cannot resolve CSS-driven visibility
  • Unit tests cover the hidden and visible cases (packages/rules/tests/h1-exposed-count-1636.test.ts)

Verification

  • bun test ./packages/rules/tests/h1-exposed-count-1636.test.ts — 12 pass, 0 fail; with src/core/h1.ts reverted to main, 8 of the 12 fail, and with the one-exposed case set back to pass, 3 fail
  • bun run scripts/test-suites.ts --run rules — 10,019 pass, 25 todo, 0 fail
  • bun run scripts/test-suites.ts --run report — 1,193 pass, 0 fail (includes a new test that the (N exposed, M in the HTML; …) messages merge across pages)
  • bun run scripts/test-suites.ts --run audit-engine — 1,923 pass, 3 skip, 1 fail: template-fanout-equivalence-golden.test.ts builds a path with new URL(...).pathname, which can't be opened from my checkout because its path has a space; unrelated to this change
  • bun run --cwd packages/rules typecheck, bun run --cwd packages/report typecheck
  • bun run lint, bun run format:check
  • bun run docs:check — all checks passed
  • oxlint -c apps/cli/oxlint.config.mjs on the changed files: clean; the test file is formatted with the pinned oxfmt (the existing h1.ts is not oxfmt-clean on main, so it was not reflowed)

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: docs/rules/core/h1.mdx. Skill: none.

nc9 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 8ce4734

Verdict: pending maintainer review. No correctness bugs found, but the change moves some pages from warn to pass, which is a scoring decision for the maintainer. Thanks for the thorough tests and docs.

Findings, most severe first:

  1. Medium (design): packages/rules/src/core/h1.ts now passes a page with one exposed H1 and N hidden ones (Single H1 tag present (3 in the HTML, 2 hidden; ...)). Before, that page warned, so its score changes. This matches the acceptance criteria of core/h1: distinguish raw counts from exposed experiment headings #1636 ("does not message as three visible headings"), but it also means crawlers that read the raw HTML and see three H1s are no longer warned. Worth a maintainer call on pass versus a lower-severity warn.
  2. Low: when the only H1 left after removing hidden ones is itself unknown (a style may hide it, e.g. exposed=0, unconfirmed=1, hidden>=1), exposed + unconfirmed > 1 is false, so it takes the "one H1 is left" path and passes as Single H1 tag present, without the h1-unconfirmed flag the rest of the rule uses for this state. Suggest a test for that case and either flagging it or documenting the choice.
  3. Low: the exposed-count and pass messages embed the long RENDERING_NOTE text, and the exposed-count message varies per page (2 exposed, 3 in the HTML). Check that report grouping that merges on the Multiple H1 tags found (N) text still folds these; the PR says the report tests pass, but they cover the old text only.
  4. Nit: the code comment lists <template> among the statically hidden cases, while the docs omit it and the test shows the parser never counts template content. Pick one.
  5. Process: the ### Fixed section under ## [Unreleased] in CHANGELOG.md will conflict with fix(rules): exclude hidden tables from table-duplicate-name #1641 and fix(rules): skip presentational descendants in aria-required-parent #1642, as the author noted.

Checks against the acceptance criteria of #1636: rawCount is kept on details, exposedCount is reported beside it, /hidden-h1 passes without the multiple-H1 wording, /visible-h1 keeps the unchanged Multiple H1 tags found (3) warning, the message states the HTTP-only limit, and tests cover both cases. aria-hidden is deliberately not read, which is correct.

Conventions: rule docs updated, CHANGELOG [Unreleased] entry added, no new runtime dependency, DCO sign-off present. CI: every check on this head is green or skipped.

nik

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in bee724ad:

  1. Pass vs. lower-severity warn (design): left as pass for now, because core/h1: distinguish raw counts from exposed experiment headings #1636's acceptance criteria say the hidden case should not read as multiple visible headings, and rawCount keeps the raw-HTML signal on the check. If you'd rather keep it a warn (or info) for crawlers that read raw HTML, that's a one-line change to the status of the "one H1 left" branch and its test, and I'm happy to make it.
  2. Only remaining H1 is unconfirmed: it is still checked as the single H1, since there is no duplicate to report, but the message now says so: Single H1 tag present (2 in the HTML, 1 hidden, and it may be hidden by a style (unconfirmed); …). It's pinned by a new test with exposedCount: 0, unconfirmedCount: 1 and documented on the rule page.
  3. Report grouping: I checked messageMergeKey and mergeCheckMessages on the new text. Two pages' Multiple H1 tags found (2 exposed, 3 in the HTML; …) and (4 exposed, 5 in the HTML; …) merge to (2 to 4 exposed, 3 to 5 in the HTML; …). They don't merge with the old (N) form, which only appears when no H1 is hidden. To keep grouped messages readable, the message now carries a short clause (an HTTP-only audit cannot resolve CSS or script visibility), and the full sentence moved to details.note (tested).
  4. <template>: the code comment now says template content never reaches the count because the parser keeps it out of the document, which matches the docs and the test.
  5. CHANGELOG overlap: noted; I'll rebase whichever of fix(rules): exclude hidden tables from table-duplicate-name #1641/fix(rules): skip presentational descendants in aria-required-parent #1642/fix(rules): report exposed and raw H1 counts separately in core/h1 #1643 lands later.

I also checked that the tests catch the bug: with src/core/h1.ts reverted to main, 8 of the 12 tests fail.

nc9 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: bee724a

Verdict: pending maintainer review. Findings 2 to 5 from the last review are addressed; finding 1 is a maintainer design decision and is still open.

Changes since the last reviewed head (8ce4734), one commit touching docs/rules/core/h1.mdx, packages/rules/src/core/h1.ts and the test file:

  1. Medium (design), still open: one exposed H1 plus hidden ones still passes as Single H1 tag present (N in the HTML, M hidden; ...) instead of warning, so those pages change score. The author left it as pass and offered to change it to a warn or info. This needs the maintainer's call, so I am not marking it resolved.
  2. Low, addressed: a lone remaining H1 that may itself be hidden by a style now passes as h1 with , and it may be hidden by a style (unconfirmed) in the message (packages/rules/src/core/h1.ts, "One H1 is left" branch). A new test pins exposedCount: 0, unconfirmedCount: 1, and the rule page documents it. It still does not use the h1-unconfirmed check name; that is a reasonable choice because there is no duplicate to report, but the maintainer may want it noted.
  3. Low, addressed: the message now carries the short RENDERING_LIMIT clause and the full note moved to details.note (tested), which keeps grouped messages readable. The author checked that messageMergeKey merges the new Multiple H1 tags found (N exposed, M in the HTML; ...) form across pages, but there is no report-side test for it; I did not run one.
  4. Nit, addressed: the <template> comment now matches the docs and the test.
  5. Process, unchanged: the ### Fixed entry under ## [Unreleased] will conflict with fix(rules): exclude hidden tables from table-duplicate-name #1641 and fix(rules): skip presentational descendants in aria-required-parent #1642, and the author will rebase the later one.

Conventions: rule docs updated, CHANGELOG entry present, no new dependency, DCO sign-off present. CI: all 15 completed checks on this head are green, 1 skipped.

nik

…t-1636

Signed-off-by: Ching-Wei Kang <[email protected]>

# Conflicts:
#	CHANGELOG.md

nc9 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: fc9e7b1

Verdict: pending maintainer review. The only change since the last reviewed head (bee724a) is a merge of main that resolves the CHANGELOG conflict. The open design decision from the earlier reviews is still open.

Findings, most severe first:

  1. Medium (design), still open: one exposed H1 plus hidden ones passes as Single H1 tag present (N in the HTML, M hidden; ...) instead of warning, so those pages change score (packages/rules/src/core/h1.ts, "One H1 is left" branch). The author offered to make it a warn or info. This is the maintainer's call and is not resolved.
  2. Verified unchanged: packages/rules/src/core/h1.ts, docs/rules/core/h1.mdx and packages/rules/tests/h1-exposed-count-1636.test.ts have identical blob SHAs at bee724a and fc9e7b1, so the earlier review of findings 2 to 5 (all addressed) still holds.
  3. Low: there is still no report-side test for the new Multiple H1 tags found (N exposed, M in the HTML; ...) merge form. The author describes checking messageMergeKey by hand; I did not run it.
  4. Process: the merge brings in the #1640 and #1637 CHANGELOG entries and the core/h1 entry sits after them under ## [Unreleased], so the conflict with fix(rules): exclude hidden tables from table-duplicate-name #1641 and fix(rules): skip presentational descendants in aria-required-parent #1642 is resolved for now. The branch is behind main, so a later merge may need another rebase.
  5. Nit: the first commit carries a Co-Authored-By: Claude Opus 5.5 trailer. Not blocking; DCO sign-offs are present on every commit.

Conventions: rule docs updated, CHANGELOG [Unreleased] entry present, no new runtime dependency. CI: all 15 completed checks on this head are green, 1 skipped.

nik

@nc9

nc9 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

maintainer call: one exposed H1 with other H1s hidden reports as warn. exposed and raw counts reported separately, as in this PR.

nik

…relscan#1636

Maintainer call on squirrelscan#1643: a page with one exposed H1 and hidden ones still
warns, because crawlers that do not render the page read every H1. The
message gives the exposed and raw counts separately, like the case with two
or more exposed, and the value is the raw count. Also add a report-side test
that these messages merge across pages.

Signed-off-by: Ching-Wei Kang <[email protected]>
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Done in 309c58d: one exposed H1 with the others hidden now warns as Multiple H1 tags found (1 exposed, N in the HTML; …), with the raw count as the value. The exposed and raw counts stay separate in the message and in details, and an empty remaining H1 still warns as H1 tag is empty.

I also merged main. The v0.0.174 release had renamed [Unreleased], so the CHANGELOG bullet is under the new one. And I added the report-side test from the earlier review: these messages merge across pages into one row.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

The red Dependency audit is a new low-severity advisory for fast-xml-parser (GHSA-474x-hrwr-fgx4). This PR doesn't touch bun.lock or any package.json (git diff origin/main...HEAD -- bun.lock package.json is empty), so I've left it for you.

nc9 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 1f3587d

Verdict: pending maintainer review. The maintainer decision from the last review (one exposed H1 with the rest hidden warns) is implemented; the findings below are minor.

Maintainer decision: addressed. In packages/rules/src/core/h1.ts (the "One H1 is left" branch, commit 309c58d) that case now warns as Multiple H1 tags found (1 exposed, N in the HTML; ...) with the raw count as value and expected: 1. Exposed and raw counts stay separate in the message and in details. An empty remaining H1 still warns as H1 tag is empty.

Findings, most severe first:

  1. Low: the lone H1 that may itself be hidden by a style (unconfirmed) now also warns, as Multiple H1 tags found (0 exposed, 2 in the HTML, 1 may be hidden by a style (unconfirmed); ...). That is consistent with the decision but reads oddly ("0 exposed" under a "Multiple H1" heading). The maintainer may want it kept on h1-unconfirmed. It is pinned by a test and documented in docs/rules/core/h1.mdx.
  2. Low: the earlier open item is closed. packages/report/tests/merge-check-messages.test.ts now has a test that the (N exposed, M in the HTML; ...) messages merge into ranges.
  3. CI: Dependency audit is red on a fast-xml-parser advisory (GHSA-474x-hrwr-fgx4). The PR does not touch bun.lock or any package.json, so it is not caused by this change. Every other check is green, including DCO sign-offs, Changelog guard and Docs check.
  4. Nit: the edits to the existing tests also reflow unrelated lines (trailing commas, line wraps). Harmless, but it adds noise to the diff.
  5. Docs and changelog: both updated for the new warn behaviour (docs/rules/core/h1.mdx, CHANGELOG.md under the current Unreleased entry). The rule's solution text matches too.

Thanks for the quick turnaround on the decision.

nik

@WilliamK112

Copy link
Copy Markdown
Contributor Author

On 1: I kept that case on h1 because the hidden H1 is certain, so the HTML has more than one H1 either way; only whether the remaining one shows is unconfirmed. Happy to move it to h1-unconfirmed if you'd rather.

On 4: those reflows come from running the pinned oxfmt over h1-exposed-count-1636.test.ts, which this PR adds, so the file now matches the formatter. merge-check-messages.test.ts only has the new test added.

…t-1636

Signed-off-by: Ching-Wei Kang <[email protected]>

# Conflicts:
#	CHANGELOG.md
…t-1636

Signed-off-by: Ching-Wei Kang <[email protected]>

# Conflicts:
#	CHANGELOG.md
…t-1636

Signed-off-by: Ching-Wei Kang <[email protected]>

# Conflicts:
#	CHANGELOG.md

nc9 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 6895644

Verdict: pending maintainer review. Nothing in the PR's own code changed since the last reviewed head (1f3587d); the one open question is still the maintainer's call, and the branch now conflicts with main.

Changes since the last reviewed head: 60 commits, almost all from main arriving through two merges (c177727, 6beacb2, 6895644). The core/h1 files are byte-identical to the reviewed head (blob SHAs match for packages/rules/src/core/h1.ts, docs/rules/core/h1.mdx, packages/rules/tests/h1-exposed-count-1636.test.ts and packages/report/tests/merge-check-messages.test.ts). Only CHANGELOG.md differs, because the ### Fixed bullet was carried over to the new ## [Unreleased] heading.

Findings, most severe first:

  1. Process, blocking merge: GitHub reports mergeable_state: dirty, so the branch needs another merge of main before it can land. CHANGELOG.md is the likely conflict again, since the bullet sits directly above ## v0.0.177.
  2. Low, still open from the last review: the lone H1 that may itself be hidden by a style (0 exposed, N in the HTML, 1 may be hidden by a style (unconfirmed)) warns under the h1 check name instead of h1-unconfirmed. The author kept it on h1 and offered to move it. This is the maintainer's call.
  3. Resolved: the earlier red Dependency audit is now green. It cleared because main bumped fast-xml-parser (build(deps): bump fast-xml-parser to 5.12.0 for GHSA-474x-hrwr-fgx4 #1689), not because of anything in this PR.
  4. Maintainer decision (one exposed H1 with the rest hidden warns, raw and exposed counts reported separately): still implemented as described in the previous review, with rawCount, exposedCount and hiddenCount in the details.

Conventions: rule docs updated, CHANGELOG [Unreleased] entry present, no new runtime dependency, DCO sign-offs present. CI: every completed check on this head is green, and Installer script syntax is skipped.

nik

…unt-1636

Signed-off-by: Ching-Wei Kang <[email protected]>

# Conflicts:
#	CHANGELOG.md
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Merged current main in f1c98a2 and resolved the CHANGELOG conflict by keeping the #1636 bullet under the new Unreleased section. Revalidated the 34 focused rule/report tests, the changed rule files with the pinned formatter and linter, both rules and report typechecks, and diff whitespace; all pass.

nc9 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: f1c98a2

Verdict: pending maintainer review. The maintainer decision (one exposed H1 with the rest hidden warns, raw and exposed counts reported separately) is implemented, and nothing substantive changed since the last reviewed head (6895644). The branch still needs a conflict fix before it can land.

Changes since the last reviewed head: one merge of main (f1c98a2). The only PR-owned code difference is a formatting-only reflow of the H1Exposure literal in packages/rules/src/core/h1.ts (h1Exposure). Behaviour, the rule docs, packages/rules/tests/h1-exposed-count-1636.test.ts and packages/report/tests/merge-check-messages.test.ts are unchanged.

Findings, most severe first:

  1. Process, blocking merge: GitHub still reports mergeable_state: dirty on this head. CHANGELOG.md is the likely cause, since the core/h1 bullet now sits directly above the ## v0.0.179 section that main added. Please merge main once more and check that the bullet sits under the current ## [Unreleased] heading and not under a released version.
  2. Low, still open from earlier reviews: the lone H1 that may itself be hidden by a style (0 exposed, N in the HTML, 1 may be hidden by a style (unconfirmed)) warns under the h1 check name instead of h1-unconfirmed. The author kept it on h1 and offered to move it. This is the maintainer's call.

Conventions: rule docs updated, CHANGELOG entry present, no new runtime dependency. CI: 15 checks succeeded and 1 was skipped on this head. I did not run the tests.

nik

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Merged the latest main and resolved the CHANGELOG.md conflict by keeping the new upstream Unreleased sections and the core/h1 fix under ### Fixed.

Validation passed: 43 focused H1/report tests, 19 release/changelog tests, and git diff --check.

nc9 pushed a commit that referenced this pull request Nov 13, 2026
Maintainer call on #1643: a page with one exposed H1 and hidden ones still
warns, because crawlers that do not render the page read every H1. The
message gives the exposed and raw counts separately, like the case with two
or more exposed, and the value is the raw count. Also add a report-side test
that these messages merge across pages.

Signed-off-by: Ching-Wei Kang <[email protected]>
Signed-off-by: Nik Cubrilovic <[email protected]>
nc9 added a commit that referenced this pull request Nov 13, 2026
@nc9

nc9 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Landed in bundle #1799, rebase-merged to main.

nik

@nc9 nc9 closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core/h1: distinguish raw counts from exposed experiment headings

2 participants