-
Notifications
You must be signed in to change notification settings - Fork 117
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
Request: more sensible formatting for lists that require custom formatting #1045
Comments
If you place at least one line comment inside the list literal, it will preserve your newlines. It doesn't keep the extra spaces before the elements that you're using to line up things. This is a challenging problem. Users rely on the formatter heavily to clean up unformatted code, and it's really hard to tell which formatting is deliberate (like yours here) and which isn't. |
If you place at least one line comment inside the list literal, it will preserve your newlines. |
Unfortunately, it will still break when the max line length is reached. Which is fair, I guess, but not really useful in my case. Being able to opt out a region from formatting would still be the best way of handling it. |
There is a FAQ entry for that too. Being able to opt out of formatting for some regions has some positive value, but it comes with some trade-offs in terms of the overall user experience. I still lean towards it being a net negative to allow them, because then it will lead to users arguing about when and where to use them. The whole point of |
With all respect, users will always argue. By not being able to just opt out of a region, I can really only either opt out of I don't understand why the philosophies behind the formatter and the linter are so different here, aren't both official |
Yes, but they have some different constraints on them as well as a different history of usage. Linter rules are relatively independent from each other, so it's fairly low cost to support a variety of them and allow users to pick and choose. This isn't the case with the formatter where formatting options interact with subtle complex ways and testing all of the combinations of them gets combinatorially difficult. We do have a recommended set of lints now, and that set is deliberately non-configurable. We expect all internal Dart users to follow it. Like with the formatter, we do that to avoid low-value but time consuming arguments about which lints should and should not be enabled. |
I'm still very on the side of allowing disabling the formatter on certain regions of code. For anyone who has ever worked with const ColorFilter _kGreyscaleFilter = ColorFilter.matrix(<double>[
0.2126, 0.7152, 0.0722, 0, 0,
0.2126, 0.7152, 0.0722, 0, 0,
0.2126, 0.7152, 0.0722, 0, 0,
0, 0, 0, 1, 0,
]); Now this can mostly be achieved with adding a single comment to the end of the trailing comma (which I'm really not a fan of, but at least the list is broken up nicely I guess), however you'll notice we lose the whitespace on the last row: const ColorFilter _kGreyscaleFilter = ColorFilter.matrix(<double>[
0.2126, 0.7152, 0.0722, 0, 0, //
0.2126, 0.7152, 0.0722, 0, 0,
0.2126, 0.7152, 0.0722, 0, 0,
0, 0, 0, 1, 0,
]); There are two ways in which this can be solved:
|
I'm leaning towards supporting this too. I am (very) busy working on #1253 now, but after that (assuming I still have any bandwidth left), I intend to investigate support for opting regions out from formatting. |
I didn't realize this was a duplicate of the (ancient and closed) #361. I'm going to resurrect that and merge this one with it. |
I originally submitted this as a dart-code issue but someone correctly pointed out that this is actually the correct place for it.
Is your feature request related to a problem? Please describe.
Take for example this list, which needs to be viewed in a square because that's what it represents:
When I save the file in vscode, the formatter changes it to:
and so on.
Describe the solution you'd like
Maybe someone has a better solution than this, but what I think would work is that if the formatter detects a list that has already been broken into rows, if any of them has more than 1 item then it understands this was done deliberately and doesn't reformat the list.
Describe alternatives you've considered
The only solution I've found so far is to save these lists in some constants.dart, disable the dart formatter while saving it and then turn it back on. Maybe there's another way that I can't find in the settings.
Also related, I have another constant like this:
that gets broken into this:
and this is also not desirable.
The text was updated successfully, but these errors were encountered: