Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 8d307c5

Browse files
kapunahelewongjuleskremer
authored andcommitted
docs(style-guide): copy edits applying guidelines (#3403)
1 parent 0fc4028 commit 8d307c5

File tree

1 file changed

+78
-62
lines changed

1 file changed

+78
-62
lines changed

public/docs/ts/latest/guide/style-guide.jade

Lines changed: 78 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
include ../_util-fns
22

33
:marked
4-
Welcome to the Angular Style Guide
5-
6-
## Purpose
7-
84
Looking for an opinionated guide to Angular syntax, conventions, and application structure?
95
Step right in!
10-
This style guide presents our preferred conventions and, as importantly, explains why.
6+
This style guide presents preferred conventions and, as importantly, explains why.
7+
118
.l-main-section
9+
a(id='toc')
1210

11+
:marked
12+
# Contents
13+
14+
* [Single responsibility](#single-responsibility)
15+
* [Naming](#naming)
16+
* [Coding conventions](#coding-conventions)
17+
* [App structure and Angular modules](#application-structure-and-angular-modules)
18+
* [Components](#components)
19+
* [Directives](#directives)
20+
* [Services](#services)
21+
* [Data services](#data-services)
22+
* [Lifecycle hooks](#lifecycle-hooks)
23+
* [Appendix](#appendix)
24+
25+
26+
.l-main-section
1327
:marked
1428
## Style vocabulary
1529

@@ -32,6 +46,11 @@ include ../_util-fns
3246
.s-rule.avoid
3347
:marked
3448
**Avoid** indicates something you should almost never do. Code examples to *avoid* have an unmistakeable red header.
49+
50+
.s-why
51+
:marked
52+
**Why?** gives reasons for following the previous recommendations.
53+
3554
.l-main-section
3655

3756
:marked
@@ -40,37 +59,20 @@ include ../_util-fns
4059
Some code examples display a file that has one or more similarly named companion files.
4160
For example, `hero.component.ts` and `hero.component.html`.
4261

43-
The guideline will use the shortcut `hero.component.ts|html|css|spec` to represent those various files. Using this shortcut makes this guide's file structures easier to read and more terse.
44-
45-
.l-main-section
46-
a(id='toc')
47-
48-
:marked
49-
## Table of contents
50-
51-
1. [Single responsibility](#single-responsibility)
52-
1. [Naming](#naming)
53-
1. [Coding conventions](#coding-conventions)
54-
1. [App structure and Angular modules](#application-structure-and-angular-modules)
55-
1. [Components](#components)
56-
1. [Directives](#directives)
57-
1. [Services](#services)
58-
1. [Data services](#data-services)
59-
1. [Lifecycle hooks](#lifecycle-hooks)
60-
1. [Appendix](#appendix)
62+
The guideline uses the shortcut `hero.component.ts|html|css|spec` to represent those various files. Using this shortcut makes this guide's file structures easier to read and more terse.
6163

6264
.l-main-section
65+
a#single-responsibility
6366
:marked
6467
## Single responsibility
6568

6669
Apply the
67-
<a href="https://wikipedia.org/wiki/Single_responsibility_principle" target="_blank"><i>Single Responsibility Principle</i> (SRP)</a>
70+
<a href="https://wikipedia.org/wiki/Single_responsibility_principle" target="_blank"><i>single responsibility principle</i> (SRP)</a>
6871
to all components, services, and other symbols.
6972
This helps make the app cleaner, easier to read and maintain, and more testable.
7073

71-
a#rule-of-one
72-
:marked
73-
### <a id="01-01"></a>_Rule of One_
74+
75+
### <a id="01-01"></a>Rule of One
7476
#### <a href="#01-01">Style 01-01</a>
7577
.s-rule.do
7678
:marked
@@ -95,7 +97,9 @@ a#rule-of-one
9597
:marked
9698
The key is to make the code more reusable, easier to read, and less mistake prone.
9799

98-
The following *negative* example defines the `AppComponent`, bootstraps the app, defines the `Hero` model object, and loads heroes from the server ... all in the same file. *Don't do this*.
100+
The following *negative* example defines the `AppComponent`, bootstraps the app,
101+
defines the `Hero` model object, and loads heroes from the server all in the same file.
102+
*Don't do this*.
99103

100104
+makeExample('style-guide/ts/src/01-01/app/heroes/hero.component.avoid.ts', '', 'app/heroes/hero.component.ts')(avoid=1)
101105
:marked
@@ -349,12 +353,12 @@ a(href="#toc") Back to top
349353

350354
.s-rule.do
351355
:marked
352-
**Do** suffix a service class name with Service.
356+
**Do** suffix a service class name with `Service`.
353357
For example, something that gets data or heroes
354358
should be called a `DataService` or a `HeroService`.
355359

356360
A few terms are unambiguously services. They typically
357-
indicate agency by ending in "er". You may prefer to name
361+
indicate agency by ending in "-er". You may prefer to name
358362
a service that logs messages `Logger` rather than `LoggerService`.
359363
Decide if this exception is agreeable in your project.
360364
As always, strive for consistency.
@@ -421,7 +425,7 @@ a(href="#toc") Back to top
421425

422426
.s-rule.avoid
423427
:marked
424-
**Avoid** putting app logic in the `main.ts`. Instead, consider placing it in a component or service.
428+
**Avoid** putting app logic in `main.ts`. Instead, consider placing it in a component or service.
425429

426430
.s-why
427431
:marked
@@ -451,7 +455,7 @@ a(href="#toc") Back to top
451455

452456
.s-why.s-why-last
453457
:marked
454-
**Why?** The Angular HTML parser is case sensitive and will recognize lower camel case.
458+
**Why?** The Angular HTML parser is case sensitive and recognizes lower camel case.
455459

456460
a(href="#toc") Back to top
457461

@@ -659,7 +663,7 @@ table(width="100%")
659663
tr(style=top)
660664
td
661665
:marked
662-
End to End Tests
666+
End-to-End Tests
663667
td
664668
:marked
665669
app.e2e-spec.ts
@@ -765,7 +769,7 @@ a(href="#toc") Back to top
765769
:marked
766770
## Coding conventions
767771

768-
Have consistent set of coding, naming, and whitespace conventions.
772+
Have a consistent set of coding, naming, and whitespace conventions.
769773

770774
.l-main-section
771775
:marked
@@ -824,7 +828,7 @@ a(href="#toc") Back to top
824828
:marked
825829
**Why?** The tradition of naming constants in UPPER_SNAKE_CASE reflects
826830
an era before the modern IDEs that quickly reveal the `const` declaration.
827-
TypeScript itself prevents accidental reassignment.
831+
TypeScript prevents accidental reassignment.
828832

829833
.s-rule.do
830834
:marked
@@ -906,7 +910,7 @@ a(href="#toc") Back to top
906910

907911
.s-why.s-why-last
908912
:marked
909-
**Why?** TypeScript tooling makes it easy to identify private vs public properties and methods.
913+
**Why?** TypeScript tooling makes it easy to identify private vs. public properties and methods.
910914

911915
+makeExample('style-guide/ts/src/03-04/app/core/toast.service.avoid.ts', 'example', 'app/shared/toast.service.ts')(avoid=1)
912916
:marked
@@ -972,10 +976,10 @@ a(href="#toc") Back to top
972976

973977
.s-rule.do
974978
:marked
975-
**Do** structure the app such that you can `L`ocate code quickly,
976-
`I`dentify the code at a glance,
977-
keep the `F`lattest structure you can, and
978-
`T`ry to be DRY.
979+
**Do** structure the app such that you can **L**ocate code quickly,
980+
**I**dentify the code at a glance,
981+
keep the **F**lattest structure you can, and
982+
**T**ry to be DRY.
979983

980984
.s-rule.do
981985
:marked
@@ -1000,8 +1004,7 @@ a(href="#toc") Back to top
10001004

10011005
.s-why.s-why-last
10021006
:marked
1003-
**Why?**
1004-
To work efficiently you must be able to find files quickly,
1007+
**Why?** To work efficiently you must be able to find files quickly,
10051008
especially when you do not know (or do not remember) the file _names_.
10061009
Keeping related files near each other in an intuitive location saves time.
10071010
A descriptive folder structure makes a world of difference to you and the people who come after you.
@@ -1077,7 +1080,7 @@ a(href="#toc") Back to top
10771080

10781081
.s-rule.do
10791082
:marked
1080-
**Do** be DRY (Don't Repeat Yourself)
1083+
**Do** be DRY (Don't Repeat Yourself).
10811084

10821085
.s-rule.avoid
10831086
:marked
@@ -1087,7 +1090,8 @@ a(href="#toc") Back to top
10871090
:marked
10881091
**Why?** Being DRY is important, but not crucial if it sacrifices the other elements of LIFT.
10891092
That's why it's called _T-DRY_.
1090-
For example, it's redundant to name a component, `hero-view.component.html` because a component is obviously a view.
1093+
For example, it's redundant to name a template `hero-view.component.html` because
1094+
with the `.html` extension, it is obviously a view.
10911095
But if something is not obvious or departs from a convention, then spell it out.
10921096

10931097
a(href="#toc") Back to top
@@ -1203,20 +1207,23 @@ a(href="#toc") Back to top
12031207

12041208
.s-why
12051209
:marked
1206-
**Why?** A developer can locate the code, identify what each file represents
1207-
at a glance, the structure is as flat as it can be, and there are no repetitive or redundant names.
1210+
**Why?** A developer can locate the code and identify what each file represents
1211+
at a glance. The structure is as flat as it can be and there are no repetitive or redundant names.
12081212

12091213
.s-why
12101214
:marked
12111215
**Why?** The LIFT guidelines are all covered.
12121216

12131217
.s-why
12141218
:marked
1215-
**Why?** Helps reduce the app from becoming cluttered through organizing the content and keeping them aligned with the LIFT guidelines.
1219+
**Why?** Helps reduce the app from becoming cluttered through organizing the
1220+
content and keeping them aligned with the LIFT guidelines.
12161221

12171222
.s-why
12181223
:marked
1219-
**Why?** When there are a lot of files (e.g. 10+), locating them is easier with a consistent folder structure and more difficult in a flat structure.
1224+
**Why?** When there are a lot of files, for example 10+,
1225+
locating them is easier with a consistent folder structure
1226+
and more difficult in a flat structure.
12201227

12211228
.s-rule.do
12221229
:marked
@@ -1243,7 +1250,8 @@ a(href="#toc") Back to top
12431250

12441251
.s-rule.do
12451252
:marked
1246-
**Do** create an Angular module in the app's root folder (e.g., in `/src/app`).
1253+
**Do** create an Angular module in the app's root folder,
1254+
for example, in `/src/app`.
12471255

12481256
.s-why
12491257
:marked
@@ -1269,19 +1277,23 @@ a(href="#toc") Back to top
12691277
.s-rule.do
12701278

12711279
:marked
1272-
**Do** create an Angular module for all distinct features in an application (e.g. `Heroes` feature).
1280+
**Do** create an Angular module for all distinct features in an application;
1281+
for example, a `Heroes` feature.
12731282

12741283
.s-rule.do
12751284
:marked
1276-
**Do** place the feature module in the same named folder as the feature area (.e.g `app/heroes`).
1285+
**Do** place the feature module in the same named folder as the feature area;
1286+
for example, in `app/heroes`.
12771287

12781288
.s-rule.do
12791289
:marked
1280-
**Do** name the feature module file reflecting the name of the feature area and folder (e.g. `app/heroes/heroes.module.ts`)
1290+
**Do** name the feature module file reflecting the name of the feature area
1291+
and folder; for example, `app/heroes/heroes.module.ts`.
12811292

12821293
.s-rule.do
12831294
:marked
1284-
**Do** name the feature module symbol reflecting the name of the feature area, folder, and file (e.g. `app/heroes/heroes.module.ts` defines `HeroesModule`)
1295+
**Do** name the feature module symbol reflecting the name of the feature
1296+
area, folder, and file; for example, `app/heroes/heroes.module.ts` defines `HeroesModule`.
12851297

12861298
.s-why
12871299
:marked
@@ -1316,7 +1328,8 @@ a(href="#toc") Back to top
13161328

13171329
.s-rule.do
13181330
:marked
1319-
**Do** create a feature module named `SharedModule` in a `shared` folder (e.g. `app/shared/shared.module.ts` defines `SharedModule`).
1331+
**Do** create a feature module named `SharedModule` in a `shared` folder;
1332+
for example, `app/shared/shared.module.ts` defines `SharedModule`.
13201333

13211334
.s-rule.do
13221335
:marked
@@ -1325,7 +1338,7 @@ a(href="#toc") Back to top
13251338

13261339
.s-rule.consider
13271340
:marked
1328-
**Consider** using the name SharedModule, when the contents of a shared
1341+
**Consider** using the name SharedModule when the contents of a shared
13291342
module are referenced across the entire application.
13301343

13311344
.s-rule.do
@@ -1336,11 +1349,14 @@ a(href="#toc") Back to top
13361349

13371350
.s-rule.do
13381351
:marked
1339-
**Do** import all modules required by the assets in the `SharedModule` (e.g. `CommonModule` and `FormsModule`).
1352+
**Do** import all modules required by the assets in the `SharedModule`;
1353+
for example, `CommonModule` and `FormsModule`.
13401354

13411355
.s-why
13421356
:marked
1343-
**Why?** `SharedModule` will contain components, directives and pipes that may need features from another common module (e.g. `ngFor` in `CommonModule`).
1357+
**Why?** `SharedModule` will contain components, directives and pipes
1358+
that may need features from another common module; for example,
1359+
`ngFor` in `CommonModule`.
13441360

13451361
.s-rule.do
13461362
:marked
@@ -1642,7 +1658,7 @@ a(href="#toc") Back to top
16421658
:marked
16431659
**Why?** components have templates containing HTML and optional Angular template syntax.
16441660
They display content.
1645-
Developers place components on the page as they would native HTML elements and WebComponents.
1661+
Developers place components on the page as they would native HTML elements and web components.
16461662

16471663
.s-why.s-why-last
16481664
:marked
@@ -1726,7 +1742,7 @@ a(href="#toc") Back to top
17261742

17271743
.s-rule.do
17281744
:marked
1729-
**Do** use the `@Input` and `@Output` class decorators instead of the `inputs` and `outputs` properties of the
1745+
**Do** use the `@Input()` and `@Output()` class decorators instead of the `inputs` and `outputs` properties of the
17301746
`@Directive` and `@Component` metadata:
17311747

17321748
.s-rule.do
@@ -1937,7 +1953,7 @@ a(href="#toc") Back to top
19371953

19381954
.s-why
19391955
:marked
1940-
**Why?** Attributes directives don't have an associated template.
1956+
**Why?** Attribute directives don't have an associated template.
19411957

19421958
.s-why.s-why-last
19431959
:marked
@@ -1968,7 +1984,7 @@ a(href="#toc") Back to top
19681984
.s-why.s-why-last
19691985
:marked
19701986
**Why?** The property associated with `@HostBinding` or the method associated with `@HostListener`
1971-
can be modified only in a single place - in the directive's class.
1987+
can be modified only in a single place&mdash;in the directive's class.
19721988
If you use the `host` metadata property, you must modify both the property declaration inside the controller,
19731989
and the metadata associated with the directive.
19741990

@@ -2075,7 +2091,7 @@ a(href="#toc") Back to top
20752091

20762092
.s-rule.do
20772093
:marked
2078-
**Do** use the `@Injectable` class decorator instead of the `@Inject` parameter decorator when using types as tokens for the dependencies of a service.
2094+
**Do** use the `@Injectable()` class decorator instead of the `@Inject` parameter decorator when using types as tokens for the dependencies of a service.
20792095

20802096
.s-why
20812097
:marked

0 commit comments

Comments
 (0)