Skip to content

Commit 45d959a

Browse files
committed
refactor(@angular-devkit/schematics): add consistent spacing and ordering
* add consistent spacing and tags around `<%`, `%>, and operators * reorder component decorator properties to be alphabetical * remove empty constructors * change spacing to ensure all outputs are consistently styled
1 parent c6583cd commit 45d959a

22 files changed

Lines changed: 47 additions & 63 deletions

packages/schematics/angular/application/files/module-files/src/app/app__suffix__.spec.ts.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('App', () => {
1111
declarations: [
1212
App
1313
],
14-
}).compileComponents();
14+
})
15+
.compileComponents();
1516
});
1617

1718
it('should create the app', () => {
@@ -20,7 +21,7 @@ describe('App', () => {
2021
expect(app).toBeTruthy();
2122
});
2223

23-
it('should render title', <% if(zoneless) { %>async <% } %>() => {
24+
it('should render title', <% if (zoneless) { %>async <% } %>() => {
2425
const fixture = TestBed.createComponent(App);
2526
<%= zoneless ? 'await fixture.whenStable();' : 'fixture.detectChanges();' %>
2627
const compiled = fixture.nativeElement as HTMLElement;

packages/schematics/angular/application/files/module-files/src/app/app__suffix__.ts.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Component, signal } from '@angular/core';
22

33
@Component({
4-
selector: '<%= selector %>',<% if(inlineTemplate) { %>
4+
selector: '<%= selector %>',
5+
standalone: false,<% if (inlineStyle) { %>
6+
styles: []<% } else { %>
7+
styleUrl: './app<%= suffix %>.<%= style %>'<% } %><% if (inlineTemplate) { %>
58
template: `
69
<h1>Hello, {{ title() }}</h1>
710
<p>Congratulations! Your app is running. 🎉</p>
@@ -11,9 +14,6 @@ import { Component, signal } from '@angular/core';
1114
} %>
1215
`,<% } else { %>
1316
templateUrl: './app<%= suffix %>.html',<% } %>
14-
standalone: false,<% if(inlineStyle) { %>
15-
styles: []<% } else { %>
16-
styleUrl: './app<%= suffix %>.<%= style %>'<% } %>
1717
})
1818
export class App {
1919
protected readonly title = signal('<%= name %>');

packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { NgModule, provideBrowserGlobalErrorListeners<% if(!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';
2-
import { BrowserModule } from '@angular/platform-browser';
3-
<% if (routing) { %>
1+
import { NgModule, provideBrowserGlobalErrorListeners<% if (!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';<% if (routing) { %>
43
import { AppRoutingModule } from './app-routing<%= typeSeparator %>module';<% } %>
54
import { App } from './app<%= suffix %>';
65

@@ -13,7 +12,7 @@ import { App } from './app<%= suffix %>';
1312
AppRoutingModule<% } %>
1413
],
1514
providers: [
16-
provideBrowserGlobalErrorListeners(),<% if(!zoneless) { %>
15+
provideBrowserGlobalErrorListeners(),<% if (!zoneless) { %>
1716
provideZoneChangeDetection({ eventCoalescing: true }),<% } %>
1817
],
1918
bootstrap: [App]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<% if(!!viewEncapsulation) { %>import { ViewEncapsulation } from '@angular/core';
2-
<% }%>import { platformBrowser } from '@angular/platform-browser';
1+
<% if (!!viewEncapsulation) { %>import { ViewEncapsulation } from '@angular/core';
2+
<% } %>import { platformBrowser } from '@angular/platform-browser';
33
import { AppModule } from './app/app<%= typeSeparator %>module';
44

55
platformBrowser().bootstrapModule(AppModule, {
6-
<% if(!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
6+
<% if (!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
77
})
88
.catch(err => console.error(err));
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { ApplicationConfig, provideBrowserGlobalErrorListeners<% if(!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';<% if (routing) { %>
1+
import { ApplicationConfig, provideBrowserGlobalErrorListeners<% if (!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';<% if (routing) { %>
22
import { provideRouter } from '@angular/router';
3-
43
import { routes } from './app.routes';<% } %>
54

65
export const appConfig: ApplicationConfig = {
76
providers: [
8-
provideBrowserGlobalErrorListeners(),<% if(!zoneless) { %>
7+
provideBrowserGlobalErrorListeners(),<% if (!zoneless) { %>
98
provideZoneChangeDetection({ eventCoalescing: true }),<% } %>
10-
<% if (routing) {%>provideRouter(routes)<% } %>
9+
<% if (routing) { %>provideRouter(routes)<% } %>
1110
]
1211
};

packages/schematics/angular/application/files/standalone-files/src/app/app__suffix__.spec.ts.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ describe('App', () => {
55
beforeEach(async () => {
66
await TestBed.configureTestingModule({
77
imports: [App],
8-
}).compileComponents();
8+
})
9+
.compileComponents();
910
});
1011

1112
it('should create the app', () => {
@@ -14,7 +15,7 @@ describe('App', () => {
1415
expect(app).toBeTruthy();
1516
});
1617

17-
it('should render title', <% if(zoneless) { %>async <% } %>() => {
18+
it('should render title', <% if (zoneless) { %>async <% } %>() => {
1819
const fixture = TestBed.createComponent(App);
1920
<%= zoneless ? 'await fixture.whenStable();' : 'fixture.detectChanges();' %>
2021
const compiled = fixture.nativeElement as HTMLElement;

packages/schematics/angular/application/files/standalone-files/src/app/app__suffix__.ts.template

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { Component, signal } from '@angular/core';<% if(routing) { %>
1+
import { Component, signal } from '@angular/core';<% if (routing) { %>
22
import { RouterOutlet } from '@angular/router';<% } %>
33

44
@Component({
5-
selector: '<%= selector %>',
6-
imports: [<% if(routing) { %>RouterOutlet<% } %>],<% if(inlineTemplate) { %>
5+
imports: [<% if (routing) { %>RouterOutlet<% } %>],
6+
selector: '<%= selector %>',<% if (inlineStyle) { %>
7+
styles: [],<% } else { %>
8+
styleUrl: './app<%= suffix %>.<%= style %>',<% } %><% if (inlineTemplate) { %>
79
template: `
810
<h1>Hello, {{ title() }}</h1>
911

1012
<% if (routing) {
1113
%><router-outlet /><%
1214
} %>
1315
`,<% } else { %>
14-
templateUrl: './app<%= suffix %>.html',<% } if(inlineStyle) { %>
15-
styles: [],<% } else { %>
16-
styleUrl: './app<%= suffix %>.<%= style %>'<% } %>
16+
templateUrl: './app<%= suffix %>.html',<% } %>
1717
})
1818
export class App {
1919
protected readonly title = signal('<%= name %>');

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.__style__.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if(displayBlock){ if(style != 'sass') { %>:host {
1+
<% if (displayBlock) { if (style != 'sass') { %>:host {
22
display: block;
33
}
44
<% } else { %>\:host

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
3-
import <% if(!exportDefault) { %>{ <% }%><%= classifiedName %> <% if(!exportDefault) {%>} <% }%>from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>';
2+
import <% if (!exportDefault) { %>{ <% } %><%= classifiedName %> <% if (!exportDefault) { %>} <% } %>from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>';
43

54
describe('<%= classifiedName %>', () => {
65
let component: <%= classifiedName %>;
@@ -10,7 +9,7 @@ describe('<%= classifiedName %>', () => {
109
await TestBed.configureTestingModule({
1110
<%= standalone ? 'imports' : 'declarations' %>: [<%= classifiedName %>]
1211
})
13-
.compileComponents();
12+
.compileComponents();
1413

1514
fixture = TestBed.createComponent(<%= classifiedName %>);
1615
component = fixture.componentInstance;
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { <% if(changeDetection !== 'OnPush') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';
1+
import { <% if (changeDetection !== 'OnPush') { %>ChangeDetectionStrategy, <% } %>Component<% if (!!viewEncapsulation) { %>, ViewEncapsulation<% } %> } from '@angular/core';
22

3-
@Component({<% if(!skipSelector) {%>
4-
selector: '<%= selector %>',<%}%><% if(standalone) {%>
5-
imports: [],<%} else { %>
6-
standalone: false,<% }%><% if(inlineTemplate) { %>
3+
@Component({<% if (changeDetection !== 'OnPush') { %>
4+
changeDetection: ChangeDetectionStrategy.<%= changeDetection %>,<% } %><% if (!!viewEncapsulation) { %>
5+
encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } %><% if (standalone) { %>
6+
imports: [],<% } %><% if (!skipSelector) { %>
7+
selector: '<%= selector %>',<% } %><% if (!standalone) { %>
8+
standalone: false,<% } %><% if (inlineStyle) { %>
9+
styles: `<% if (displayBlock) { %>
10+
:host {
11+
display: block;
12+
}
13+
<% } %>`,<% } else if (style !== 'none') { %>
14+
styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>',<% } %><% if (inlineTemplate) { %>
715
template: `
816
<p>
917
<%= dasherize(name) %> works!
1018
</p>
1119
`,<% } else { %>
12-
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %><%= ngext %>.html',<% } if(inlineStyle) { %>
13-
styles: `<% if(displayBlock){ %>
14-
:host {
15-
display: block;
16-
}
17-
<% } %>`,<% } else if (style !== 'none') { %>
18-
styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>',<% } %><% if(!!viewEncapsulation) { %>
19-
encapsulation: ViewEncapsulation.<%= viewEncapsulation %>,<% } if (changeDetection !== 'OnPush') { %>
20-
changeDetection: ChangeDetectionStrategy.<%= changeDetection %>,<% } %>
20+
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %><%= ngext %>.html',<% } %>
2121
})
22-
export <% if(exportDefault) {%>default <%}%>class <%= classifiedName %> {
23-
22+
export <% if (exportDefault) { %>default <% } %>class <%= classifiedName %> {
2423
}

0 commit comments

Comments
 (0)