@codemod/arm-duplicate-string-literals-s1192
Scan Azure Resource Manager (ARM) JSON templates for repeated identical string literals above a configurable minimum length and threshold, then report maintainability hotspots where values should be centralized into parameters, variables, or reusable modules instead of being duplicated inline.
What It Does
- Parses ARM JSON templates and Bicep-generated ARM JSON artifacts as JSON.
- Detects duplicated decoded string literal values across the whole file, including nested
Microsoft.Resources/deploymentsinlineproperties.templatefragments. - Excludes top-level
$schemaand common ARM schema/documentation URLs by default. - Emits structured per-file findings and
codemod:metricscounters. - Never edits source files. This is a read-only mining codemod.
Usage
Run the local package against a target repository:
bash
Common parameters:
minimal_literal_lengthdefault5thresholddefault3ignore_arm_expression_stringsdefaultfalseignore_api_versionsdefaultfalseignore_resource_typesdefaultfalseignore_known_low_signal_pathsdefaultfalserequire_arm_shapedefaultfalseredact_literalsdefaultfalse
Example with stricter filtering and redaction:
bash
Findings
Each file with findings emits a structured warning containing:
fileliteralorliteralHashwhen redaction is enabledoccurrenceCountjsonPathssemanticKindsminimal_literal_lengththresholdremediationGuidanceestimatedMaintenanceImpact
Remediation guidance recommends centralizing repeated values into:
parametersfor environment-specific valuesvariablesfor file-local constants- reusable module inputs/outputs when the value spans deployment boundaries
Metrics
The codemod emits these metrics:
arm_duplicated_string_literal_occurrenceskeyed byfilearm_duplicated_string_literal_groupskeyed byfilearm_duplicated_string_literal_max_group_sizekeyed byfilearm_duplicated_string_literal_files_with_findingskeyed byrepositoryarm_duplicated_string_literal_total_occurrenceskeyed byrepositoryarm_duplicated_string_literal_total_groupskeyed byrepositoryarm_duplicated_string_literal_parse_failureskeyed byrepositoryarm_duplicated_string_literal_ignored_schema_urlskeyed byrepositoryarm_duplicated_string_literal_ignored_expression_stringskeyed byrepositoryarm_duplicated_string_literal_by_literal_hashkeyed byliteralHash
Target Files
- Included:
**/*.json - Excluded:
**/node_modules/**,**/dist/**,**/build/**
If require_arm_shape=true, non-ARM JSON files are skipped without findings.
Development
bash
The fixture suite keeps input.json and expected.json identical because the codemod is analysis-only; verification focuses on successful parsing, read-only behavior, and spec-specific scenario coverage.
License
MIT