You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Control flow schematic formatter option to preserve newlines #53494
area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
The new control flow migration is a marvellous bit of engineering, however the formatter has a troublesome side-effect of removing all newlines from the templates. It would be preferable were the migration formatter to take a more minimalistic approach to formatting, only adding newlines / whitespace where the control flow code is added to the html templates.
Proposed solution
Add a property to the control migration schema to preserve existing newlines when formatting. And naturally, the formatter should thus obey this.
Something like:
"preserveNewLines": {
"type": "boolean",
"description": "Preserve newlines when formatting",
"x-prompt": "Should existing newlines be preserved when formatting?",
"default": "false"
}
Alternatives considered
There are other formatters such as prettier, which is too opinionated, or beautify-js does not yet support the new control flow syntax.
I can understand the desire for this. There's a tradeoff to it though. When the control flow migration runs and replaces some content, some of the items, like ng-templates and ng-containers, get removed. That ends up leaving a blank line behind. The removal of newlines was a compromise to not leave awkward empty lines where there were none before. So preserving newlines would essentially leave all the prior existing newlines, but would also leave in the awkwardly added newlines from the migration, as well.
Thanks @jessicajaniuk for the quick reply! The thought process makes sense. Speaking for myself, I wonder if it be bad to simply remove only those lines where the ng-templates and ng-containers were previously, as they no longer have meaning?
The current behaviour presents a conundrum for some users: use the formatter and have all newlines wiped out, and have to go line by line through every file to undo it, or not use the formatter and have to go through every template and reposition all of the new control statements. Either of those involves a not inconsiderable amount of tedium and headache. IMHO, this method might be a nice compromise between the two.
The challenge here is that during the formatting process, there's no context into what was there before vs what's changed. It happens after the actual migration of code finishes and is just looking at the new template line by line. I can see if there's a way I can mark lines that were changed and only remove those newlines. If so, I can safely only remove newlines in the migrated areas.
area: migrationsIssues related to `ng update`/`ng generate` migrationscore: control flowIssues related to the built-in control flow (@if, @for, @switch)
Activity
jessicajaniuk commentedon Dec 11, 2023
I can understand the desire for this. There's a tradeoff to it though. When the control flow migration runs and replaces some content, some of the items, like ng-templates and ng-containers, get removed. That ends up leaving a blank line behind. The removal of newlines was a compromise to not leave awkward empty lines where there were none before. So preserving newlines would essentially leave all the prior existing newlines, but would also leave in the awkwardly added newlines from the migration, as well.
TimUnderhay commentedon Dec 11, 2023
Thanks @jessicajaniuk for the quick reply! The thought process makes sense. Speaking for myself, I wonder if it be bad to simply remove only those lines where the ng-templates and ng-containers were previously, as they no longer have meaning?
The current behaviour presents a conundrum for some users: use the formatter and have all newlines wiped out, and have to go line by line through every file to undo it, or not use the formatter and have to go through every template and reposition all of the new control statements. Either of those involves a not inconsiderable amount of tedium and headache. IMHO, this method might be a nice compromise between the two.
jessicajaniuk commentedon Dec 11, 2023
The challenge here is that during the formatting process, there's no context into what was there before vs what's changed. It happens after the actual migration of code finishes and is just looking at the new template line by line. I can see if there's a way I can mark lines that were changed and only remove those newlines. If so, I can safely only remove newlines in the migrated areas.
fix(migrations): CF migration only remove newlines of changed templat…
jessicajaniuk commentedon Dec 11, 2023
I put a fix up that should resolve this without needing an optional flag. It's in #53508.
TimUnderhay commentedon Dec 12, 2023
@jessicajaniuk you are a legend. Thank you!
fix(migrations): CF migration only remove newlines of changed templat…
angular-automatic-lock-bot commentedon Jan 12, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(migrations): CF migration only remove newlines of changed templat…
fix(migrations): CF migration only remove newlines of changed templat…
fix(migrations): CF migration only remove newlines of changed templat…