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

Permit newline breaks in ternary (a ? b : c), for and if statements #5829

Closed
anthony-c-martin opened this issue Feb 1, 2022 · 9 comments · Fixed by #11052
Closed

Permit newline breaks in ternary (a ? b : c), for and if statements #5829

anthony-c-martin opened this issue Feb 1, 2022 · 9 comments · Fixed by #11052
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@anthony-c-martin
Copy link
Member

anthony-c-martin commented Feb 1, 2022

Created from discussion in #146

If, For and Ternary statements often end up taking up a lot of horizontal space, and it would be nice to have the freedom to use line breaks to avoid this in Bicep. See below for some mockups.

Ternary

var foo = abc ? def : ghi
// could be rewritten as
var foo = abc ?
  def :
  ghi

If

resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' = if (someCondition) {
...
// could be rewritten as
resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' =
  if (someCondition) {
    ...
  }

For

resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' = [for (val, i) in someArray: {
...
// could be rewritten as
resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' =
  [for (val, i) in someArray: {
    ...
   }]
@slavizh
Copy link
Contributor

slavizh commented Feb 2, 2022

How could look with both if and for

resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' = [for (val, i) in someArray: if (someCondition) {
...
// could be rewritten as
resource foo 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' =
  [for (val, i) in someArray: 
  if (someCondition) {
...

@alex-frankel alex-frankel added Needs: Author Feedback Awaiting feedback from the author of the issue and removed Needs: Triage 🔍 labels Feb 2, 2022
@jonassamuelssoncab
Copy link

Is this something that's on the roadmap?
Also, I saw that this issue has at least one duplicate, #1760.

@slavizh
Copy link
Contributor

slavizh commented May 11, 2023

@anthony-c-martin is there any plans to continue the multi-line work for ternary operators and if statements?

@ghost
Copy link

ghost commented May 19, 2023

Hi anthony-c-martin, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! 😄 🦾

@github-project-automation github-project-automation bot moved this to Todo in Bicep May 19, 2023
@ghost ghost closed this as completed May 22, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Bicep May 22, 2023
@slavizh
Copy link
Contributor

slavizh commented May 22, 2023

@anthony-c-martin @alex-frankel can this be re-opened? It is not completed and actually I have recently asked for status.

@anthony-c-martin anthony-c-martin removed the Needs: Author Feedback Awaiting feedback from the author of the issue label May 22, 2023
@shenglol
Copy link
Contributor

shenglol commented May 25, 2023

Another case to add here is the lambdas:

Lambda

(a, b, c) => '${a}-${b}-${c}'
(a, b, c) =>
  '${a}-${b}-${c}'

This is somewhat related to the prettier formatter. I'd be interested in implementing this.

Progress:

  • if-expression
  • for-expression
  • conditional (ternary) operator
  • lambdas

@Adam-S-Daniel
Copy link

I note a difference in the ternary implementation from #5829 (comment)

Ternary

var foo = abc ? def : ghi
// could be rewritten as
var foo = abc ?
  def :
  ghi

The supported syntax ended up being the following instead.

var foo = abc
  ? def
  : ghi

ref: https://github.com/Azure/bicep/blob/v0.19.5/src/Bicep.Core.Samples/Files/PrettyPrint_LF/main.syntax.bicep#L1430-L1449

@slavizh
Copy link
Contributor

slavizh commented Jul 20, 2023

@shenglol it seems new line does not work inside for(). Below gives error and it is not the same if you do not use for().

module modules 'modules/power-bi-embedded-capacities.bicep' = [for (resourceGroup, i) in resourceGroups:
  if (!empty(resourceGroup.modules)) {
  name: 'modules-${uniqueString(deploymentLocation)}-${i}'
  scope: resourceGroupsRes[i]
  params: {
    modules: union(defaultResourceGroup, resourceGroup).modules
  }
}]

@slavizh
Copy link
Contributor

slavizh commented Jul 24, 2023

@shenglol also does not work on module names
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants