-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeScript-CodeStyle.mdc
More file actions
71 lines (56 loc) · 2.82 KB
/
TypeScript-CodeStyle.mdc
File metadata and controls
71 lines (56 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
description: Best practices for formatting TypeScript code.
globs: *.ts, *.tsx
---
# Code
## Naming
- Private variables should be prefixed with an underscore. For example: `private _someNumber: number`
- When a private variable is exposed by a property, the property should have the same name as the private variable but without the underscore. For example: `public get someNumber(): number`
## Grouping and Sorting
- When generating code, group members by type, then sort alphabetically.
- When grouping members by type, use the following groups IN THIS ORDER:
- Private Constants
- Protected Constants
- Public Constants
- Private Variables
- Protected Variables
- Private Constructors
- Protected Constructors
- Public Constructors
- Private Methods
- Protected Methods
- Public Methods
- Private Properties
- Protected Properties
- Public Properties
- Private Events
- Protected Events
- Public Events
## Nomenclature
- Consider variables that are not private to be "Public Properties".
- Consider public variables that start with 'on' and are related to callbacks as "Events".
- Consider public properties that start with 'on' and are related to callbacks as "Events".
## Regions
- Always surround code groups with a matching named region.
- Regions should start with // #region \[GroupName\], for example: `// #region \[Public Methods\]`
- Regions should end with // #endregion \[GroupName\], for example: `// #endregion \[Public Methods\]`
- // #region \[GroupName\] statements should be followed by one blank line before code begins.
- // #endregion \[GroupName\] statements should be preceded by one blank line.
- When asked to create regions, always use the group names identified in [Grouping and Sorting](#grouping-and-sorting).
- When asked to create regions, do not create empty regions for groups that don't exist.
## Comments
- Add standard // code comments inside method blocks where helpful to describe what the code is doing.
- Add [JSDoc documentation comments](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) to all Methods, Properties and Events.
- When adding comments, be sure to add them before any metadata annotations.
- When adding comments, if multiple lines are needed start with a summary line and include a blank line between the summary and remaining lines.
- When documenting methods always document and explain parameters.
## Imports
- Imports should always be at the top of the file.
- Imports should always be sorted alphabetically.
- There should not be any blank lines between import statements.
# Refactoring
- When asked to apply Code Style:
1. [Create code groups](#grouping-and-sorting)
1. [Create regions](#regions)
1. Sort regions using the [grouping and sorting rules](#grouping-and-sorting)
1. Add documentation using [code comments](#comments)