Potential Analyzer - loading json with the same name as a bicep module may be problematic
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
Problematic for new users:
Having a bicep and json file with the same base name, and inside of bicep load the json may cause the original json to be replaced on build.
### `constants.json`
```json
{
"billingDept": "1234"
}
```
### `constants.bicep`
```bicep
var consts = loadJsonContent('constants.json')
output BillingDept string = consts.billingDept
```
### `main.bicep`
```bicep
module consts 'constants.bicep' = {
name: 'consts'
}
```
### Invoke Build Order:
```shell
> bicep build constants.bicep && bicep build module.bicep
constants.bicep(3,36) : Error BCP053: The type "object" does not contain property "billingDept". Available properties include "$schema", "contentVersion", "metadata", "outputs", "resources", "variables".
main.bicep(1,15) : Error BCP104: The referenced module has errors.
```
**Describe the solution you'd like**
This was pretty hard to realize that the root cause would be my bicep file replacing my json file. There are plenty of solutions here so its not really a bug and probably a couple of bad practices but a rule like this could be beneficial.
Rule: Loading content from `/.json` may be overwritten if `/.bicep` was built with the default output location.
Binds to function calls to `load*Content('./.json')`
Contributor guide
Research direction
Start with the loadJsonContent call in constants.bicep and reproduce the issue using the shown constants.bicep and main.bicep build commands. Find the analyzer entry point for load*Content('./basename.json') calls. Done means a diagnostic warns when the default build output can overwrite the loaded JSON file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100