Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What If Short Circuiting Linter Rule (Default Off) #14910

Merged
merged 14 commits into from
Sep 10, 2024
Merged
6 changes: 3 additions & 3 deletions src/Bicep.Cli/Services/TemplateEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,21 @@ private static TestEvaluation EvaluateTemplate(JToken? templateJtoken, JToken? p
var template = TemplateEngine.ParseTemplate(templateJtoken.ToString());
var parameters = ParseParametersFile(parametersJToken);

TemplateEngine.ValidateTemplate(template, TemplateWriter.NestedDeploymentResourceApiVersion, deploymentScope);
TemplateEngine.ValidateTemplate(template, EmitConstants.NestedDeploymentResourceApiVersion, deploymentScope);

TemplateEngine.ProcessTemplateLanguageExpressions(
managementGroupName: config.ManagementGroup,
subscriptionId: config.SubscriptionId,
resourceGroupName: config.ResourceGroup,
template: template,
apiVersion: TemplateWriter.NestedDeploymentResourceApiVersion,
apiVersion: EmitConstants.NestedDeploymentResourceApiVersion,
inputParameters: new(parameters),
metadata: metadata,
metricsRecorder: new TemplateMetricsRecorder());

ProcessTemplateLanguageExpressions(template, config, deploymentScope);

TemplateEngine.ValidateProcessedTemplate(template, TemplateWriter.NestedDeploymentResourceApiVersion, deploymentScope);
TemplateEngine.ValidateProcessedTemplate(template, EmitConstants.NestedDeploymentResourceApiVersion, deploymentScope);

var allAssertions = template.Asserts?.Select(p => new AssertionResult(p.Key, (bool)p.Value.Value)).ToImmutableArray() ?? [];
var failedAssertions = allAssertions.Where(a => !a.Result).Select(a => a).ToImmutableArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/TemplateEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,21 @@ private static JToken EvaluateTemplate(JToken? templateJtoken, JToken? parameter
var template = TemplateEngine.ParseTemplate(templateJtoken.ToString());
var parameters = ParseParametersFile(parametersJToken);

TemplateEngine.ValidateTemplate(template, TemplateWriter.NestedDeploymentResourceApiVersion, deploymentScope);
TemplateEngine.ValidateTemplate(template, EmitConstants.NestedDeploymentResourceApiVersion, deploymentScope);

TemplateEngine.ProcessTemplateLanguageExpressions(
managementGroupName: config.ManagementGroup,
subscriptionId: config.SubscriptionId,
resourceGroupName: config.ResourceGroup,
template: template,
apiVersion: TemplateWriter.NestedDeploymentResourceApiVersion,
apiVersion: EmitConstants.NestedDeploymentResourceApiVersion,
inputParameters: new(parameters),
metadata: metadata,
metricsRecorder: new TemplateMetricsRecorder());

ProcessTemplateLanguageExpressions(template, config, deploymentScope);

TemplateEngine.ValidateProcessedTemplate(template, TemplateWriter.NestedDeploymentResourceApiVersion, deploymentScope);
TemplateEngine.ValidateProcessedTemplate(template, EmitConstants.NestedDeploymentResourceApiVersion, deploymentScope);

return template.ToJToken();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.Samples/DataSetsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string SaveFilesToTestDirectory(this DataSet dataSet, TestContext
await dataSet.PublishModulesToRegistryAsync(clientFactory);
var templateSpecRepositoryFactory = dataSet.CreateMockTemplateSpecRepositoryFactory(testContext);

var compiler = ServiceBuilder.Create(s => s.AddSingleton(templateSpecRepositoryFactory).AddSingleton(clientFactory).WithFeatureOverrides(features)).GetCompiler();
var compiler = ServiceBuilder.Create(s => s.AddSingleton(templateSpecRepositoryFactory).AddSingleton(clientFactory).WithFeatureOverrides(features).WithAnalyzersCodesToDisableConfiguration(BicepTestConstants.TestAnalyzersToSkip)).GetCompiler();

var fileUri = PathHelper.FilePathToFileUrl(Path.Combine(outputDirectory, DataSet.TestFileMain));
var compilation = await compiler.CreateCompilation(fileUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@
"newText": "'./modulec.json'"
}
},
{
"label": "moduled.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_moduled.bicep",
"filterText": "'./moduled.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "'./moduled.bicep'"
}
},
{
"label": "moduled.json",
"kind": "file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@
"newText": "'modulec.json'"
}
},
{
"label": "moduled.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_moduled.bicep",
"filterText": "'moduled.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "'moduled.bicep'"
}
},
{
"label": "moduled.json",
"kind": "file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@
"newText": "'modulec.json'"
}
},
{
"label": "moduled.bicep",
"kind": "file",
"deprecated": false,
"preselect": false,
"sortText": "1_moduled.bicep",
"filterText": "'moduled.bicep'",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "'moduled.bicep'"
}
},
{
"label": "moduled.json",
"kind": "file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,34 @@
"newText": "modCycle"
}
},
{
"label": "modDOne",
"kind": "module",
"detail": "modDOne",
"deprecated": false,
"preselect": false,
"sortText": "2_modDOne",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "modDOne"
}
},
{
"label": "modDTwo",
"kind": "module",
"detail": "modDTwo",
"deprecated": false,
"preselect": false,
"sortText": "2_modDTwo",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "modDTwo"
}
},
{
"label": "modWithListKeysInCondition",
"kind": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,34 @@
"newText": "modCycle"
}
},
{
"label": "modDOne",
"kind": "module",
"detail": "modDOne",
"deprecated": false,
"preselect": false,
"sortText": "2_modDOne",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "modDOne"
}
},
{
"label": "modDTwo",
"kind": "module",
"detail": "modDTwo",
"deprecated": false,
"preselect": false,
"sortText": "2_modDTwo",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "modDTwo"
}
},
{
"label": "modWithListKeysInCondition",
"kind": "module",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module nonExistentFileRef './nonExistent.bicep' = {
module nonExistentFileRef './nonExistent.bicep' = {

}

Expand All @@ -16,6 +16,21 @@ module moduleWithoutPath = {

}

module modDOne 'moduled.bicep' = {
name: 'modDOne'
params: {
input: 'NameOne'
}
}

module modDTwo 'moduled.bicep' = {
name: 'modDTwo'
params: {
input: modDOne.outputs.storageAccountName
}
}


// #completionTest(41) -> moduleBodyCompletions
module moduleWithPath './moduleb.bicep' =

Expand Down Expand Up @@ -566,4 +581,4 @@ module jsonModMissingParam 'moduled.json' = {
module assignToOutput 'empty.bicep' = {
name: 'assignToOutput'
outputs: {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ module moduleWithoutPath = {
}
//@[000:001) [BCP007 (Error)] This declaration type is not recognized. Specify a metadata, parameter, variable, resource, or output declaration. (bicep https://aka.ms/bicep/core-diagnostics#BCP007) |}|

module modDOne 'moduled.bicep' = {
name: 'modDOne'
params: {
input: 'NameOne'
}
}

module modDTwo 'moduled.bicep' = {
name: 'modDTwo'
params: {
input: modDOne.outputs.storageAccountName
//@[011:045) [what-if-short-circuiting (Warning)] Runtime value 'modDOne.outputs.storageAccountName' will reduce the precision of what-if analysis for module 'modDTwo' (bicep core linter https://aka.ms/bicep/linter/what-if-short-circuiting) |modDOne.outputs.storageAccountName|
}
}


// #completionTest(41) -> moduleBodyCompletions
module moduleWithPath './moduleb.bicep' =
//@[041:041) [BCP118 (Error)] Expected the "{" character, the "[" character, or the "if" keyword at this location. (bicep https://aka.ms/bicep/core-diagnostics#BCP118) ||
Expand Down Expand Up @@ -803,3 +819,4 @@ module assignToOutput 'empty.bicep' = {
outputs: {}
//@[002:009) [BCP073 (Error)] The property "outputs" is read-only. Expressions cannot be assigned to read-only properties. (bicep https://aka.ms/bicep/core-diagnostics#BCP073) |outputs|
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ module moduleWithoutPath = {

}

module modDOne 'moduled.bicep' = {
name: 'modDOne'
params: {
input: 'NameOne'
}
}

module modDTwo 'moduled.bicep' = {
name: 'modDTwo'
params: {
input: modDOne.outputs.storageAccountName
}
}

// #completionTest(41) -> moduleBodyCompletions
module moduleWithPath './moduleb.bicep' =

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ module moduleWithoutPath = {

}

module modDOne 'moduled.bicep' = {
//@[07:14) Module modDOne. Type: module. Declaration start char: 0, length: 91
name: 'modDOne'
params: {
input: 'NameOne'
}
}

module modDTwo 'moduled.bicep' = {
//@[07:14) Module modDTwo. Type: module. Declaration start char: 0, length: 116
name: 'modDTwo'
params: {
input: modDOne.outputs.storageAccountName
}
}


// #completionTest(41) -> moduleBodyCompletions
module moduleWithPath './moduleb.bicep' =
//@[07:21) Module moduleWithPath. Type: module. Declaration start char: 0, length: 41
Expand Down Expand Up @@ -745,3 +762,4 @@ module assignToOutput 'empty.bicep' = {
name: 'assignToOutput'
outputs: {}
}

Loading
Loading