Skip to content

Ratchet unicorn/prefer-includes-over-repeated-comparisons to error#281

Merged
twschiller merged 2 commits into
mainfrom
ratchet-unicorn-prefer-includes
Jun 22, 2026
Merged

Ratchet unicorn/prefer-includes-over-repeated-comparisons to error#281
twschiller merged 2 commits into
mainfrom
ratchet-unicorn-prefer-includes

Conversation

@twschiller

Copy link
Copy Markdown
Contributor

Second ratchet from #279. Stacked on #280 (base = ratchet-unicorn-dom-traversal).

Pivoted from no-computed-property-existence-check: investigation showed it's ~21 false positives vs 2 real wins in this codebase (fires on any obj[dynamicKey] in a boolean position, e.g. !RULE_DEFAULTS[id]), so it stays a warning. prefer-includes-over-repeated-comparisons is a clean, high-value alternative.

Changes

Replaced 15 repeated x === "a" || x === "b" || … literal chains (none autofixable) with membership lookups. Since unicorn/prefer-set-has (already an error) wants Set.has() over array .includes() for these — and that matches the codebase's existing tag-set style — the lists became module-level Sets, constructed once at module load:

  • disguised-ad-flag.ts — interactive tags/roles, page-boundary tags
  • hidden-fee-annotate.ts — interactive tags/roles, navigation tags/roles, page-boundary tags, order-summary container tags
  • schema-trust-sanitize.ts — href / src microdata carrier tags (each used in two functions)
  • site-denylist.ts — content-scheme protocols
  • text-walk-shadow.property.test.ts — non-content tag guard (inline .includes, test-only)

eslint.config.js: rule removed from the warn list → reverts to unicorn/recommended default (error).

Performance

No production impact. The membership Sets are built once at module load (not per call), so per-element checks stay O(1) with no new per-call allocation — if anything marginally faster than the === chains for the longer lists. The one inline .includes is test-only.

Verification

  • bun run typecheck clean
  • bun run check exit 0 (rule now errors; 0 violations)
  • bun run test — 2059/2059 pass

Refs #279

twschiller and others added 2 commits June 22, 2026 06:54
… to error

First ratchet from #279. Both are small, source-only, zero-risk:

- page-tree.ts: `.childNodes[0]` → `.firstChild` (coerce the null the
  property returns to undefined to match `getElementTree`'s return type).
- lifecycle.ts: `Number.isInteger(tabId)` → `Number.isSafeInteger(tabId)`
  at the two tab-id guards.

Both rules drop back to their unicorn/recommended default (error).

Refs #279

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Second ratchet from #279 (pivoted from no-computed-property-existence-check,
which is ~21 false positives in this codebase — kept as a warning).

Replace repeated `x === "a" || x === "b" || …` literal chains with
membership lookups. The plugin's prefer-set-has rule (already an error)
wants `Set.has()` over array `.includes()` for these, matching the
codebase's existing tag-set style, so the lists become module-level
`Set`s built once at load:

- disguised-ad-flag.ts: interactive tags/roles, page-boundary tags
- hidden-fee-annotate.ts: interactive tags/roles, navigation tags/roles,
  page-boundary tags, order-summary container tags
- schema-trust-sanitize.ts: href/src microdata carrier tags
- site-denylist.ts: content-scheme protocols
- text-walk-shadow.property.test.ts: non-content tag guard (inline)

Refs #279

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 22, 2026 11:19am

Request Review

Base automatically changed from ratchet-unicorn-dom-traversal to main June 22, 2026 11:19
@twschiller twschiller merged commit d250bc6 into main Jun 22, 2026
7 checks passed
@twschiller twschiller deleted the ratchet-unicorn-prefer-includes branch June 22, 2026 11:20
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.

1 participant