Ratchet unicorn/prefer-includes-over-repeated-comparisons to error#281
Merged
Conversation
… 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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anyobj[dynamicKey]in a boolean position, e.g.!RULE_DEFAULTS[id]), so it stays a warning.prefer-includes-over-repeated-comparisonsis a clean, high-value alternative.Changes
Replaced 15 repeated
x === "a" || x === "b" || …literal chains (none autofixable) with membership lookups. Sinceunicorn/prefer-set-has(already anerror) wantsSet.has()over array.includes()for these — and that matches the codebase's existing tag-set style — the lists became module-levelSets, constructed once at module load:disguised-ad-flag.ts— interactive tags/roles, page-boundary tagshidden-fee-annotate.ts— interactive tags/roles, navigation tags/roles, page-boundary tags, order-summary container tagsschema-trust-sanitize.ts— href / src microdata carrier tags (each used in two functions)site-denylist.ts— content-scheme protocolstext-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.includesis test-only.Verification
bun run typecheckcleanbun run checkexit 0 (rule now errors; 0 violations)bun run test— 2059/2059 passRefs #279