Regex deduplication
Toggle: enabledChecks.regex-dedup plus regexDedup config · Fix: autofix.regexDedup · Command: regex-dedup
Detects duplicate regex literals and supported constructor patterns. Safe fixes can extract file-local, non-stateful duplicates into CONFIG or REGEX constants. Set sharedModule to a repository-relative .mjs path to enable cross-file ESM factories, with a matching .d.mts declaration. Without it, fixes remain file-local.
Configure minimumCount, extensions, and ignoredFiles. Stateful regex flags and incompatible CommonJS consumers remain advisory because sharing can change behavior.
Before — the same non-stateful expression is constructed twice:
const first = /^terra-[a-z]+$/;const second = /^terra-[a-z]+$/;After — a supported local autofix creates one constant and reuses it:
const TERRA_A_Z_REGEX = /^terra-[a-z]+$/;const first = TERRA_A_Z_REGEX;const second = TERRA_A_Z_REGEX;Exact generated identifiers depend on the pattern and names already used in the file.