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

[dartformat] Better code formatting for flow controls in Maps #1440

Open
escamoteur opened this issue Apr 18, 2024 · 3 comments
Open

[dartformat] Better code formatting for flow controls in Maps #1440

escamoteur opened this issue Apr 18, 2024 · 3 comments

Comments

@escamoteur
Copy link

I recently stumbled upon this piece of code from a colleague of mine and had real problems at first to understand what is going on here:

grafik

One reason for sure was that I wasn't aware that we can use if and for not only inside Lists but also for Maps which is indeed a pretty cool feature :-) the bigger reason IMHO is that the way dartformat currently treats this makes it hard to spot where the key of the created/inserted pair is. To be honest I don't have a good idea of how to do this better. Maybe outdent the key?
Maybe @munificent has an idea of how to improve this.

@julemand101
Copy link

Maybe the issue should be moved to: https://github.com/dart-lang/dart_style/issues ?

@escamoteur
Copy link
Author

Oh definitely, I didn't know that there is a separate repository for the formatted. So please anyone who can move an issue please move it there?

@mraleph mraleph transferred this issue from dart-lang/sdk Apr 18, 2024
@VojtaStanek
Copy link

VojtaStanek commented Apr 24, 2024

I agree!
I would like to insert a new line after a conditional or loop statement and indent the key. Here's an example of how it could look:

final current = {
  if (true) 'a': 1,
  for (final i in [1, 2, 3]) 'b$i': i,
  for (final nested in foo1)
    for (final i in nested) 'c$i': i,
  for (final nested in foo2) ...nested,
};
final proposed = {
  if (true)
    'a': 1,
  for (var i in [1, 2, 3])
    'b$i': i,
  for (final nested in foo1)
    for (final i in nested)
      'c$i': i,
  for (final nested in foo2)
    ...nested,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants