Azure / Azure/bicep

Linter should check that `load*Content()` is not used multiple times for the same file

Open
#6,970 14 comments 0 reactions 0 assignees View on GitHub
enhancement story: linter rules
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
0.6.18

**Describe the bug**
If a I load a json file into a variable like this:
``` bicep
var publicPaasEndpointsParams = json(loadTextContent('lib/policy_set_definitions/policy_set_definition_es_deny_publicpaasendpoints.parameters.json'))
```
and reference it throughout my bicep file then the json content is only loaded once when I reference it this way:
```bicep
libSetChildDefinitions: [
{
definitionReferenceID: 'ACRDenyPaasPublicIP'
definitionID: '/providers/Microsoft.Authorization/policyDefinitions/0fdf0491-d080-4575-b627-ad0e843cba0f'
definitionParameters: publicPaasEndpointsParams.ACRDenyPaasPublicIP.parameters
}
{
definitionReferenceID: 'AFSDenyPaasPublicIP'
definitionID: '/providers/Microsoft.Authorization/policyDefinitions/21a8cd35-125e-4d13-b82d-2e19b7208bb7'
definitionParameters: publicPaasEndpointsParams.AFSDenyPaasPublicIP.parameters
}
```

But if I load content this way:
```bicep
libSetChildDefinitions: [
{
definitionReferenceID: 'ACRDenyPaasPublicIP'
definitionID: '/providers/Microsoft.Authorization/policyDefinitions/0fdf0491-d080-4575-b627-ad0e843cba0f'
definitionParameters: json(loadTextContent('lib/policy_set_definitions/policy_set_definition_es_deny_publicpaasendpoints.parameters.json')).ACRDenyPaasPublicIP.parameters
}
{
definitionReferenceID: 'AFSDenyPaasPublicIP'
definitionID: '/providers/Microsoft.Authorization/policyDefinitions/21a8cd35-125e-4d13-b82d-2e19b7208bb7'
definitionParameters: json(loadTextContent('lib/policy_set_definitions/policy_set_definition_es_deny_publicpaasendpoints.parameters.json')).AFSDenyPaasPublicIP.parameters
}
```

Then the json content gets loaded multiple times even though it is the same content in the json file which can greatly bloat the file and cause it to exceed the 4MB limit. I would expect loading json content into a variable and refencing json files

**To Reproduce**
Store the content of a json file in a variable and refencing the object multiple times and then generate the json file to see that the string for the json file is only loaded once. Then reference the json file by loading it multiple times within the bicep file and see that the content is added to the json file multiple times creating bloat, even though the content of the files is the same.

**Additional context**
If you need any addtional information I'm happy to provide it.

Contributor guide

Open the contributing guide

Research direction

Reproduce the two examples from the issue: compare a variable holding json(loadTextContent(...)) with repeated inline loadTextContent() calls, then inspect the linter behavior. Done means the linter reports multiple loads of the same file while allowing repeated references to content loaded once through a variable.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.