codemod/arm-unused-local-variables-s1481
Remove trailing unused lambda variables from ARM template expressions embedded in JSON files.
# @codemod/arm-unused-local-variables-s1481
Remove trailing unused lambda variables from ARM template expressions in JSON files.
## Installation
```bash
# Run from the registry
pnpm dlx codemod@latest @codemod/arm-unused-local-variables-s1481 -t /path/to/project
# Or run the local package
pnpm dlx codemod@latest workflow run -w . -t /path/to/project
```
## Usage
This codemod scans JSON ARM templates and rewrites string-valued ARM expressions that use `lambda(...)`.
It removes only trailing lambda parameters that are never referenced through `lambdaVariables('<name>')` in the lambda body.
Examples:
```json
{
"value": "[map(variables('dogs'), lambda('dog', 'i', lambdaVariables('dog').name))]"
}
```
becomes:
```json
{
"value": "[map(variables('dogs'), lambda('dog', lambdaVariables('dog').name))]"
}
```
```json
{
"value": "[reduce(variables('ages'), 0, lambda('cur', 'next', 'i', add(lambdaVariables('cur'), lambdaVariables('next'))))]"
}
```
becomes:
```json
{
"value": "[reduce(variables('ages'), 0, lambda('cur', 'next', add(lambdaVariables('cur'), lambdaVariables('next'))))]"
}
```
The codemod intentionally leaves these cases unchanged:
- Lambdas where the trailing parameter is referenced
- Lambdas with only one parameter, even if it is unused
- Non-expression JSON strings that do not look like ARM expressions
- Cases where a matching `lambdaVariables(...)` reference is only for a nested lambda's shadowed parameter
Because ARM expressions are embedded inside JSON strings, the codemod uses JSON AST edits for the string boundary and applies a syntax-aware string rewrite only within those expression values.
## Development
```bash
# Type-check the package
pnpm run check-types
# Test the transformation
pnpm test
# Validate the workflow
pnpm dlx codemod@latest workflow validate -w workflow.yaml
# Publish to registry
pnpm dlx codemod@latest login
pnpm dlx codemod@latest publish
```
## License
MIT