Skip to content

no-duplicate-constant-values: boolean/string values lack the coincidence guard given to numbers #50197

Description

@github-actions

Summary

eslint-factory/src/rules/no-duplicate-constant-values.ts flags a later module-level const declaration whenever its static value duplicates an earlier one. For numeric literals the rule requires at least MIN_NUMERIC_DUPLICATE_GROUP_SIZE = 3 declarations sharing a value before reporting (src/rules/no-duplicate-constant-values.ts:10,82) — an explicit acknowledgment that small numbers (0, 1, -1, etc.) collide coincidentally all the time and a 2-way match is too weak a signal.

Booleans get no such guard: getStaticValueKey maps every boolean literal to one of exactly two keys (boolean:true / boolean:false, via the generic ${typeof node.value}:${String(node.value)} branch at line 17), and shouldReportDuplicates only special-cases the number: prefix (line 82). Since there are only 2 possible boolean values module-wide — versus an effectively unbounded but coincidence-prone numeric range that still got a 3-way threshold — any two unrelated top-level const bindings that happen to both be true (or both false) will be flagged as "duplicating" each other, even though there's no reason to believe they're supposed to share a single source of truth. This is at least as prone to coincidental collision as the numeric case the threshold was added for, but has no corresponding protection.

Short/generic string sentinels (e.g. two unrelated const X = ""; or two unrelated 2-3 char status/mode strings) are analogously exposed, though the collision space there is larger and harder to hit by accident.

Why this wasn't filed with a live example

A search of actions/setup/js/*.cjs for module-level const NAME = true; / const NAME = false; / const NAME = ""; currently turns up zero coincidental collisions — the corpus is disciplined. This mirrors the precedent set by the require-fs-sync-try-catch catch-less-try/finally finding filed 2026-07-08: an ungrounded but cheap, clearly-reasoned soundness/FP gap worth fixing proactively before the corpus grows into it.

Acceptance criteria

  • Either extend a minimum-group-size guard to boolean values (matching the numeric threshold's rationale — 2 possible values is a smaller space than "small numbers" and deserves at least the same protection), or explicitly document in a code comment why booleans are intentionally exempt if the maintainers judge 2 boolean occurrences is still a meaningful signal.
  • Add a test case: two unrelated top-level const declarations both set to true (different names, no semantic relationship) — decide and assert the intended behavior (flag or don't).
  • Consider whether short (e.g. <=2 char) string values deserve the same treatment, and if not, note why strings differ from numbers/booleans.

Scope

eslint-factory/src/rules/no-duplicate-constant-values.ts and its test file only.

Generated by 🤖 ESLint Refiner · agent · 261.5 AIC · ⌖ 30.2 AIC · ⊞ 4.9K ·

  • expires on Aug 10, 2026, 10:21 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions