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

Formatter v2 part 8: Make ternary operators and lambdas less newline sensitive #11052

Merged
merged 8 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/SetBaseline.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet test --filter "TestCategory=Baseline" -- 'TestRunParameters.Parameter(name=\"SetBaseLine\", value=\"true\")'
dotnet test --filter "TestCategory=Baseline" -- 'TestRunParameters.Parameter(name="SetBaseLine", value="true")'
jeskew marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion src/Bicep.Core.Samples/Files/Functions_LF/main.pprint.bicep
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
func buildUrl(https bool, hostname string, path string) string => '${https ? 'https' : 'http'}://${hostname}${empty(path) ? '' : '/${path}'}'
func buildUrl(https bool, hostname string, path string) string =>
'${https ? 'https' : 'http'}://${hostname}${empty(path) ? '' : '/${path}'}'

output foo string = buildUrl(true, 'google.com', 'search')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ var ternary = null ? 4 : false
var complex = test(2 + 3 * 4, true || false && null)
var complex = -2 && 3 && !4 && 5
var complex = null ? !4 : false
var complex = true == false != null == 4 != 'a' ? -2 && 3 && !4 && 5 : true || false && null
var complex = true == false != null == 4 != 'a'
? -2 && 3 && !4 && 5
: true || false && null

var nestedTernary = null ? 1 : 2 ? true ? 'a' : 'b' : false ? 'd' : 15
var nestedTernary = (null ? 1 : 2) ? (true ? 'a' : 'b') : (false ? 'd' : 15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,11 +1590,13 @@ resource dataCollectionRuleRes 'Microsoft.Insights/dataCollectionRules@2021-04-0
properties: {
description: dataCollectionRule.description
destinations: union(
empty(dataCollectionRule.destinations.azureMonitorMetrics.name) ? {} : {
azureMonitorMetrics: {
name: dataCollectionRule.destinations.azureMonitorMetrics.name
}
},
empty(dataCollectionRule.destinations.azureMonitorMetrics.name)
? {}
: {
azureMonitorMetrics: {
name: dataCollectionRule.destinations.azureMonitorMetrics.name
}
},
{
logAnalytics: [
for (logAnalyticsWorkspace, i) in dataCollectionRule.destinations.logAnalyticsWorkspaces: {
Expand Down
9 changes: 9 additions & 0 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ var objectMap2 = toObject(range(0, 10), i => '${i}', i => {
isGreaterThan4: (i > 4)
})
var objectMap3 = toObject(sortByObjectKey, x => x.name)
var objectMap4 = toObject(sortByObjectKey, x =>

x.name)
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
})
12 changes: 12 additions & 0 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.diagnostics.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,16 @@ var objectMap2 = toObject(range(0, 10), i => '${i}', i => {
})
var objectMap3 = toObject(sortByObjectKey, x => x.name)
//@[04:14) [no-unused-vars (Warning)] Variable "objectMap3" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |objectMap3|
var objectMap4 = toObject(sortByObjectKey, x =>
//@[04:14) [no-unused-vars (Warning)] Variable "objectMap4" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |objectMap4|

x.name)
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
//@[04:14) [no-unused-vars (Warning)] Variable "objectMap5" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |objectMap5|
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
//@[04:14) [no-unused-vars (Warning)] Variable "objectMap6" is declared but never used. (CodeDescription: bicep core(https://aka.ms/bicep/linter/no-unused-vars)) |objectMap6|
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
})

9 changes: 9 additions & 0 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.formatted.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ var objectMap2 = toObject(range(0, 10), i => '${i}', i => {
isGreaterThan4: (i > 4)
})
var objectMap3 = toObject(sortByObjectKey, x => x.name)
var objectMap4 = toObject(sortByObjectKey, x =>

x.name)
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
})
45 changes: 44 additions & 1 deletion src/Bicep.Core.Samples/Files/Lambdas_LF/main.ir.bicep
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var doggos = [
//@[000:2533) ProgramExpression
//@[000:2847) ProgramExpression
//@[000:0054) ├─DeclaredVariableExpression { Name = doggos }
//@[013:0054) | └─ArrayExpression
'Evie'
Expand Down Expand Up @@ -442,4 +442,47 @@ var objectMap3 = toObject(sortByObjectKey, x => x.name)
//@[043:0054) | └─LambdaExpression
//@[048:0054) | └─PropertyAccessExpression { PropertyName = name }
//@[048:0049) | └─LambdaVariableReferenceExpression { Variable = x }
var objectMap4 = toObject(sortByObjectKey, x =>
//@[000:0060) ├─DeclaredVariableExpression { Name = objectMap4 }
//@[017:0060) | └─FunctionCallExpression { Name = toObject }
//@[026:0041) | ├─VariableReferenceExpression { Variable = sortByObjectKey }
//@[043:0059) | └─LambdaExpression

x.name)
//@[002:0008) | └─PropertyAccessExpression { PropertyName = name }
//@[002:0003) | └─LambdaVariableReferenceExpression { Variable = x }
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
//@[000:0129) ├─DeclaredVariableExpression { Name = objectMap5 }
//@[017:0129) | └─FunctionCallExpression { Name = toObject }
//@[026:0041) | ├─VariableReferenceExpression { Variable = sortByObjectKey }
//@[043:0128) | └─LambdaExpression
//@[085:0128) | └─PropertyAccessExpression { PropertyName = name }
//@[085:0123) | └─LambdaVariableReferenceExpression { Variable = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
//@[000:0122) ├─DeclaredVariableExpression { Name = objectMap6 }
//@[017:0122) | └─FunctionCallExpression { Name = toObject }
//@[026:0038) | ├─FunctionCallExpression { Name = range }
//@[032:0033) | | ├─IntegerLiteralExpression { Value = 0 }
//@[035:0037) | | └─IntegerLiteralExpression { Value = 10 }
//@[040:0051) | ├─LambdaExpression
//@[045:0051) | | └─InterpolatedStringExpression
//@[048:0049) | | └─LambdaVariableReferenceExpression { Variable = i }
//@[053:0121) | └─LambdaExpression
{
//@[000:0052) | └─ObjectExpression
isEven: (i % 2) == 0
//@[002:0022) | ├─ObjectPropertyExpression
//@[002:0008) | | ├─StringLiteralExpression { Value = isEven }
//@[010:0022) | | └─BinaryExpression { Operator = Equals }
//@[011:0016) | | ├─BinaryExpression { Operator = Modulo }
//@[011:0012) | | | ├─LambdaVariableReferenceExpression { Variable = i }
//@[015:0016) | | | └─IntegerLiteralExpression { Value = 2 }
//@[021:0022) | | └─IntegerLiteralExpression { Value = 0 }
isGreaterThan4: (i > 4)
//@[002:0025) | └─ObjectPropertyExpression
//@[002:0016) | ├─StringLiteralExpression { Value = isGreaterThan4 }
//@[019:0024) | └─BinaryExpression { Operator = GreaterThan }
//@[019:0020) | ├─LambdaVariableReferenceExpression { Variable = i }
//@[023:0024) | └─IntegerLiteralExpression { Value = 4 }
})

7 changes: 5 additions & 2 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "4686158236210752139"
"templateHash": "842468545343421723"
}
},
"variables": {
Expand Down Expand Up @@ -48,7 +48,10 @@
"parentheses": "[map(createArray(123), lambda('i', format('{0}', lambdaVariables('i'))))]",
"objectMap": "[toObject(createArray(123, 456, 789), lambda('i', format('{0}', div(lambdaVariables('i'), 100))))]",
"objectMap2": "[toObject(range(0, 10), lambda('i', format('{0}', lambdaVariables('i'))), lambda('i', createObject('isEven', equals(mod(lambdaVariables('i'), 2), 0), 'isGreaterThan4', greater(lambdaVariables('i'), 4))))]",
"objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]"
"objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",
"objectMap4": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",
"objectMap5": "[toObject(variables('sortByObjectKey'), lambda('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', lambdaVariables('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').name))]",
"objectMap6": "[toObject(range(0, 10), lambda('i', format('{0}', lambdaVariables('i'))), lambda('i', createObject('isEven', equals(mod(lambdaVariables('i'), 2), 0), 'isGreaterThan4', greater(lambdaVariables('i'), 4))))]"
},
"resources": [
{
Expand Down
16 changes: 16 additions & 0 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.pprint.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@ var objectMap2 = toObject(
}
)
var objectMap3 = toObject(sortByObjectKey, x => x.name)
var objectMap4 = toObject(sortByObjectKey, x => x.name)
var objectMap5 = toObject(
sortByObjectKey,
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx =>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name
)
var objectMap6 = toObject(
range(0, 10),
i => '${i}',
i =>
// comment
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
}
)
14 changes: 13 additions & 1 deletion src/Bicep.Core.Samples/Files/Lambdas_LF/main.sourcemap.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,17 @@ var objectMap2 = toObject(range(0, 10), i => '${i}', i => {
isGreaterThan4: (i > 4)
})
var objectMap3 = toObject(sortByObjectKey, x => x.name)
//@ "objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]"
//@ "objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",
var objectMap4 = toObject(sortByObjectKey, x =>
//@ "objectMap4": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",

x.name)
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
//@ "objectMap5": "[toObject(variables('sortByObjectKey'), lambda('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', lambdaVariables('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').name))]",
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
//@ "objectMap6": "[toObject(range(0, 10), lambda('i', format('{0}', lambdaVariables('i'))), lambda('i', createObject('isEven', equals(mod(lambdaVariables('i'), 2), 0), 'isGreaterThan4', greater(lambdaVariables('i'), 4))))]"
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
})

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"_generator": {
"name": "bicep",
"version": "dev",
"templateHash": "7333326022903475769"
"templateHash": "255327203079656600"
}
},
"variables": {
Expand Down Expand Up @@ -50,7 +50,10 @@
"parentheses": "[map(createArray(123), lambda('i', format('{0}', lambdaVariables('i'))))]",
"objectMap": "[toObject(createArray(123, 456, 789), lambda('i', format('{0}', div(lambdaVariables('i'), 100))))]",
"objectMap2": "[toObject(range(0, 10), lambda('i', format('{0}', lambdaVariables('i'))), lambda('i', createObject('isEven', equals(mod(lambdaVariables('i'), 2), 0), 'isGreaterThan4', greater(lambdaVariables('i'), 4))))]",
"objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]"
"objectMap3": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",
"objectMap4": "[toObject(variables('sortByObjectKey'), lambda('x', lambdaVariables('x').name))]",
"objectMap5": "[toObject(variables('sortByObjectKey'), lambda('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', lambdaVariables('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').name))]",
"objectMap6": "[toObject(range(0, 10), lambda('i', format('{0}', lambdaVariables('i'))), lambda('i', createObject('isEven', equals(mod(lambdaVariables('i'), 2), 0), 'isGreaterThan4', greater(lambdaVariables('i'), 4))))]"
},
"resources": {
"storageAcc": {
Expand Down
16 changes: 16 additions & 0 deletions src/Bicep.Core.Samples/Files/Lambdas_LF/main.symbols.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,20 @@ var objectMap2 = toObject(range(0, 10), i => '${i}', i => {
var objectMap3 = toObject(sortByObjectKey, x => x.name)
//@[043:044) Local x. Type: object | object | object | object. Declaration start char: 43, length: 1
//@[004:014) Variable objectMap3. Type: object. Declaration start char: 0, length: 55
var objectMap4 = toObject(sortByObjectKey, x =>
//@[043:044) Local x. Type: object | object | object | object. Declaration start char: 43, length: 1
//@[004:014) Variable objectMap4. Type: object. Declaration start char: 0, length: 60

x.name)
var objectMap5 = toObject(sortByObjectKey, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.name)
//@[043:081) Local xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Type: object | object | object | object. Declaration start char: 43, length: 38
//@[004:014) Variable objectMap5. Type: object. Declaration start char: 0, length: 129
var objectMap6 = toObject(range(0, 10), i => '${i}', i => // comment
//@[040:041) Local i. Type: int. Declaration start char: 40, length: 1
//@[053:054) Local i. Type: int. Declaration start char: 53, length: 1
//@[004:014) Variable objectMap6. Type: object. Declaration start char: 0, length: 122
{
isEven: (i % 2) == 0
isGreaterThan4: (i > 4)
})

Loading