Skip to content

Commit 4221a33

Browse files
committed
fix(@schematics/angular): add missing prettier config
The current style guide no longer enforces the use of the template file extension `.component.html`. This means that prettier won't auto-detect the proper parser for these files anymore. To ensure template formatting works out-of-the-box, we're adding a prettier config to newly created projects. Fixes #30548
1 parent 1c5bd2e commit 4221a33

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/schematics/angular/workspace/files/package.json.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
"watch": "ng build --watch --configuration development"<% if (!minimal) { %>,
99
"test": "ng test"<% } %>
1010
},
11+
"prettier": {
12+
"overrides": [
13+
{
14+
"files": "*.html",
15+
"options": {
16+
"parser": "angular"
17+
}
18+
}
19+
]
20+
},
1121
"private": true,
1222
"dependencies": {
1323
"@angular/common": "<%= latestVersions.Angular %>",

packages/schematics/angular/workspace/index_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,10 @@ describe('Workspace Schematic', () => {
133133
const { tasks } = parseJson(tree.readContent('.vscode/tasks.json').toString());
134134
expect(tasks).not.toContain(jasmine.objectContaining({ type: 'npm', script: 'test' }));
135135
});
136+
137+
it('should include prettier config overrides for Angular templates', async () => {
138+
const tree = await schematicRunner.runSchematic('workspace', defaultOptions);
139+
const pkg = JSON.parse(tree.readContent('/package.json'));
140+
expect(pkg.prettier).withContext('package.json#prettier is present').toBeTruthy();
141+
});
136142
});

0 commit comments

Comments
 (0)