⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@alan-agius4
Copy link
Collaborator

This change introduces automatic formatting of files generated or modified during a schematic execution.

When a schematic is executed, the CLI will now attempt to find and use the project's local Prettier installation to format all created or updated files. This ensures that generated code adheres to the project's established coding style without requiring developers to manually run a formatting command.

If Prettier is not installed in the user's workspace, the formatting step will be gracefully skipped. This avoids adding a direct dependency on Prettier to the CLI and respects the user's project setup. The implementation leverages the Prettier CLI directly for a more robust and reliable formatting process.

Closes #10777

@alan-agius4 alan-agius4 requested a review from clydin January 27, 2026 08:37
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Jan 27, 2026
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/cli labels Jan 27, 2026
Comment on lines 57 to 64
await execFileAsync(prettierCliPath, [
'--write',
...[...files].filter((f) => fileTypes.has(extname(f))).map((f) => relative(cwd, f)),
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, this might need the shell option enabled.

Copy link
Collaborator Author

@alan-agius4 alan-agius4 Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'll see when this is merged.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 27, 2026
This change introduces automatic formatting of files generated or modified during a schematic execution.

When a schematic is executed, the CLI will now attempt to find and use the project's local Prettier installation to format all created or updated files. This ensures that generated code adheres to the project's established coding style without requiring developers to manually run a formatting command.

If Prettier is not installed in the user's workspace, the formatting step will be gracefully skipped. This avoids adding a direct dependency on Prettier to the CLI and respects the user's project setup. The implementation leverages the Prettier CLI directly for a more robust and reliable formatting process.

Closes angular#10777
@alan-agius4 alan-agius4 force-pushed the formatter branch 3 times, most recently from a10a6ca to f6721ed Compare January 27, 2026 19:50
@alan-agius4 alan-agius4 merged commit fbae1b6 into angular:main Jan 28, 2026
34 checks passed
@alan-agius4
Copy link
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

@alan-agius4 alan-agius4 deleted the formatter branch January 28, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically run a formatter command after ng generate

2 participants