Skip to content

Commit

Permalink
Formatter v2 part 7: Less newline sensitivity for if-expression and f…
Browse files Browse the repository at this point in the history
…or-expression (#10984)

Partially addresses #5829.

###### Microsoft Reviewers: [Open in
CodeFlow](https://portal.fabricbot.ms/api/codeflow?pullrequest=https://github.com/Azure/bicep/pull/10984)
  • Loading branch information
shenglol authored Jun 19, 2023
1 parent efa5eca commit a347ebb
Show file tree
Hide file tree
Showing 65 changed files with 2,961 additions and 1,457 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
},
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "/.github/workflows/*.yml"
}
},
"dotnet.defaultSolution": "Bicep.sln"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void Print_VariousWidths_OptimizesLayoutAccordingly(int width)

[DataTestMethod]
[DynamicData(nameof(GetData), DynamicDataSourceType.Method, DynamicDataDisplayNameDeclaringType = typeof(DataSet), DynamicDataDisplayName = nameof(DataSet.GetDisplayName))]
[TestCategory(BaselineHelper.BaselineTestCategory)]
public void Print_DataSet_ProducesExpectedOutput(DataSet dataSet)
{
var output = Print(dataSet.Bicep, PrettyPrinterV2Options.Default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ resource vm 'Microsoft.Compute/virtualMachines@2020-12-01' = {
properties: vmProperties
}

var ipConfigurations = [for i in range(0, 2): {
id: true
name: 'asdf${i}'
properties: {
madeUpProperty: boolVal
subnet: 'hello'
var ipConfigurations = [
for i in range(0, 2): {
id: true
name: 'asdf${i}'
properties: {
madeUpProperty: boolVal
subnet: 'hello'
}
}
}]
]

resource nic 'Microsoft.Network/networkInterfaces@2020-11-01' = {
name: 'abc'
Expand All @@ -33,25 +35,26 @@ resource nic 'Microsoft.Network/networkInterfaces@2020-11-01' = {
}
}

resource nicLoop 'Microsoft.Network/networkInterfaces@2020-11-01' = [for i in range(
0,
2
): {
name: 'abc${i}'
properties: {
ipConfigurations: [
// TODO: fix this
ipConfigurations[i]
]
resource nicLoop 'Microsoft.Network/networkInterfaces@2020-11-01' = [
for i in range(0, 2): {
name: 'abc${i}'
properties: {
ipConfigurations: [
// TODO: fix this
ipConfigurations[i]
]
}
}
}]
]

resource nicLoop2 'Microsoft.Network/networkInterfaces@2020-11-01' = [for ipConfig in ipConfigurations: {
name: 'abc${ipConfig.name}'
properties: {
ipConfigurations: [
// TODO: fix this
ipConfig
]
resource nicLoop2 'Microsoft.Network/networkInterfaces@2020-11-01' = [
for ipConfig in ipConfigurations: {
name: 'abc${ipConfig.name}'
properties: {
ipConfigurations: [
// TODO: fix this
ipConfig
]
}
}
}]
]
27 changes: 14 additions & 13 deletions src/Bicep.Core.Samples/Files/InvalidLambdas_LF/main.pprint.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ var inObject = {

var inArray = [i => i, j => j]

resource stg 'Microsoft.Storage/storageAccounts@2021-09-01' = [for i in range(
0,
2
): {
name: 'antteststg${i}'
location: 'West US'
sku: {
name: 'Standard_LRS'
resource stg 'Microsoft.Storage/storageAccounts@2021-09-01' = [
for i in range(0, 2): {
name: 'antteststg${i}'
location: 'West US'
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
kind: 'StorageV2'
}]
]

output stgKeys array = map(range(0, 2), i => stg[i].listKeys().keys[0].value)
output stgKeys2 array = map(
Expand All @@ -76,9 +75,11 @@ output accessTiers2 array = map(
)
output accessTiers3 array = map(ids, foo => reference('${foo}').accessTier)

module modLoop './empty.bicep' = [for item in range(0, 5): {
name: 'foo${item}'
}]
module modLoop './empty.bicep' = [
for item in range(0, 5): {
name: 'foo${item}'
}
]

var modLoopNames = map(modLoop, i => i.name)
output modOutputs array = map(range(0, 5), i => modLoop[i].outputs.foo)
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@ module subscriptionModuleDuplicateName2 'modules/subscription.bicep' = {
scope: subscription('1ad827ac-2669-4c2f-9970-282b93c3c550')
}

module managementGroupModules 'modules/managementGroup.bicep' = [for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroup(mg)
}]

module cannotUseModuleCollectionAsScope 'modules/managementGroup.bicep' = [for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroupModules
}]

module cannotUseSingleModuleAsScope 'modules/managementGroup.bicep' = [for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroupModules[i]
}]
module managementGroupModules 'modules/managementGroup.bicep' = [
for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroup(mg)
}
]

module cannotUseModuleCollectionAsScope 'modules/managementGroup.bicep' = [
for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroupModules
}
]

module cannotUseSingleModuleAsScope 'modules/managementGroup.bicep' = [
for (mg, i) in []: {
name: 'dep-${mg}'
scope: managementGroupModules[i]
}
]

module cannotUseSingleModuleAsScope2 'modules/managementGroup.bicep' = {
name: 'test'
Expand Down
Loading

0 comments on commit a347ebb

Please sign in to comment.