Ccodemod

codemod/arm-unused-local-variables-s1481

Remove trailing unused lambda variables from ARM template expressions embedded in JSON files.

azurearmjsonlambdacode-quality
Public
0 executions

Run locally

npx codemod @codemod/arm-unused-local-variables-s1481

@codemod/arm-unused-local-variables-s1481

Remove trailing unused lambda variables from ARM template expressions in JSON files.

Installation

bash

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

becomes:

json
json

becomes:

json

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

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.